Learn
Concept·

Feature Selection & Derived Variables

Training error fell all the way to 60 features. Validation bottomed out at 8

You add features one at a time and record the error. Training error keeps falling. It is lowest with all sixty in. So you ship all sixty.

Validation error did something else. It bottomed out at the eighth feature and climbed from there. The sixty-feature model carries 87% more error than the eight-feature one — a fact entirely invisible from the training curve.

Features usedError on the training dataError on data it has never seen
8still has room to falllowest
60lowest87% higher than with 8

The two columns point in opposite directions. Read the left one and sixty is the answer; read the right one and eight is. The right one is the column the model will actually live in.

Feature selection sounds like tidying: throw out what does not help. It is not. Every feature you add means the model spends part of your data working out what that feature does. When data is scarce, that cost comes back as worse predictions.

The traffic runs the other way too. Derived variables combine existing columns into new ones, and one well-chosen derived feature can beat twenty raw ones outright.

The key question

Does this feature improve validation performance, or only training performance?

1

Concept

Every feature spends some of your data

Why more features can hurt

Each one adds something the model has to estimate. With unlimited data that is free; on a finite sample it means spreading the same information across more places.

  • Variance goes up — more coefficients to estimate makes each individual estimate less precise.
  • Noise gets mistaken for signal — an irrelevant feature still fits the training data by chance.
  • Distances stop meaning anything — in high dimensions every point is roughly equidistant from every other.
  • Nobody can read the model — a sixty-coefficient model goes unexamined.
  • Operations get more expensive — every feature carries collection, validation and monitoring with it.

Think in p over n, not p

"How many features is too many" has no fixed answer. On 40 rows the limit is around 4; on 4,000 rows it is around 14. What matters is p relative to n.

Three families of method

Filter

score, then cut

Rank each feature on its own, keep the top ones.

Wrapper

try, measure, repeat

Add or drop features and refit the model each time.

Embedded

the model decides

Lasso and trees select while they fit.

FamilyExamplesCostBlind spot
FilterCorrelation, chi-square, mutual information, varianceCheap — one passJudges each feature alone, so it misses combinations
WrapperForward, backward, recursive eliminationExpensive — refits repeatedlyOverfits the validation set if used greedily
EmbeddedLasso, Elastic Net, tree importanceFree — part of fittingTied to that one model family
DomainWhat the business knows is causalHuman timeConfirms what you already believed

In practice the common combination is a filter to clear the obvious cases and an embedded method for the rest. Wrappers are expensive, and because they consult the validation set repeatedly they become a source of overfitting in their own right.

2

Why It Matters

What a correlation filter cannot see

What a correlation filter cannot see

The most common selection rule is correlate each feature with the target and drop the low ones. Fast, simple, and blind to everything that is not a straight line.

Table 1 What happens when correlation is the only criterion
RelationshipPearson rA filter wouldActually
y = x, straight line1.00keepCorrect
y = x², U-shaped0.00dropPerfectly predictive
Two clean clusters0.02dropSeparates the classes on its own
Predictive only above a threshold0.11dropA tree finds it immediately
Useless alone, decisive with another0.03dropAn interaction term is where it lives
Near-duplicate of another feature0.94keepRedundant — one of the pair is enough

Row two is the extreme case. y = x² means x determines y exactly, and the Pearson correlation is zero. Cut on correlation and the best feature is the first one you throw away.

The last row runs the other way. It survives with r = 0.94 while carrying almost the same information as a feature you already have. Correlating with the target and adding something are different properties.

Redundant features are worse than none

Several strongly correlated features together produce multicollinearity. Raw predictive accuracy may hold up, but the coefficients become unstable and interpretation collapses.

SymptomCauseWhat to do
A coefficient with the wrong signCorrelated features cancelling each otherKeep one of the pair
Coefficients swing on small data changesThe solution is barely identifiedRidge, or drop a feature
Significant F, no significant tThe contribution is spread across severalDiagnose with VIF
VIF above 10One feature is nearly explained by the othersRemove or combine
The same quantity in two unitsA preprocessing slipDelete immediately

When the strongest feature is the problem

If one feature dominates the importance ranking, that is not a result to celebrate but a thing to check. It usually means information from after the prediction point has found its way in.

FeatureLooks likeThe problem
cancel_reasonA strong predictor of churnOnly filled in after the churn happens
total_paid including taxPredicts order value wellIt contains the target
account_closed_dateUseful timing informationIts presence is the label
A field updated nightlyFine in the training tableHolds the future at prediction time
An ID that increases over timeCorrelates with the outcomeIt is encoding the date, not a cause

They all share one property: each is a value that comes into existence after the outcome does. In the training table they look perfectly ordinary; at the moment you actually need a prediction, the cell is empty.

Ask the timing question

Take each feature and ask "does this value exist at the moment I have to predict?" That single question catches most leakage, and it is frequently more useful than any importance ranking.

3

How It Works

Work in order, and select inside the fold

1. Work through it in order

Before reaching for an algorithm, clear out everything you can eliminate by thinking. It is common for this pass alone to remove more than half the columns.

StepRemoveCriterion
1Leaky featuresThe value does not exist at prediction time
2IdentifiersIDs, names, random codes
3Constant and near-constantOne distinct value, or 99% the same
4Exact duplicatesThe same quantity in different units
5Review very sparse columnsOver 80% missing — keep only the indicator
6Domain-irrelevant columnsIf you cannot explain it, do not keep it
7Run an algorithm on the restLasso, tree importance, recursive elimination

2. Select inside the fold, always

Feature selection learns from data. Select on the full dataset and then cross-validate, and each held-out fold is being scored on features chosen partly by looking at that fold.

Same data, same model

Top 20 selected on the full dataset, then cross-validated: 84.1%

Reselected within each fold: 78.6%

Actual production accuracy: 78.9%

The whole 5.5-point gap leaked in during selection. It widens as features increase and rows decrease.

3. Building derived features

A good derived feature supplies a form the model would struggle to build itself. Linear models cannot divide; trees can approximate a ratio only by spending several splits on it.

PatternExampleWhy it helps
RatioSpend ÷ visits = spend per visitRemoves size so behaviour shows through
DifferenceThis month − last monthTrend beats level for most decisions
Elapsed timeDays since last purchaseA date is not a number; an interval is
AggregateMean, max, count over a windowOne row per entity instead of many
InteractionPrice × season, tier × tenureEffects that exist only in combination
Cyclicalsin and cos of hour or monthKeeps midnight adjacent to 23:00
FlagWas this field blank?Missingness is often the signal

Why ratios pull so much weight

Give a model revenue and visit count separately and it finds large customers. Give it revenue per visit and it finds high-value customers. The second is usually the question, and a linear model cannot express it from the first two.

4. Where derived features go wrong

  • Do not reach into the future — an aggregate like "spend over the next three months" does not exist at prediction time.
  • Pin the aggregation window — "last 30 days" has to be anchored to the prediction date, not to today.
  • Decide about the originals — having built a ratio, choose whether the numerator and denominator stay in.
  • Handle division by zero — revenue per visit is undefined for a customer with no visits.
  • Keep the count under control — all pairwise ratios of 20 features gives 380 columns, and most of them are noise.
4

Example

One derived feature beating twenty raw ones

In practice: one derived feature against twenty raw ones

Churn prediction for a subscription product. The raw features were twenty columns pulled from usage logs — active days per month, total session time, per-feature usage counts.

Feature setCountValidation AUCInterpretability
All 20 raw200.734Low
Top 8 of the raw80.741Moderate
Last 30 days ÷ prior 30 days (usage ratio)10.768High
That ratio plus the top 560.803High

Row three is the finding: one feature beats all twenty raw ones. What drives churn is not the level of usage but the change in it, and every raw feature captured only the level.

Could a tree have found that ratio itself? In principle. But approximating a division with splits burns depth, and depth costs data. A human writing one line is far cheaper.

The lesson here

Feature design often moves performance more than feature selection does. And design does not come from an algorithm — it comes from understanding what causes the thing you are predicting.

In practice: dropping the top-ranked feature

Importance on the same model put support_ticket_count in first place by a wide margin, and performance backed it up. Checking the timing turned up a problem.

Checking the timing

The count in training: includes the month before cancellation

The moment of prediction in production: churn status still unknown

Customers who have decided to leave file a burst of tickets on the way out. The feature was a consequence of churn, not a cause — and at prediction time it had not happened yet.

Recomputing it as "the 30 days before the prediction date" rather than "the last 30 days" dropped it to seventh in importance and took validation AUC from 0.83 to 0.80. The drop is the correct outcome. The 0.83 was performance that did not exist.

Common misunderstandings

Misconception 1

❌ More features is better — the model will sort it out.

True with unlimited data. On a finite sample every feature spends part of it.Sixty features on forty rows drives training error to zero and nothing else.

Misconception 2

❌ Low correlation with the target means it can go.

Correlation sees straight lines only. U-shaped relationships, threshold effects and features that matter only in combination all come back near zero.

Misconception 3

❌ Selection is preprocessing, so do it once.

Selection learns from data. Under cross-validation it has to be redone inside every fold, or the score comes out optimistic.

Misconception 4

❌ The top-ranked feature is the most important one.

Rule out leakage first. And tree importance systematically favours high-cardinality features, so cross-check with permutation importance.

Misconception 5

❌ Generating lots of derived features costs nothing.

All pairwise ratios of twenty features is 380 columns, nearly all noise. A derived feature is still a feature and pays exactly the same price.

5

Interactive

Add features and watch the two errors diverge

Add features and watch the two errors diverge

Training and validation error plotted together as features go from 1 to 60. Only five of them carry any signal; the rest is noise. Use the slider to change how much data you have.

Five features actually carry signal. Everything after that is noise the model can still memorise.

Rows

200

Best feature count

8

Cost of using all 60

+87%

With 200 rows the validation error bottoms out at 8 features and rises after that, even though training error keeps falling all the way to 60. Using every feature costs 87% more error than stopping at the bottom.

"Too many features" is not a fixed number — it is a number relative to how many rows you have.

What to look for

  • At what point does training error start rising?
  • How many features minimise validation error?
  • Drop n to 40 — where does that minimum move to?
  • Push n to 4,000 — what happens then?
  • Five features carry signal, so why is the optimum not five?

Learning points

Training error always falls as features are added, which is why it decides nothing.

The minimum of the validation curve moves with the amount of data.

With plenty of data a useless feature costs little; with little data it is decisive.

Key takeaways

Fewer, not more

Every feature costs data

  • Training error always falls; validation does not
  • The limit scales with n, not p
  • Redundant features are worse than none

Better, not just fewer

A ratio can beat both its parts

  • Ratios, differences, elapsed time
  • Interactions for combined effects
  • Domain knowledge beats every search

Select honestly

Selection is part of the model

  • Select inside the CV fold, never outside
  • A feature scoring 0.99 is leakage
  • Ask if it exists at prediction time

The question is not "which features should I keep?"

It is "does this feature exist at prediction time?" The best-performing feature turns out to be a feature that does not existsurprisingly often.

How does this apply to real data?

Selecting and designing features moves performance more than choosing a model does. In SKARI you can check the following alongside.

Selection

Lasso, RFE, Mutual Information, Boruta

Redundancy

VIF, Correlation Heatmap, Condition Index

Importance

Permutation Importance, SHAP, Tree Importance

Dimension reduction

PCA, Factor Analysis, UMAP

Once this clicks, you can answer questions like these.

  • How many features can this many rows support?
  • Does this feature actually exist when the prediction is made?
  • Am I dropping good features because their correlation is low?
  • Is there a relationship a ratio or a difference would express better?
  • Is selection happening inside the cross-validation fold?
Now try it on real dataOpen in Lab

Go Deeper

Sampling & Data Splitting