0
0
ML Pythonprogramming~20 mins

Feature scaling (StandardScaler, MinMaxScaler) in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Feature Scaling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use StandardScaler instead of MinMaxScaler?

Imagine you have a dataset with features measured in very different units, like height in centimeters and income in dollars. You want to prepare the data for a machine learning model.

Why might you choose StandardScaler over MinMaxScaler?

AStandardScaler centers data to mean 0 and scales to unit variance, which handles outliers better than MinMaxScaler.
BStandardScaler always scales data between 0 and 1, which is better for all models.
CMinMaxScaler removes outliers automatically, so StandardScaler is better for noisy data.
DMinMaxScaler centers data to mean 0 and scales to unit variance, so StandardScaler is not needed.
Attempts:
2 left
Predict Output
intermediate
1:30remaining
Output of scaling with MinMaxScaler

What is the output of the following code?

ML Python
from sklearn.preprocessing import MinMaxScaler
import numpy as np

X = np.array([[1], [2], [3], [4], [5]])
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled.flatten())
A[0. 0.25 0.5 0.75 1. ]
B[1. 2. 3. 4. 5.]
C[-1. -0.5 0. 0.5 1.]
D[0.2 0.4 0.6 0.8 1. ]
Attempts:
2 left
Metrics
advanced
1:30remaining
Effect of StandardScaler on mean and variance

After applying StandardScaler to a feature column, what will be the approximate mean and variance of the transformed data?

AMean close to 1 and variance close to 0
BMean close to 0 and variance close to 1
CMean close to 0 and variance close to 0
DMean close to 1 and variance close to 1
Attempts:
2 left
🔧 Debug
advanced
2:00remaining
Why does this scaling code raise an error?

Consider this code snippet:

from sklearn.preprocessing import StandardScaler
import numpy as np

X = np.array([1, 2, 3, 4, 5])
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled)

Why does this code raise an error?

Afit_transform method does not exist for StandardScaler, causing AttributeError.
BStandardScaler cannot handle integer data types, causing a TypeError.
CMissing import for StandardScaler causes NameError.
DX is 1D array but fit_transform expects 2D array, causing a ValueError.
Attempts:
2 left
Model Choice
expert
2:00remaining
Choosing scaler for neural network input

You are training a neural network on image pixel data with values from 0 to 255. Which scaler is the best choice to preprocess the input pixels before training?

ANo scaling needed because neural networks handle raw pixel values well
BStandardScaler to center pixels around 0 with unit variance
CMinMaxScaler to scale pixel values between 0 and 1
DUse a scaler that scales pixels between -1 and 1 by subtracting 128 and dividing by 128
Attempts:
2 left