SeeingML
Working With Data Guide 7 of 8 · tap to switch
✦ Interactive Visual Guide 8 min · 4 hands-on labs · Beginner friendly

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:

  1. Wrapping a clock around midnight: On a plain 0 to 23 number line, 23:00 (11 PM) and 01: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). Now 23:00 and 01:00 sit right next to each other across the top of the clock, just like December and January on a 12-month calendar!
  2. Combining clues (Interactions): Sometimes two clues only unlock the real answer when multiplied together. A straight-line model given Width and Length separately struggles to price rooms accurately, until you add one combined clue: Area = Width × Length.

Try both transformations below.

Interactive Lab 1: Crafting Clearer Clues (Clocks & Interactions)
Raw Line (0 to 23): Gap = 22 hrs!Places midnight edges at opposite ends0:006:0012:0018:0023:00A (23:00)B (01:00)Clock Rim Coordinates (sin, cos): True Gap = 2 hrs00:0006:0012:0018:00sin (L/R)cos (Top/Bot)Straight Rim Distance = 0.52
23:00
Left/Right (sin): -0.26 | Top/Bottom (cos): +0.97
01:00
Left/Right (sin): +0.26 | Top/Bottom (cos): +0.97
Midnight wrap trap! Between 23:00 and 01:00, the raw 0 to 23 number line reports a huge 22-hour gap, even though the true clock gap is only 2 hours! Using Clock Rim Coordinates (sin, cos) keeps them right next door (rim distance = 0.52).

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.

Interactive Lab 2: Straight-Line Correlation & the r = 0.00 Curved Trap
Pearson r = +0.84
Outside Temp vs. Ice Cream Sales (Pearson r = +0.84)$100$300$500$700$90010°C16°C22°C28°C34°COutside Temp (°C)Ice Cream Sales ($)
+0.85
Strong upward straight-line link (r = +0.84): warmer days reliably boost ice cream sales, so a simple model can use this clue right away. Now click "Show r = 0.00 Curved Trap!" to see where Pearson r misses a huge pattern.

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!

Interactive Lab 3: Why Twin Columns Scramble Model Weights
Learned Weight on Floor Area (m²)
+£144k / m²
Swings wildly from -£164k to +£218k on tiny sample shifts!
Learned Weight on Floor Area (sq ft)
£-13.0k / sq ft
Swings in the exact opposite direction to cancel out the m² weight.
Predicted Price for a 50 m² Flat (538 sq ft)
£206kBarely changes despite wild weights!
50 m² contribution+£7,200k
538 sq ft contribution-£6,994k
-£11,500k£0+£11,500k
Net Flat Price: (+£7,200k) + (-£6,994k) = £206k
Twin correlation (m² vs sq ft): r = 0.998
Tug-of-war trap (Sample 1): Floor Area (m²) pushes +£7,200k while Floor Area (sq ft) pulls -£6,994k. Those two massive opposing weights nearly cancel out to £206k for our 50 m² flat, so predictions look normal, yet the individual weights flip wildly between negative and positive! Click "Retrain" to watch them swing, then click "Drop Redundant Twin (m² Only)".

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.

Interactive Lab 4: Pruning Junk Columns to Exact Zero With Lasso (L1)
Unseen Test Error: £29k
Real Clues (3/3 active)Random Junk Columns (3/3 active)
No Pruning
Floor Area (m²)92
Near Tube Station68
Bedrooms48
House Number (Junk)22
Seller Birth Month (Junk)18
Listing Weekday (Junk)14
Shrinkage Penalty (λ) = 0
0 (No Tax)22 to 26 (Sweet Spot)32 (Too Strict)
At Shrinkage Penalty (λ) = 0, all 3 random junk columns keep noisy weights, hurting unseen test error (£29k). Slide the penalty up toward 22 to watch Lasso squeeze them to exact zero!
⚠️ Warning

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 (rr): Measures strictly linear covariance normalized by both standard deviations:

rxy=∑i=1n(xi−xˉ)(yi−yˉ)∑i=1n(xi−xˉ)2∑i=1n(yi−yˉ)2∈[−1,1]r_{xy} = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \in [-1, 1]

To capture monotonic non-linear trends use Spearman’s rank correlation (ρ\rho); to capture arbitrary curves (like Lab 2’s U-shape) use Mutual Information I(X;Y)=∬p(x,y)ln⁡p(x,y)p(x)p(y) dx dyI(X; Y) = \iint p(x,y)\ln\frac{p(x,y)}{p(x)p(y)}\,dx\,dy.

2. Multicollinearity & Variance Inflation Factor (VIF): Regressing feature xjx_j onto all other predictors yields Rj2R_j^2 and:

VIFj=11−Rj2\text{VIF}_j = \frac{1}{1 - R_j^2}

When Rj2=0.99R_j^2 = 0.99, VIFj=100\text{VIF}_j = 100, inflating the variance of estimated slope w^j\hat{w}_j 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 ℓ1\ell_1, 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
python
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.

✓ Self-Check

Quick Intuition Check

Four quick real-world scenarios. No scores, just test your intuition.

1

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?

Pick an option first, or peek anytime
2

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?

Pick an option first, or peek anytime
3

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?

Pick an option first, or peek anytime
4

Checking correlations across the ENTIRE spreadsheet (including your unseen test rows) to pick the top 10 columns gives you an honest test score.

Pick an option first, or peek anytime
Quick Reference

Common Questions

What is feature engineering in machine learning?
Feature engineering is the craft of turning raw columns into clearer, higher-signal clues using domain knowledge, such as combining Width and Length into Area, turning 24-hour clock times into sine/cosine coordinates, or dividing debt by income.
Why encode cyclical time (hours, months, days of week) with sine and cosine?
On a plain 0 to 23 scale, 23:00 (11 PM) and 01:00 (1 AM) look 22 units apart. Mapping hour h to sin(2πh/24) and cos(2πh/24) places midnight seamlessly next to both 11 PM and 1 AM.
Why is multicollinearity (highly correlated input columns) a problem?
When two input columns carry nearly identical information (like Floor Area in m² and sq ft), linear models can assign huge opposing positive and negative weights that cancel each other out. Predictions may survive, but individual weights become unstable and impossible to interpret.
Does Pearson correlation r = 0 mean a feature is useless?
No. Pearson r only measures straight-line relationships. A clean curved relationship like y = x² scores r = 0.00 even when X predicts Y with 100% accuracy. Use Mutual Information or Spearman rank correlation to catch non-linear links.
How does Lasso (L1) perform automatic feature selection?
Lasso adds a penalty proportional to the sum of absolute weights (|w|), whose diamond-shaped geometry drives noisy or irrelevant feature weights all the way to exact zero during training.

Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference

https://seeingml.com/learn/feature-engineering/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@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}
}
APA

Irshad, M. A. (2026). Feature Engineering and Selection: Interactive Visual Guide. SeeingML. https://seeingml.com/learn/feature-engineering/