Skip to content
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS
Close
Beyond Knowledge Innovation

Beyond Knowledge Innovation

Where Data Unveils Possibilities

  • Home
  • AI & ML Insights
  • Machine Learning
    • Supervised Learning
      • Introduction
      • Regression
      • Classification
    • Unsupervised Learning
      • Introduction
      • Clustering
      • Association
      • Dimensionality Reduction
    • Reinforcement Learning
    • Generative AI
  • Knowledge Base
    • Introduction To Python
    • Introduction To Data
    • Introduction to EDA
  • References
HomeKnowledge BaseWhat is PolynomialFeatures preprocessing technique?
Knowledge Base Linear Regression Supervised Learning

What is PolynomialFeatures preprocessing technique?

February 26, 2024February 26, 2024CEO 176 views

PolynomialFeatures is a preprocessing technique used in machine learning, particularly in polynomial regression. It transforms an input feature matrix by adding new features that are polynomial combinations of the original features.

For example, if you have a feature (x), PolynomialFeatures can generate additional features like \( (x^2), (x^3) \), etc., up to a specified degree. This allows the model to capture nonlinear relationships between the features and the target variable.

Here’s a simple example using Python’s scikit-learn library:

from sklearn.preprocessing import PolynomialFeatures
import numpy as np

# Create a feature matrix with a single feature [1, 2, 3]
X = np.array([[1], [2], [3]])

# Create a PolynomialFeatures transformer with degree 2
poly = PolynomialFeatures(degree=2)

# Transform the original feature matrix to include polynomial features
X_poly = poly.fit_transform(X)

print(X_poly)

The transformed X_poly would look like:

[[1, 1, 1],
 [1, 2, 4],
 [1, 3, 9]]

In this example, the original feature was [1, 2, 3], and PolynomialFeatures added polynomial features up to degree 2, resulting in a new feature matrix with columns for constant term, linear term, and quadratic term.

This transformation allows a linear regression model to capture quadratic relationships between the input feature and the target variable. It’s particularly useful when the underlying relationship between the features and the target is not strictly linear.

The parameter interaction_only is a boolean parameter that controls whether to include only interaction features (products of distinct features), excluding polynomial features.

When interaction_only=True, the transformer generates only the interaction features, leaving out the polynomial features. This can be useful if you are specifically interested in modeling interactions between different features without introducing higher-degree polynomial terms.

In the example above, the transformed X_poly with interaction_only=True would look like:

[[1, 1],
 [1, 2],
 [1, 3]]
feature, fit, linear, polynomial, regression, transform

Post navigation

Previous Post
Previous post: What is Uniform Distribution?
Next Post
Next post: Linear regression model coefficients

You Might Also Like

No image
One-Hot Encoding
February 29, 2024 Comments Off on One-Hot Encoding
No image
Linear regression model coefficients
February 28, 2024 Comments Off on Linear regression model coefficients
  • Recent
  • Popular
  • Random
  • No image
    7 months ago Low-Rank Factorization
  • No image
    7 months ago Perturbation Test for a Regression Model
  • No image
    7 months ago Calibration Curve for Classification Models
  • No image
    March 15, 20240Single linkage hierarchical clustering
  • No image
    April 17, 20240XGBoost (eXtreme Gradient Boosting)
  • No image
    April 17, 20240Gradient Boosting
  • No image
    March 11, 2024What are the common Distance Measures in…
  • No image
    March 1, 2024Difference between R-square and Adjusted R-square
  • No image
    March 11, 2024Standardizing features by StandardScaler
  • Implementation (55)
    • EDA (4)
    • Neural Networks (10)
    • Supervised Learning (26)
      • Classification (17)
      • Linear Regression (8)
    • Unsupervised Learning (11)
      • Clustering (8)
      • Dimensionality Reduction (3)
  • Knowledge Base (44)
    • Python (27)
    • Statistics (6)
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Oct    

We are on

FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS

Subscribe

© 2025 Beyond Knowledge Innovation
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS