Hint: StandardScaler centers data to mean 0 and scales variance 1 [OK]
Common Mistakes:
Expecting original data output
Confusing StandardScaler with MinMaxScaler
Missing import causing runtime error
4. Identify the error in this code that uses NumPy with scikit-learn:
import numpy as np
from sklearn.linear_model import LinearRegression
X = [[1, 2], [3, 4], [5, 6]]
y = [1, 2, 3]
model = LinearRegression()
model.fit(X, y)
print(model.coef_)
medium
A. X should be a NumPy array, not a list
B. y should be a 2D array, not a list
C. LinearRegression requires data scaling before fitting
D. model.fit() is missing required parameters
Solution
Step 1: Check data types for model.fit()
scikit-learn expects NumPy arrays or similar, not plain Python lists.
Step 2: Identify the issue in X
X is a list of lists; converting to np.array is needed for proper fitting.
Final Answer:
X should be a NumPy array, not a list -> Option A
Quick Check:
Use NumPy arrays for input data = B [OK]
Hint: Always convert input data to NumPy arrays before fitting models [OK]
Common Mistakes:
Thinking y must be 2D array
Believing scaling is mandatory before fitting
Assuming fit() needs extra parameters
5. You have a dataset as a Python list of lists representing features. You want to prepare it for a machine learning model that requires normalized NumPy arrays. Which steps should you perform?
hard
A. Convert the list to a Python tuple, then normalize manually with loops
B. Directly pass the list to the model without conversion or scaling
C. Convert the list to a NumPy array, then use a scaler like MinMaxScaler to normalize
D. Use pandas DataFrame without converting to NumPy arrays
Solution
Step 1: Convert list to NumPy array
Machine learning models expect NumPy arrays for efficient computation.
Step 2: Normalize data using scaler
Use MinMaxScaler or similar to scale features between 0 and 1 for better model performance.
Final Answer:
Convert the list to a NumPy array, then use a scaler like MinMaxScaler to normalize -> Option C
Quick Check:
Convert then scale data before modeling = C [OK]
Hint: Always convert data to NumPy arrays and scale before modeling [OK]
Common Mistakes:
Passing raw lists directly to models
Using tuples which are not efficient for ML
Skipping normalization hurting model accuracy
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.