Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.preprocessing import StandardScaler
row = np.array([[5.1, 3.5, 1.4, 0.2]])
scaled = StandardScaler().fit_transform(row)
print(scaled.sum())0.0
- Expecting
nanfrom dividing by a zero spread: scikit-learn does not divide by a zero standard deviation, so each value minus its own mean stays0. - Expecting the row to pass through unchanged:
fit_transformfirst learns the means from this one row, which equal the row itself, so every value becomes0.
- Why does a service that fits a new scaler on each request answer the same for every request?
- Which object should the service apply to a raw request row instead?