Z-Scores: Measuring in Standard Deviations

Data ProcessingEasy+10 XP+10

Z-Scores: Measuring in Standard Deviations

Standardizing recentres a feature on zero and rescales it so one unit means one standard deviation:

1z = (value - mean) / std

Task: write zscore(values) returning the standardized list, rounded to 4 decimal places.

  • Use the population standard deviation — divide the squared deviations by n, not n - 1.
  • If every value is identical the deviation is zero; return all zeros rather than dividing by zero.
  • An empty list returns an empty list.

Unlike min-max scaling this has no fixed range, which is exactly why outliers hurt it less — an extreme value lands at z = 8 and stays out there instead of crushing everything else toward one end.

Comparing Scaling Transformations

Explore how data positions and coordinate axes shift under standardization and Min-Max scaling. Hover over data points to check coordinate values.

Metrics Summary

Mode: Raw
X Range: [1.0, 5.0]
Y Range: [10.0, 40.0]
Notice how the scale of Y is 10x larger than X. Distance calculations will be biased towards Y.

Examples

values = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
returns [-1.5, -0.5, -0.5, -0.5, 0.0, 0.0, 1.0, 2.0]
values = [1.0, 2.0, 3.0]
returns [-1.2247, 0.0, 1.2247]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run