Feature Engineering

Turning domain knowledge into informative inputs: aggregates, ratios, date parts, text counts, interactions and transformations.

Intermediate · about 10 hours · difficulty 3/5

Learn first: Data Cleaning and Missing Values

For tabular problems, good features beat fancy algorithms. Feature engineering encodes what you know about the domain in a form models can use.

Common patterns

  • Datetime features: hour, weekday, month, holidays, time since an event. Use cyclical sine/cosine encoding for hour or month when order wraps around.
  • Aggregates: counts, means and recency per user, product or region (group-by features).
  • Ratios and differences: price per square foot, debt to income.
  • Transformations: log1p for heavy-tailed values, binning when relationships are step-like.
  • Interactions: products of features for linear models; trees find many interactions on their own.
  • Text and geo basics: word counts, TF-IDF, distances to landmarks.

Process

Add features one idea at a time and measure the change in cross-validated score. Keep a log of what helped. Remove features that add noise or are expensive to compute in production.

Pitfalls

Aggregates computed over the whole dataset (including the future or the test set) leak information. Features that are unavailable at prediction time are useless no matter how predictive they look offline.

Good enough to move on when you can add three to five engineered features to a baseline and demonstrate their value with cross-validation.

Key concepts

  • Datetime and cyclical features
  • Group-by aggregates
  • Ratios and domain features
  • Log and power transforms
  • Interaction and polynomial features
  • Feature selection: Importance, RFE, mutual information
  • Automated feature tools

Mini project

On the Kaggle Bike Sharing Demand dataset, engineer datetime, weather and rolling features and report the cross-validated RMSE gain of each feature group over a baseline.

Check yourself

Why might a feature that improves validation score still be a bad feature to ship?

Free resources