Polynomial features are new features created by raising existing features to a power (like squared or cubed) or by multiplying features together. They help models learn more complex patterns.
Click to reveal answer
beginner
Why do we use polynomial features in machine learning?
We use polynomial features to allow simple models, like linear regression, to fit curved or more complex relationships between variables.
Click to reveal answer
intermediate
How does the degree parameter affect polynomial features?
The degree controls the highest power used. For example, degree 2 adds squared terms and interaction terms, while degree 3 adds cubes and more complex combinations.
Click to reveal answer
intermediate
What is an interaction term in polynomial features?
An interaction term is a feature made by multiplying two or more original features together, showing how they work together to affect the outcome.
Click to reveal answer
intermediate
What is a potential downside of using high-degree polynomial features?
Using very high-degree polynomial features can make the model too complex, causing it to fit noise instead of real patterns, which is called overfitting.
Click to reveal answer
What does a polynomial feature of degree 2 include?
AOriginal features, squared features, and interaction terms
BOnly original features
COnly squared features
DOnly interaction terms
✗ Incorrect
Degree 2 polynomial features include the original features, their squares, and products of pairs of features (interaction terms).
Why might adding polynomial features improve a linear regression model?
AIt reduces the number of features
BIt allows the model to capture nonlinear relationships
CIt makes the model run faster
DIt removes noise from data
✗ Incorrect
Polynomial features let the model learn curved relationships, not just straight lines.
What is an interaction term in polynomial features?
AA feature removed from the dataset
BA feature raised to a power
CA feature normalized between 0 and 1
DA feature created by multiplying two or more original features
✗ Incorrect
Interaction terms are products of features, showing combined effects.
What risk increases when using very high-degree polynomial features?
AOverfitting the model to noise
BUnderfitting the data
CReducing model accuracy
DLosing original features
✗ Incorrect
High-degree polynomials can make the model too complex, fitting noise instead of true patterns.
Which Python library provides a tool to create polynomial features easily?
Apandas
Bmatplotlib
Cscikit-learn
Dnumpy
✗ Incorrect
scikit-learn has a PolynomialFeatures class to generate polynomial features.
Explain in your own words what polynomial features are and why they are useful.
Think about how simple features can be combined or raised to powers to help models learn curves.
You got /3 concepts.
Describe the potential risks of using high-degree polynomial features in a model.
Consider what happens when a model becomes too flexible.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using Polynomial features in data analysis?
easy
A. To reduce the number of features in the dataset
B. To capture non-linear relationships by adding powers and combinations of features
C. To remove outliers from the data
D. To convert categorical data into numerical data
Solution
Step 1: Understand what polynomial features do
Polynomial features create new features by raising existing features to powers and combining them, which helps model curves.
Step 2: Identify the purpose in modeling
This helps capture non-linear relationships that simple linear features cannot represent.
Final Answer:
To capture non-linear relationships by adding powers and combinations of features -> Option B
Quick Check:
Polynomial features = capture curves [OK]
Hint: Polynomial features add powers to model curves, not reduce features [OK]
Common Mistakes:
Thinking polynomial features reduce feature count
Confusing polynomial features with data cleaning
Assuming polynomial features handle categorical data
2. Which of the following is the correct way to create polynomial features of degree 2 using scikit-learn in Python?
easy
A. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(1)
X_poly = poly.transform(X)
B. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit(X)
C. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=3)
X_poly = poly.fit_transform(X)
D. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)
Solution
Step 1: Import and initialize PolynomialFeatures correctly
Use degree=2 to specify the polynomial degree.
Step 2: Use fit_transform to fit and transform the data in one step
fit_transform returns the transformed feature matrix, which is needed for modeling.
Final Answer:
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X) -> Option D
Quick Check:
Use degree=2 and fit_transform() [OK]
Hint: Use fit_transform() with degree=2 to create polynomial features [OK]
Common Mistakes:
Using transform() without fitting first
Setting wrong degree value
Calling fit() without transform or fit_transform()
3. Given the code below, what is the shape of X_poly?
import numpy as np
from sklearn.preprocessing import PolynomialFeatures
X = np.array([[2, 3]])
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)
medium
A. (1, 6)
B. (1, 3)
C. (2, 3)
D. (2, 6)
Solution
Step 1: Count original features and polynomial features
Original X has 2 features. Degree 2 polynomial features include:
- bias (1)
- original features (2)
- squared features and interaction (3): x1^2, x1*x2, x2^2
Total = 1 + 2 + 3 = 6 features.
Step 2: Check number of samples
X has 1 sample (row), so output shape is (1, 6).
Final Answer:
(1, 6) -> Option A
Quick Check:
Features after degree 2 = 6 [OK]
Hint: Degree 2 with 2 features gives 6 output features [OK]
Common Mistakes:
Ignoring bias (constant) term
Counting only squared terms, missing interactions
Confusing samples with features in shape
4. Identify the error in the following code that tries to create polynomial features of degree 3:
A. PolynomialFeatures requires degree to be specified as a keyword argument
B. fit_transform cannot be used on lists, input must be a numpy array
C. No error, the code runs correctly
D. PolynomialFeatures does not support degree 3
Solution
Step 1: Check PolynomialFeatures initialization
Degree can be passed as positional argument, so PolynomialFeatures(3) is valid.
Step 2: Check input type for fit_transform
fit_transform accepts array-like inputs, including lists, so [[1, 2], [3, 4]] is valid.
Final Answer:
No error, the code runs correctly -> Option C
Quick Check:
Degree 3 and list input are valid [OK]
Hint: PolynomialFeatures accepts degree as positional and list input [OK]
Common Mistakes:
Thinking degree must be keyword argument
Assuming lists are invalid input
Believing degree 3 is unsupported
5. You have a dataset with 3 features and want to add polynomial features up to degree 2 but exclude the bias (constant) term. Which code snippet correctly achieves this?
hard
A. poly = PolynomialFeatures(degree=2, include_bias=False)
X_poly = poly.fit_transform(X)