Which statement best describes the role of the degree in polynomial regression?
Think about how polynomial terms like x² or x³ affect the shape of the curve.
The degree in polynomial regression defines the highest power of the input variable included. Higher degrees allow the model to capture more complex, curved relationships.
What is the output of the following code snippet?
from sklearn.preprocessing import PolynomialFeatures import numpy as np X = np.array([[2]]) poly = PolynomialFeatures(degree=3, include_bias=False) result = poly.fit_transform(X) print(result)
Remember that include_bias=False excludes the constant 1 term.
PolynomialFeatures with degree=3 and include_bias=False transforms input [2] into [2, 2²=4, 2³=8].
You have a dataset with noisy data points. Which degree choice for polynomial regression is most likely to avoid overfitting?
Overfitting happens when the model is too complex for the data.
Degree 5 offers a balance between underfitting (too simple) and overfitting (too complex). Degree 10 is likely too complex, degree 1 too simple, and degree 0 too trivial.
After training a polynomial regression model, you get these metrics on test data: Mean Squared Error (MSE) = 0.02, R² = 0.95. What does this tell you?
Recall that lower MSE and higher R² indicate better fit.
Low MSE means predictions are close to actual values. R² of 0.95 means 95% of variance is explained by the model, indicating a good fit.
Consider this code snippet for polynomial regression prediction. What is the main reason the predictions are all zeros?
from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures import numpy as np X_train = np.array([[1], [2], [3], [4]]) y_train = np.array([1, 4, 9, 16]) poly = PolynomialFeatures(degree=2) X_poly = poly.fit_transform(X_train) model = LinearRegression() model.fit(X_train, y_train) X_test = np.array([[5], [6]]) X_test_poly = poly.transform(X_test) predictions = model.predict(X_test_poly) print(predictions)
Check if the model was trained on the same feature format as used for prediction.
The model was trained on X_train (original features), but prediction uses X_test_poly (polynomial features). This mismatch causes poor predictions (close to zero). The model should be trained on X_poly.
