Problem 9 (5 points, coding task)
Use StandardScaler
that has been imported from sklearn.preprocessing
(DO NOT IMPORT IT AGAIN) to do the following tasks.
-
Create an object called
scaler
. -
Use
scaler.fit_transform
to scale each column inX_train
to standard normal. Save the scaled training dataset asX_train_scaled
. -
Use
scaler.transform
to scaleX_test
. Save the scaled test dataset asX_test_scaled
. -
Add a column to
X_train_scaled
with all 1s. Do the same thing forX_test_scaled
. -
Print the types of objects
X_train_scaled
andX_test_scaled
. -
Print the shapes of objects
X_train_scaled
andX_test_scaled
. -
Print the first five rows of
X_train_scaled
andX_test_scaled
.