Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What are polynomial features in machine learning?
Polynomial features are new features created by raising existing features to a power and combining them. They help models learn more complex patterns by adding curved relationships.
Click to reveal answer
beginner
Why do we use polynomial features in a model?
We use polynomial features to allow simple models like linear regression to fit curves and capture non-linear relationships in data.
Click to reveal answer
intermediate
How does degree affect polynomial features?
The degree controls the highest power of features included. Higher degree means more complex features but can cause overfitting if too high.
Click to reveal answer
beginner
What is an example of polynomial features for two variables x and y with degree 2?
For x and y, degree 2 polynomial features include: 1 (bias), x, y, x², xy, y².
Click to reveal answer
intermediate
What is a potential downside of using polynomial features?
Using too many polynomial features can make the model complex, slow to train, and prone to overfitting, especially with small data.
Click to reveal answer
What does adding polynomial features to a dataset help a model do?
AReduce the number of features
BMake the model linear only
CCapture non-linear relationships
DRemove noise from data
✗ Incorrect
Polynomial features help models learn curved or non-linear patterns by adding powers and combinations of original features.
Which of these is NOT a polynomial feature of degree 2 for variables x and y?
Ay³
Bxy
Cx²
Dy²
✗ Incorrect
y³ is degree 3, which is higher than degree 2, so it is not included in degree 2 polynomial features.
What happens if you use a very high degree for polynomial features?
AModel becomes simpler
BModel may overfit
CModel ignores features
DModel always improves
✗ Incorrect
High degree polynomial features can cause the model to fit noise, leading to overfitting.
Polynomial features are mainly used with which type of model?
ALinear models
BDecision trees
CNeural networks only
DClustering algorithms
✗ Incorrect
Polynomial features transform data so linear models can fit non-linear patterns.
Which term is usually included automatically when generating polynomial features?
AOnly squared features
BOnly original features
COnly interaction terms
DBias term (constant 1)
✗ Incorrect
The bias term (constant 1) is included to allow the model to fit an intercept.
Explain what polynomial features are and why they are useful in simple terms.
Think about how adding powers of features changes what the model can learn.
You got /3 concepts.
Describe the risks of using very high degree polynomial features in a model.
Consider what happens when a model tries to fit too many details.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using PolynomialFeatures in machine learning?
easy
A. To create new features by adding powers and combinations of existing features
B. To reduce the number of features in the dataset
C. To normalize the data between 0 and 1
D. To split the dataset into training and testing sets
Solution
Step 1: Understand the role of PolynomialFeatures
PolynomialFeatures generates new features by raising existing features to powers and combining them, helping models learn curves.
Step 2: Compare with other options
Feature reduction, normalization between 0 and 1, and splitting into training/testing sets describe different preprocessing steps, not feature creation with powers.
Final Answer:
To create new features by adding powers and combinations of existing features -> Option A
Quick Check:
PolynomialFeatures = create new polynomial features [OK]
Hint: PolynomialFeatures adds powers and combos of features [OK]
Common Mistakes:
Confusing feature creation with normalization
Thinking it reduces features instead of expanding
Mixing it up with data splitting
2. Which of the following is the correct way to import and create polynomial features of degree 2 using scikit-learn?
easy
A. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=2)
B. from sklearn.linear_model import PolynomialFeatures
poly = PolynomialFeatures(2)
C. import PolynomialFeatures from sklearn.preprocessing
poly = PolynomialFeatures(degree=2)
D. from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(3)
Solution
Step 1: Check the correct import statement
PolynomialFeatures is in sklearn.preprocessing, so 'from sklearn.preprocessing import PolynomialFeatures' is correct.
Step 2: Verify the degree parameter
To create degree 2 features, use degree=2 in the constructor.
Final Answer:
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=2) -> Option A
Quick Check:
Import from preprocessing and set degree=2 [OK]
Hint: Import from preprocessing and set degree=2 [OK]
Common Mistakes:
Importing from wrong module
Forgetting 'degree=' keyword
Setting wrong degree value
3. Given the code below, what is the output of X_poly?
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
X = np.array([[2, 3]])
poly = PolynomialFeatures(degree=2, include_bias=False)
X_poly = poly.fit_transform(X)
print(X_poly)
medium
A. [[2 3 5 6 9]]
B. [[1 2 3 4 6 9]]
C. [[2 3 4 6 9]]
D. [[2 3 4 5 6 9]]
Solution
Step 1: Understand PolynomialFeatures output with degree=2 and include_bias=False
Features include original features, their squares, and pairwise products: [x1, x2, x1^2, x1*x2, x2^2].
Step 2: Calculate values for X = [2, 3]
x1=2, x2=3; x1^2=4, x1*x2=6, x2^2=9; so output is [[2, 3, 4, 6, 9]].
Final Answer:
[[2 3 4 6 9]] -> Option C
Quick Check:
Polynomial features = original + squares + products [OK]
Hint: Output includes original, squares, and cross-products [OK]
Common Mistakes:
Including bias term when include_bias=False
Miscomputing squares or products
Adding extra features not in degree 2
4. Identify the error in the following code snippet that uses PolynomialFeatures:
from sklearn.preprocessing import PolynomialFeatures
X = [[1, 2], [3, 4]]
poly = PolynomialFeatures(degree=3)
X_poly = poly.fit_transform(X)
print(X_poly)
medium
A. X should be a NumPy array, not a list of lists
B. No error; code runs correctly
C. Missing import for NumPy
D. Degree 3 is not supported by PolynomialFeatures
Solution
Step 1: Check input type compatibility
PolynomialFeatures accepts lists or arrays, so X as list of lists is valid.
Step 2: Verify degree parameter and imports
Degree 3 is supported; no NumPy import needed if not used explicitly.
Final Answer:
No error; code runs correctly -> Option B
Quick Check:
PolynomialFeatures accepts lists and degree 3 [OK]
Hint: PolynomialFeatures accepts lists; degree 3 is valid [OK]
Common Mistakes:
Assuming input must be NumPy array
Thinking degree 3 is invalid
Expecting import errors without NumPy usage
5. You have a dataset with 3 features and want to add polynomial features up to degree 3. How many features will the transformed dataset have if include_bias=False?
hard
A. 10
B. 20
C. 16
D. 19
Solution
Step 1: Use formula for number of polynomial features
Number of features = C(n + d, d) - 1 if include_bias=False, where n=3, d=3.
Step 2: Calculate combinations
C(3+3, 3) = C(6, 3) = 20; subtract 1 for no bias gives 19 features.
Final Answer:
19 -> Option D
Quick Check:
Features = combinations(6,3)-1 = 19 [OK]
Hint: Use combinations(n+d, d) minus bias if excluded [OK]