1. Learn
  2. /
  3. Courses
  4. /
  5. Predicting CTR with Machine Learning in Python

Exercise

Standard scaling

Standard scaling transforms numerical features to have a mean of 0 and variance of 1. In this exercise, you will do standard scaling using StandardScaler() from sklearn. First, you will select only the relevant columns to apply scaling on, using a combination of filtering for numerical columns along with some knowledge of the columns. This filtering is already provided and will be done through the use of regular expressions, which allows for partial string matches. Then you will use fit_transform() to transform the relevant columns.

The pandas module is available as pd in your workspace and the sample DataFrame is loaded as df. Additionally, the hour column is already converted to a datetime, and StandardScaler from sklearn.preprocessing is available.

Instructions

100 XP
  • Select the numerical columns, and filter the given filter_cols using .select_dtypes().
  • Apply standard scaling to the relevant columns by first creating a StandardScaler() and then using .fit_transform().
  • Print the variance of the newly transformed columns using .var().