Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.preprocessing import StandardScaler
X_train = np.array([[2.0], [2.0], [6.0], [6.0]])
X_test = np.array([[10.0]])
scaler = StandardScaler()
scaler.fit(X_train)
z = scaler.transform(X_test)[0, 0]
print(round(z, 2))3.0
- Expecting
0.0:transformuses the mean4.0and standard deviation2.0stored byfitonX_train, so10.0becomes(10 - 4) / 2 = 3.0. - Expecting
6.0, the value minus the mean: standardization also divides by the standard deviation, which is2.0here.
- What would
scaler.fit_transform(X_test)give for the same test row, and why is that wrong? - Why may the scaled test set have a mean different from zero?