Working With Data Guide 7 of 8 · tap to switch
Feature Engineering and Selection
How turning raw columns into smarter clues and cutting redundant or noisy junk often beats switching to a bigger model.
The biggest accuracy jumps on real-world spreadsheets rarely come from a fancier algorithm: they come from giving your model clearer clues! Turning raw spreadsheet columns into smarter, easier-to-read clues is called feature engineering, and it routinely beats throwing a massive model at raw numbers.
Consider two everyday examples:
- Wrapping a clock around midnight: On a plain
0 to 23number line,23:00(11 PM) and01:00(1 AM) look 22 hours apart, even though they are only 2 hours apart! Placing each hour around a 24-hour clock rim turns time into two simple coordinates: Horizontal Left/Right (sin) and Vertical Top/Bottom (cos). Now23:00and01:00sit right next to each other across the top of the clock, just like December and January on a 12-month calendar! - Combining clues (Interactions): Sometimes two clues only unlock the real answer when multiplied together. A straight-line model given
WidthandLengthseparately struggles to price rooms accurately, until you add one combined clue:Area = Width × Length.
Try both transformations below.
Measuring linear links (and avoiding the r = 0.00 trap)
When a spreadsheet holds dozens of columns, you want to see which clues move together with the answer you are trying to predict. One fast check is Pearson correlation (r), a straight-line score running from -1.0 (perfect downward slope) through 0.0 (no straight-line trend) to +1.0 (perfect upward slope).
Watch out for a classic catch: because r only looks for a straight line, a strong curved pattern can fool it completely! For instance, if a factory machine breaks down whenever the room is too cold OR too hot, the downward left slope and upward right slope cancel out to r = 0.00.
Drag the correlation slider below to calibrate your eye, then click Show r = 0.00 Curved Trap! to see why you should always look at a plot before deleting a low-r column.
Why twin columns scramble model weights (Multicollinearity)
What happens if a spreadsheet accidentally carries two columns saying the exact same thing, like Floor Area (m²) and Floor Area (sq ft) (r = 0.998)? Because both columns carry nearly identical information, a straight-line model cannot tell how to divide credit between them, a trap called multicollinearity.
Click Retrain on Slightly Different Sample below with both twins kept versus dropping the redundant sq ft twin. With both twins kept, tiny nudges in the training data send the m² weight swinging wildly from -£164k to +£218k per m² while the sq ft weight swings in the opposite direction to cancel it out. Even though the predicted price for a 50 m² flat barely changes (staying near £200k), the individual weights become total nonsense!
Pruning junk columns automatically with Lasso (L1)
Real spreadsheets often carry deadweight columns (house numbers, seller birth months, random listing weekdays) that trick a model into memorizing noise. To clear them out automatically, we can add a weight budget, like a tiny tax on every clue the model wants to use. Weak, noisy clues cannot justify paying the tax, so their weights get squeezed all the way to exact zero and automatically dropped! This automatic pruning trick is called Lasso (L1) regularization, and its strictness dial is written as the shrinkage penalty λ (lambda).
Slide the shrinkage penalty λ upward below and watch the three random noise columns drop to 0.00 (Pruned!) while the three real clues survive and unseen test error falls. Then keep sliding past 26 to see what happens when the tax gets too strict.
Golden rule: pick your clues using practice (training) rows only! Never compute correlations or filter columns across the entire spreadsheet before setting aside your unseen test rows. Peeking at unseen test rows to choose winning columns leaks the answers ahead of time and fakes an unrealistically high test score.
See Pearson r, Variance Inflation Factor (VIF) & Lasso L1 SelectionThesis / Reference
1. Pearson Correlation Coefficient (): Measures strictly linear covariance normalized by both standard deviations:
To capture monotonic non-linear trends use Spearman’s rank correlation (); to capture arbitrary curves (like Lab 2’s U-shape) use Mutual Information .
2. Multicollinearity & Variance Inflation Factor (VIF): Regressing feature onto all other predictors yields and:
When , , inflating the variance of estimated slope by 100×. Values above 5 to 10 warn against interpreting individual OLS coefficients directly.
3. Three Feature Selection Families (Guyon & Elisseeff, 2003):
- Filter methods (Pearson, Mutual Information, ANOVA F-test): fast model-free screening, may miss feature interactions.
- Wrapper methods (Recursive Feature Elimination / forward selection): evaluate subsets directly via cross-validation; accurate yet compute-heavy.
- Embedded methods (Lasso , tree split importance, permutation importance): select features jointly during training. Crucially, always run feature selection strictly inside cross-validation folds (Ambroise & McLachlan, 2002) to prevent severe selection bias!
See cyclical encoding & Lasso feature selection in PythonOptional Code
import numpy as np
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LassoCV
# 1. Cyclical clock encoding for hour of day (0..23)
hour = np.array([23, 0, 1, 12])
hour_sin = np.sin(2 * np.pi * hour / 24)
hour_cos = np.cos(2 * np.pi * hour / 24)
# 2. Leak-free automatic feature selection with scaled LassoCV
lasso = make_pipeline(StandardScaler(), LassoCV(cv=5, random_state=42))
lasso.fit(X_train, y_train)
kept = [name for name, w in zip(feature_names, lasso[-1].coef_) if abs(w) > 1e-4]
print("Selected features:", kept)Final step in Path 02: compressing dozens of correlated columns cleanly
What if you have 30 correlated sensor or financial columns where every column carries a slice of truth, so you cannot simply drop 25 of them? Next up in Principal Component Analysis (PCA), you will rotate and compress high-dimensional clouds into a handful of super-features while keeping almost all the information.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
Why is wrapping 'Month of Year (1 to 12)' onto two clock-rim coordinates (sin and cos) better than leaving it as plain numbers 1 to 12 for a weather model?
A room temperature sensor shows Pearson correlation r = 0.01 with machine failure, yet plotting it shows failures spike steeply whenever the room is EITHER too cold OR too hot. Why did r miss it?
When predicting hospital bills, you accidentally include both patient weight in kilograms AND patient weight in pounds (r = 1.00). What breaks in plain linear regression?
Checking correlations across the ENTIRE spreadsheet (including your unseen test rows) to pick the top 10 columns gives you an honest test score.
Common Questions
What is feature engineering in machine learning?
Why encode cyclical time (hours, months, days of week) with sine and cosine?
Why is multicollinearity (highly correlated input columns) a problem?
Does Pearson correlation r = 0 mean a feature is useless?
How does Lasso (L1) perform automatic feature selection?
Related Visual Guides
One-Hot Encoding & Categorical Encoding
How to turn text categories like London boroughs, cup sizes, and postcodes into clean numbers without tricking your model into fake math.
Principal Component Analysis (PCA)
How to rotate and compress dozens of correlated features into a few clean axes without throwing away the real story.
Gradient Boosting (XGBoost & LightGBM)
Build a relay team of small trees where every new tree fixes the leftover mistakes of the previous ones, dominating real-world tabular ML.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026featureengineering,
author = {Irshad, Muhammad Aashir},
title = {Feature Engineering and Selection: Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/feature-engineering/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). Feature Engineering and Selection: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/feature-engineering/