liveBook · Manning

Standardization

As explained in Ensemble Methods for Machine Learning

Standardization rescales numerical features so that each feature has a specified mean and dispersion, commonly zero mean and unit standard deviation.

Standardization puts numerical features on a comparable scale by centering each feature at mean 0 and rescaling it to standard deviation 1. This prevents columns such as engine weight, horsepower, and acceleration from entering a downstream regression algorithm at drastically different scales. section 7.2 section 8.1.4

Use the procedure as a small, disciplined preprocessing pipeline:

  • Split the data into training and test sets before fitting any scaler. section 7.2 section 7.4.1
  • Fit the standardization parameters on training features, then transform both training and test features with that fitted preprocessor. section 7.2 section 7.4.1
  • Apply scaling primarily to continuous numerical columns; treat categorical columns with an appropriate categorical preprocessing method instead. section 8.1.4

AutoMPG regression

For AutoMPG, split the data, fit sklearn.preprocessing.StandardScaler on the training data, transform both partitions, and then separate the scaled features from the MPG target. The same pattern applies to the Bike Sharing data, where the feature matrix is standardized while the count-valued target remains the prediction label. section 7.2 section 7.4.1

Listing 7.2 Loading and preprocessing the AutoMPG data set
import pandas as pd
data = pd.read_csv('./data/ch07/autompg.csv')                        #1
 
labels = data.columns.get_loc('MPG') 
features = np.setdiff1d(np.arange(0, len(data.columns), 1), 
                        labels)                                      #2
 
from sklearn.model_selection import train_test_split
trn, tst = train_test_split(data, test_size=0.2, 
                            random_state=42)                         #3
 
from sklearn.preprocessing import StandardScaler
preprocessor = StandardScaler().fit(trn)                             #4
trn, tst = preprocessor.transform(trn), preprocessor.transform(tst)
 
Xtrn, ytrn = trn[:, features], trn[:, labels]                        #5
Xtst, ytst = tst[:, features], tst[:, labels]

Inspect the complete AutoMPG loading, splitting, fitting, transforming, and feature-target separation workflow. section 7.2

Listing 7.8 Preprocessing the Bike Sharing data set
labels = data.columns.get_loc('casual')                      #1
features = np.setdiff1d(np.arange(0, len(data.columns), 1), 
                        labels)                              #2
 
 
from sklearn.model_selection import train_test_split
trn, tst = train_test_split(data, test_size=0.2,             #3
                            random_state=42)
Xtrn, ytrn = trn.values[:, features], trn.values[:, labels]
Xtst, ytst = tst.values[:, features], tst.values[:, labels]
 
from sklearn.preprocessing import StandardScaler
preprocessor = StandardScaler().fit(Xtrn)                    #4
Xtrn, Xtst = preprocessor.transform(Xtrn), preprocessor.transform(Xtst)

Inspect the Bike Sharing workflow, including fitting StandardScaler on training features and transforming the held-out test features. section 7.4.1

How Ensemble Methods for Machine Learning covers it

How deep it goes
Explains zero-mean unit-variance scaling, train-only fitting, and library implementation, while deferring broader discrete-feature strategies.
Examples
Uses AutoMPG, Bike Sharing, and Australian Credit Approval data to demonstrate numerical scaling alongside regression or categorical encoding.
What it assumes
Assumes familiarity with features, labels, training-test splits, and downstream learning algorithms; reinforces preprocessing workflow.
What you can do after
Apply it via sklearn.preprocessing.StandardScaler without fitting preprocessing parameters on the held-out test set.
How it connects
Connects preprocessing with train-test splitting, data leakage, one-hot encoding, pipelines, and ColumnTransformer.

Also explained in

Compare how 5 books explain standardization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.