You can use PolynomialFeatures in Scikit-learn to create higher-order features, capturing non-linear relationships in regression tasks.
Here is the code snippet you can refer to:
In the above code we are using the following key points:
- PolynomialFeatures(degree=2) creates polynomial terms up to the second degree.
- fit_transform(X_train) and transform(X_test) expand feature space with polynomial combinations.
- LinearRegression() models the transformed features to capture non-linear relationships.
- mean_squared_error() evaluates the model’s prediction accuracy.
Hence, PolynomialFeatures enhances regression models by introducing non-linear terms, allowing better fitting to complex data patterns. Let me know if you’d like any changes or further clarifications!