Feature availability and interactions
Quick answer
Feature engineering converts information available at prediction time into useful numerical inputs. A delivery estimate can use package weight and distance known when an order is accepted, but not the final delivery timestamp. An interaction combines two measurements so a model can express their joint effect.
Point-in-time total
events = [(2, 3, 5), (6, 12, 9), (11, 11, 7)]cutoff = 10print(sum(value for event, available, value in events if event <= cutoff and available <= cutoff))Expected output:
5Only the first event is both historical and available.
How it works
Write a feature contract with source, unit, entity key, event time, availability time, prediction cutoff, aggregation window, missing-value policy and version. Event time describes when something occurred; availability time describes when the prediction system could actually read it. Both must be at or before the cutoff for a historical event feature. A product interaction x1*x2 lets a linear model express an effect that depends on both inputs. A ratio such as units per package requires a defined zero-denominator policy; a missing result can be imputed with an indicator using training-only statistics. Preserve units and avoid accidental identifiers. PolynomialFeatures generates candidate columns, not necessarily useful features: quadratic expansion can grow quickly and correlated columns may make estimates unstable. Reuse the same feature definition offline and online and compare results on identical fixtures.
Interaction columns
from sklearn.preprocessing import PolynomialFeaturesp = PolynomialFeatures(degree=2, interaction_only=True, include_bias=False)print(p.fit_transform([[2, 3], [4, 5]]).astype(int).tolist())Expected output:
[[2, 3, 6], [4, 5, 20]]The two original inputs are followed by their product; squares and the bias column are excluded.
Common mistakes
Do not join the latest record without checking its availability timestamp. A record describing yesterday but arriving tomorrow is still unavailable today. Do not divide by zero or silently replace undefined ratios with real zero measurements.
Practice
Given a prediction at time 10, identify which events can be used. Then derive weight-distance and units-per-package features; document what happens for a zero denominator. Complete the chapter exercise and knowledge check. Scientific examples are local scikit-learn 1.8.0 static snippets; ByteMind execution support is not verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Feature availability and interactions — knowledge check
Apply feature engineering and leakage controls to synthetic scenarios.
An event occurred at 8 and arrived at 12. Prediction time is 10. Use it?
What does a product interaction of 3 and 4 equal?
A ratio denominator is zero. What is a defensible policy?
Why track feature units?
What checks train-serving consistency?