liveBook · Manning

Z-score

As explained in The Well-Grounded Data Analyst

A z-score is a standardized value expressing how many standard deviations an observation lies above or below a variable's mean.

A z-score expresses a value as its distance from a column mean in standard deviations. It puts differently scaled continuous variables on a comparable scale, preventing a high-variation feature from dominating distance-based clustering. section 13.1.4

Use z-score scaling when preparing continuous features for clustering:

  • Scale continuous variables such as number of apps, number of sessions, and average session length. section 13.1.4
  • Leave binary indicator columns unchanged because they are already on a comparable scale. section 13.1.4
  • Interpret a value of 1 as one standard deviation above that variable’s mean; scaled values are approximately between −5 and 5. section 13.1.4

Scaling selected user features

Create a StandardScaler, copy the feature table, and replace only the continuous columns with their z-scores before clustering.

How The Well-Grounded Data Analyst covers it

How deep it goes
Defines standard-deviation distance and demonstrates selective implementation, without deriving the transformation mathematically.
Examples
Uses mobile-user features including apps, sessions, and average session length, while preserving binary indicators.
What it assumes
Assumes a prepared feature table and distinguishes continuous variables from already comparable binary indicators.
What you can do after
Apply it via scikit-learn’s StandardScaler to selected continuous features before clustering.
How it connects
Connects z-scores to feature scaling, continuous variables, binary indicators, distance-based clustering, and K-means.

Also explained in

Compare how 8 books explain z-score →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.