What does StandardScaler do?
Perfect, let’s carefully analyze this code step by step.
Code Recap
import pandas as pd
from sklearn.preprocessing import StandardScaler
data = pd.DataFrame({
'col1': [1, 2, 3, 4, 5],
'col2': [10, 20, 30, 40, 50]
})
ss = StandardScaler()
scaled_data = ss.fit_transform(data)
print(ss.var_)
We are asked: What will ss.var_ print?
Step 1: What does StandardScaler do?
-
It standardizes features by removing the mean and scaling to unit variance.
-
Internally, it computes:
👉 Notice:
StandardScaleruses population variance (divide by n), not sample variance (which divides by n-1).
Step 2: Compute variance for col1
col1 = [1, 2, 3, 4, 5]
-
Mean =
So, var(col1) = 2.
Step 3: Compute variance for col2
col2 = [10, 20, 30, 40, 50]
-
Mean =
So, var(col2) = 200.
Step 4: Final Answer
ss.var_ = [2, 200]
✅ Correct Option: [2, 200]
Would you like me to also explain why the other options are wrong (e.g., why [4,400] or [10,10000] appear as distractors)?
Comments
Post a Comment