Polynomial regression can fit curves instead of straight lines. Why does this help with non-linear data?
Think about how adding squared or cubic terms changes the shape of the prediction.
Polynomial regression adds powers of input features (like squared or cubic terms). This lets the model fit curved lines, which helps capture non-linear relationships in data.
You have data with complex curves and interactions. Which regression model is best to capture these patterns?
Think about models that split data into regions and fit different values in each.
Decision tree regression splits data into regions and fits simple models in each. This allows it to capture complex non-linear patterns better than polynomial regression of fixed degree.
What is the predicted value from this polynomial regression model?
from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression import numpy as np X = np.array([[2]]) poly = PolynomialFeatures(degree=2, include_bias=False) X_poly = poly.fit_transform(X) model = LinearRegression() model.coef_ = np.array([3, 4]) model.intercept_ = 5 prediction = model.predict(X_poly) print(prediction[0])
Calculate 3*x + 4*x^2 + 5 for x=2.
The polynomial features for x=2 are [2, 4]. The prediction is 5 + 3*2 + 4*4 = 5 + 6 + 16 = 27.0.
You compare linear regression and polynomial regression on the same dataset. Which metric best shows that polynomial regression fits non-linear data better?
Think about what a good fit means for error values.
A lower Mean Squared Error means the model predictions are closer to actual values, showing better fit. Polynomial regression usually lowers MSE on non-linear data compared to linear regression.
Given this code snippet, why does the kernel ridge regression model fail to capture non-linear patterns?
from sklearn.kernel_ridge import KernelRidge import numpy as np X = np.array([[1], [2], [3], [4], [5]]) y = np.array([1, 4, 9, 16, 25]) # y = x^2 model = KernelRidge(alpha=1.0, kernel='linear') model.fit(X, y) pred = model.predict(np.array([[6]])) print(round(pred[0], 2))
Think about what the kernel function does in kernel ridge regression.
The linear kernel treats the problem like linear regression, so it cannot capture the quadratic pattern y = x^2. Using a non-linear kernel like 'rbf' would help model non-linearity.