Machine LearningFeature Engineering

"A model can only learn from what you show it, so the right feature can turn messy data into a surprisingly accurate prediction."

Feature Engineering

Explains the concept of feature engineering and its impact on model performance.

~25 min readPart of: Machine Learning

Why feature engineering matters

Imagine giving a chef raw groceries versus prepped ingredients: same food, very different results. Feature engineering is the process of transforming raw data into inputs that make patterns easier for a model to detect. A housing model may receive square_feet, bedrooms, and year_built, but a better feature might be price per square foot, home age, or distance to downtown.

Models are picky. A linear model may miss a curved relationship unless you create a feature like age^2. A model may also struggle with dates unless you extract useful parts like day of week, month, or is_weekend.

Good feature engineering does two things:

  • reveals structure already hiding in the data
  • reduces noise and ambiguity

It does not mean adding random columns. Every new feature should help the model answer the prediction question more directly.

Common ways to engineer features

A strong feature often comes from combining, reshaping, or re-expressing existing data. Suppose you're predicting whether a customer will churn from a music app.

Useful transformations include:

  • Combining features: songs_skipped / songs_played gives a skip rate
  • Extracting from dates: signup_month, days_since_last_login
  • Encoding categories: turn plan_type = premium/free/family into model-readable columns
  • Scaling numbers: put monthly_minutes and account_age_days on comparable ranges
  • Nonlinear features: usage^2 can capture curves

A worked example: if a user played 120 songs and skipped 30, then

skip_rate = 30 / 120 = 0.25

That single ratio may be more predictive than the two raw counts separately, because it captures behavior, not just volume.

Example in code: from raw columns to better features

Here is a small Python example using customer data. We turn timestamps and counts into features a model can use more effectively.

import pandas as pd

df = pd.DataFrame({
    'signup_date': ['2024-01-10', '2024-03-02'],
    'last_login': ['2024-04-10', '2024-04-11'],
    'songs_played': [120, 40],
    'songs_skipped': [30, 20],
    'plan_type': ['premium', 'free']
})

df['signup_date'] = pd.to_datetime(df['signup_date'])
df['last_login'] = pd.to_datetime(df['last_login'])
df['days_active'] = (df['last_login'] - df['signup_date']).dt.days
df['skip_rate'] = df['songs_skipped'] / df['songs_played']
df = pd.get_dummies(df, columns=['plan_type'], drop_first=True)

Now the model sees days_active, skip_rate, and a numeric encoding of plan_type. These features are closer to the real question: how engaged is this user, and what kind of plan are they on?

How to know if your engineered features helped

Feature engineering is an experiment, not decoration. Add a feature, then check whether validation performance improves. For example, if a baseline model predicts house prices with a mean absolute error of $28,000, and adding home_age plus distance_to_subway lowers it to $22,500, those features likely added real signal.

Use this practical checklist:

  • start with a simple baseline
  • add one or a few thoughtful features
  • test on validation data, not training data
  • remove features that add complexity but no gain
  • watch for leakage and overfitting

A good question to ask is: Would a human expert care about this transformation? If a loan officer, doctor, or marketer would find it meaningful, your model probably will too. Great feature engineering is domain knowledge translated into numbers.

Study this interactively on Wisdemic

Test your understanding with inline MCQs, track your mastery score, and get scheduled review reminders — free.

Start learning for free
← Previous
Data Preprocessing
Next →
Model Selection