liveBook · Manning

StandardScaler

As explained in Data Without Labels

StandardScaler is a scikit-learn transformer that standardizes features by removing their means and scaling them to unit variance.

When one feature has much larger values than another, it can dominate a distance calculation. StandardScaler prepares features by subtracting each feature’s mean and dividing by its standard deviation. This puts features on a comparable scale before distance-based clustering or principal component analysis (PCA). section 2.3.5 section 3.5.2

Use it on the features that will enter the analysis:

  • Inspect the dataset and check for missing values before scaling. section 2.3.5
  • Separate the features from any class or target column; the vehicle clustering and iris PCA workflows both scale feature columns. section 2.3.5 section 3.5.2
  • Create StandardScaler(), then call fit_transform on the feature data to obtain the transformed array. section 2.3.5 section 3.5.2
sc = StandardScaler()
transformed_df = sc.fit_transform(X_variables)

The iris workflow fits the scaler to X_variables and stores the scaled features in transformed_df, ready for the covariance calculation and PCA. section 3.5.2

Scaling before k-means

For vehicle data, remove the class column and scale the remaining features into X_standard. Plot the scaled data, use X_standard to compare cluster counts with the elbow method, and fit k-means on that same array. Scaling keeps a naturally large-valued dimension from dominating Euclidean distance. section 2.3.5

How Data Without Labels covers it

How deep it goes
Defines mean subtraction and standard-deviation scaling, then demonstrates fit_transform; defers comparisons with other scaling techniques.
Examples
Uses scaled vehicle features for an elbow-method clustering workflow and scaled iris features for covariance and PCA calculations.
What it assumes
Assumes familiarity with Python tabular data and teaches why scaling matters and how to call fit_transform.
What you can do after
Apply it via scikit-learn to transform feature columns before fitting k-means or calculating PCA inputs.
How it connects
Connects feature scaling to Euclidean distance, k-means clustering, covariance matrices, and PCA.

Also explained in

Compare how 2 books explain StandardScaler →

Related concepts

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