← All posts
Machine Learning · Linear Model Explainability · Part 5 of 9

Build Features People Can Understand

A clear equation is only useful when its inputs have clear meanings. “Visits” sounds obvious, but does it count the previous seven days, the previous month, or all visits ever recorded? This chapter turns that question into concrete feature definitions.

State when the prediction is made

Our running example predicts next month’s spending. Visits means completed visits during the previous calendar month. Plan means the plan recorded at the prediction time. Observed spending is collected after the target month ends.

Time makes the difference between a usable predictor and information from the future.
ItemAvailable when predicting?Role
Previous-month visitsYesModel input
Current planYesModel input
Next-month spendingNoOutcome to predict
Refund after next month endsNoNot an input for this prediction

This definition also gives a simple explanation: “The prediction uses your visits last month and the plan you currently have.” A column called activity_score_v7 would need much more unpacking.

Put counts on a meaningful observation window

Imagine a separate activity report for our four customers. Each report counts recent visits, but the available history covers different numbers of days. These are new history measurements, not replacements for the previous-month inputs in Part 1.

Normalize these report counts before comparing activity rates.
CustomerVisits recordedDays observedVisits per 7 days
Asha171
Ben1140.5
Cara373
Dev3141.5

Asha and Ben both have one recorded visit. But Ben’s history covers twice as long. Compute a common rate:

Visits per 7 days = 7 × recorded visits / observed days.
Ben: 7 × 1 / 14 = 0.5.

If this rate became a model input, its coefficient would mean “dollars per additional weekly visit in the measured rate.” We would need to refit the model for that definition. We cannot silently replace the old monthly count while keeping its coefficient 5.

A history with zero observed days has no measured rate. Treat it as missing or give it an explicitly designed representation. Calling it zero activity would confuse “we saw no visits” with “we had no opportunity to observe visits.”

Make larger values mean what the reader expects

Suppose we want to capture increasing activity. Here is another small example using the same names:

Both windows have the same duration, so their counts are comparable.
CustomerEarlier visitsRecent visitsRecent / earlier
Asha242
Ben420.5
Cara331
Dev133

Asha’s ratio of 2 means recent activity doubled. Ben’s 0.5 means it halved. A value of 1 means no change. This direction is easy to explain: larger values mean more growth.

The inverse ratio would carry related information but reverse the direction. It might make the eventual explanation harder to follow. Choosing the orientation is part of feature design. Changing a ratio to its inverse generally changes the functions a linear model can fit, so refit and evaluate it rather than assuming the predictions stay identical.

If the earlier count is zero, the ratio is undefined. For a first implementation, an absolute change plus a “no earlier activity” indicator may be easier to interpret. A feature should have a meaningful definition for the rows where you will actually use it.

Choose useful information from different sources

Suppose our candidate list contains visits last month, visits over two months, time spent visiting, current plan, and a customer identifier. Ranking each column in isolation can fill the shortlist with several versions of activity.

A shortlist is a modeling decision, not just a sort by one score.
CandidateWhat it contributesDecision to investigate
Monthly visitsActivity levelKeep as a clear starting feature
Visit minutesAnother activity measureCheck what it adds beyond visits
Current planService tierKeep a distinct source of information
Customer identifierRecord identityExclude from this simple spending model
Future refundLater outcome informationUnavailable at prediction time

A useful candidate should be predictive in evaluation, reliably measured, available when needed, and clear enough to describe. Also check whether its meaning is likely to remain stable. If an app release changes what counts as a “visit,” the same stored number may stop representing the same behavior.

Predictive value depends on the other inputs. A modest feature by itself can add something valuable to a model; two strong features by themselves may mostly repeat each other. Keep that context when selecting the final set.

Turn definitions into a working process

  1. Define the prediction time and target. List the events that have happened by that time.
  2. Build readable features. State the window, units, and missing-value behavior.
  3. Group overlapping candidates. Start with the underlying measurements they share.
  4. Fit and compare on development data. Check whether the simpler set preserves useful prediction quality.
  5. Evaluate the chosen model on fresh rows. Keep the feature definitions and transformations fixed.

For our running model, the definitions fit in one sentence and there are only two inputs. In larger datasets, grouping overlapping candidates becomes the difficult step. The next chapter uses feature clustering to make that grouping visible.

Sources and worked examples

This chapter develops ideas from the lessons below in A Data Odyssey’s Explainable AI playlist. The customer data, calculations, figures, and interactive examples here are original teaching examples. The creator’s companion notebooks use different datasets.