Summary - Feature engineering
- Machine Learning course
- Beginner
- Lesson 86/112
- 6 min
In this group you learned feature selection, extraction, and transformation.
Summary: feature engineering
In this group:
- Features are the only information the model sees; a good feature relates to the target and is known at prediction time.
- Simple selection is done with a variance threshold and correlation.
- Extraction from dates and text: month, day, word counts.
- Categorical features: one-hot (unordered), ordinal (ordered),
handle_unknown="ignore". - Numeric transformations:
log1p, binning, polynomials.
Every transformation must be learned on training data and applied unchanged to test data; a pipeline is the safest way.
Practice Features from a date
Build a list containing the month and the weekend flag (1 if weekday() >= 5, else 0) for each date and print it as an np.array.
Starter code
import numpy as np
from datetime import date
tarihler = [date(2024, 1, 6), date(2024, 1, 8), date(2024, 7, 14)]
# buraya yazSample solution
import numpy as np
from datetime import date
tarihler = [date(2024, 1, 6), date(2024, 1, 8), date(2024, 7, 14)]
ozet = [[t.month, int(t.weekday() >= 5)] for t in tarihler]
print(np.array(ozet))Expected output
[[1 1] [1 0] [7 1]]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which carries a leakage risk for a credit model?
- Income at application time
- The applicant's age
- The amount requested
- The number of late payments computed after the loan closed Correct answer
Explanation: This information doesn't exist at prediction time; it is derived from the target itself.
2 Compress the skewed value with a logarithm.
x_log = np.____(gelir)
x_log = np.log1p(gelir)
Explanation: log1p is defined at 0 too.
3 Match the tools.
| Term | Meaning |
|---|---|
VarianceThreshold |
Drops constant columns |
CountVectorizer |
Counts words |
OneHotEncoder |
Category columns |
PolynomialFeatures |
Squares and products |