Z-Test and Hypothesis Testing

Maths: Statistics for machine learning

3 min read

Published Oct 22 2025, updated Aug 17 2026


40
0
0
0

Machine LearningMathsNumPyPandasPythonStatistics

A Z-test is a statistical hypothesis test used to determine whether there is a significant difference between a sample mean and a population mean, or between the means of two samples, when the population standard deviation (σ) is known and/or the sample size is large (n ≥ 30).


In simple terms:

“A Z-test checks if a sample mean is far enough away from what we expect — in standard deviation units — to suggest a real difference rather than random variation.”




When to Use a Z-Test

Use a Z-test when:

  • The population standard deviation (σ) is known
  • The sample size is large (n ≥ 30) (Central Limit Theorem applies)
  • The data are approximately normally distributed

If σ is unknown and n is small, use a T-test instead.




Types of Z-Tests

Test Type

Purpose

Example

One-sample Z-test

Compare a sample mean to a population mean

“Is the average height of students different from 170 cm?”

Two-sample Z-test

Compare two independent sample means

“Do males and females have different average test scores?”

Z-test for proportions

Compare sample proportion(s) to a population or another group

“Did more than 60% of users click the ad?”




Hypothesis Setup

Symbol

Meaning

Example

H₀ (Null Hypothesis)

No difference or effect

μ = μ (e.g. mean = 50)

H₁ (Alternative Hypothesis)

There is a difference

μ ≠ μ (two-tailed) or μ > μ / μ < μ (one-tailed)


You start by assuming H₀ is true, then use your data to test if it should be rejected.




Z-Test Formula

For a one-sample Z-test:

z-test formula

Where:

  • X = sample mean
  • μ0 = population mean under H₀
  • σ = population standard deviation
  • n = sample size



Decision Rule

  1. Choose a significance level (α) (commonly 0.05).
  2. Find the critical Z-value:
    • Two-tailed test: ±1.96 (for α = 0.05)
    • One-tailed test: ±1.645 (for α = 0.05)
  3. Compute your Z-statistic using the formula.
  4. Compare:
    • If |Z| > Z-critical, reject H₀ (significant difference).
    • Otherwise, fail to reject H₀.



Example

A sample of 50 students has an average test score of 78.
The population mean is 75, with a known σ = 10.
At α = 0.05, is the difference significant?

z-test example

Compare with critical Z (±1.96 for 95% confidence):

|2.12| > 1.96 → Reject H₀

Interpretation:
There is a statistically significant difference between the sample mean and population mean.




P-Value Approach

You can also interpret the Z-test using the p-value:

  • Find p-value from Z (e.g., p = 0.034).
  • Compare with α = 0.05.
  • If p ≤ α → Reject H₀, else Fail to reject H₀.

Same conclusion as using Z-critical values.




Visual Understanding

  • The Z-distribution (standard normal) is centred at 0.
  • The tails represent rare or extreme outcomes.
  • If your Z-statistic lies in the tails (beyond ±Z-critical), your result is unlikely under H₀.


A two-tailed test shades both ends of the normal curve (extreme low and high).
A one-tailed test shades only one end.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Maths: Statistics for machine learning | Z-Test and Hypothesis Testing | SimpleSteps.guide