C.W.K.
Stream
Lesson 02 of 05 · published

Feature Engineering as Leverage

~30 min · features, engineering

Level 0Scout
0 XP0/48 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Where the lift comes from

Past the baseline, feature engineering buys more performance per hour than hyperparameter tuning. The trick is engineering features that respect the time-of-prediction constraint. Aggregations over a time window, ratios, lags, and domain-specific groupings consistently outperform raw fields.

The pattern catalog

  • Time-window aggregates — count/sum/mean over the last 7/30/90 days, computed as of prediction time.
  • Ratios — value over a baseline ("this user's spend / their plan's average spend").
  • Recency / frequency — days since last action, count of actions per period.
  • Categorical interactions — pairs that represent business segments ("tier × region").
  • Cross-entity rollups — features about the user's organization, not just the user.

The leakage check on every feature

For each engineered feature, write a one-sentence proof that it could be computed at prediction time, with the data available at that exact moment. If the proof is hard, the feature is leakage.

Code

Time-aware rolling window in pandas·python
df = df.sort_values(["user_id", "event_time"])
df["tickets_30d"] = (
    df.groupby("user_id")
      .rolling("30D", on="event_time")["ticket_count"]
      .sum()
      .reset_index(level=0, drop=True)
)
Ratio and recency features·python
df["spend_vs_plan_avg"] = df["monthly_spend"] / df.groupby("plan_tier")["monthly_spend"].transform("median")
df["days_since_last_login"] = (df["prediction_time"] - df["last_login_at"]).dt.days

External links

Exercise

Add three engineered features to your dataset: one rolling time-window aggregate, one ratio, one recency. For each, write the one-sentence prediction-time legality proof. Re-run CV and report the lift.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.