esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

What Is Feature Engineering?

What feature engineering is, the main techniques, a worked card-fraud example and the leakage mistake to avoid, explained for your AI interview.

In short

Feature engineering is turning raw data, like timestamps, amounts and merchant names, into numbers a model can learn from. Google calls it a vital part of machine learning, and the key rule is to learn its settings from training data only.

9 min readBeginnerOccasional · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Feature engineering means turning raw data into the inputs a model learns from. A bank's raw card record has a time, an amount and a merchant type. I turn the time into hour of day, the amount into a multiple of the card's usual spend, and the merchant into numbers. The one rule I hold to: any average I compute comes from training rows only, so the test rows never leak in.

What is feature engineering, in plain words?

Think of a loan officer at a bank. She doesn't read a customer's whole statement line by line. She works out what matters: how much comes in each month, and how often the account goes overdrawn. Those summaries are her features.

A card fraud model at a mid-size bank gets raw records: a timestamp, an amount and a merchant type. Models need numbers, so the team turns each one into a number that shows the pattern. That turning is the feature engineering.

Key words

Feature
One input the model learns from, such as hour of day or amount.
Feature vector
The row of numbers the model reads for one example.
One-hot encoding
Turning a category into zeros with a single 1 in its own slot.
Leakage
When information from test rows sneaks into training, so the score looks better than it really is.
Training and test rows
Training rows teach the model. Test rows are held back to check it on data it has not seen.

What are the main feature engineering techniques?

  • Scaling

    Squeeze numbers into a standard range, so one big number doesn't drown out the rest.

  • Bucketing (binning)

    Group numbers into ranges, such as night, morning, afternoon and evening for an hour of day.

  • One-hot encoding

    Give each category its own slot. Electronics becomes 0 0 1 0 across four merchant types.

  • Date and time parts

    Pull out the hour, weekday or month, which can carry a pattern the raw timestamp hides.

  • Ratios

    Divide one number by another, like this amount by the card's usual spend. The ratio often says more than either number alone.

Google's machine learning course puts the job in one line, and scikit-learn, a Python library for machine learning, explains why scaling matters for some models.

  • “You must determine the best way to represent raw dataset values as trainable values in the feature vector.”

    Google

  • “many learning algorithms such as linear models benefit from standardization of the data set”

    scikit-learn

How does it work, step by step?

  1. 1

    Pick what might help

    Ask which parts of the raw record could predict the outcome. Ask the people who know the business.

  2. 2

    Turn raw values into numbers

    Times become hours, categories become slots, and text becomes counts or codes.

  3. 3

    Scale or bucket the numbers

    Put numbers on a similar range. Models usually train faster and predict better that way.

  4. 4

    Test that it helped

    Measure on test rows the features never touched. If a feature doesn't move the score, drop it.

From a raw card record to model input

Raw card record

time, amount and merchant type

Your feature code

Hour of day

02:47 becomes 2

Amount vs usual

amount divided by normal spend

Merchant type

electronics becomes 0 0 1 0

Feature vector

all numbers, one row

Model

learns which patterns look like fraud

  1. 1The raw record goes into your feature code.
  2. 2The code turns each part into a number.
  3. 3The model reads one row of numbers.
One card record goes through the feature code and comes out as one row of numbers. In this pipeline the model learns from that row.

What does a worked example look like?

Here is a small, simplified version of the card fraud step. The made-up numbers describe a card that usually spends about 46 dollars a purchase.

Python
# A simplified card-fraud feature step for a mid-size bank. Made-up numbers.
from datetime import datetime

CATEGORIES = ["grocery", "travel", "electronics", "fuel"]

def features(txn, usual_spend):
    # Turn a raw record into numbers the model can learn from.
    hour = datetime.fromisoformat(txn["time"]).hour
    avg = sum(usual_spend) / len(usual_spend)
    ratio = round(txn["amount"] / avg, 2)  # this amount vs the card's normal spend
    one_hot = [1.0 if txn["category"] == c else 0.0 for c in CATEGORIES]
    return [float(hour), ratio] + one_hot

usual = [42.50, 38.00, 55.20, 47.90]  # the card's last four normal purchases
night_buy = {"time": "2026-03-14T02:47:00", "amount": 1849.00, "category": "electronics"}
day_buy = {"time": "2026-03-14T12:10:00", "amount": 52.10, "category": "grocery"}

print("night purchase:", features(night_buy, usual))
print("day purchase:", features(day_buy, usual))

Output

night purchase: [2.0, 40.28, 0.0, 0.0, 1.0, 0.0]
day purchase: [12.0, 1.14, 1.0, 0.0, 0.0, 0.0]

Read the first line of output. The purchase happened at 2 a.m., and it is about forty times the card's usual spend, in electronics. The second line is a 52 dollar grocery purchase at noon. Its ratio stays close to 1, so it looks like the card's normal spending.

What is the most common mistake?

The most common mistake is leakage. Scikit-learn defines it as "Data leakage occurs when information that would not be available at prediction time is used when building the model." Its scaling example is simple: the average has to come from the training rows.

Scikit-learn warns that "If the test subset is included in the average calculation, information from the test subset is influencing the model."

Where the scaling average comes from

Split the data

training rows and test rows, apart

Wrong way

Average of all rows

test rows leak into the average

Right way

Average of train rows

test rows never touch it

Score looks too good

overstates the real result

Honest score

how it does on new cards

  1. 1Test rows get mixed into the average.
  2. 2Only training rows feed the average.
  3. 3The inflated average makes the score look better.
  4. 4The honest score shows how the model does on new cards.
Two ways to scale the same data. The wrong way lets test rows into the average, so the score looks better than it is. The right way learns the average from training rows only.

Tip

Asked about leakage? Say that every average, range and scaler is learnt from training rows only, then applied to the test rows. Never fit anything on the test rows.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: turning raw data into numbers a model can learn from.
  • The main techniques: scaling, bucketing, one-hot encoding and ratios.
  • A worked example from a real problem, with the numbers.
  • Leakage: every average and range learnt from training data only.
  • The steps in order: pick the features, turn them into numbers, scale them, then test on rows the model never saw.

Common traps

  • Trap"More features always make the model better."

    BetterExtra features can add noise. Keep the ones that help on test rows.

  • Trap"Scale the whole dataset, then split it."

    BetterThat leaks test rows into the average. Split first, then fit the scaler on training rows only.

  • Trap"Feature engineering is an old step we can skip."

    BetterRaw bank records are rarely ready for a model as they are. Skipping this step is a choice you must justify with test results.

Can you spot the leak?

Spot the leak

Which step lets test rows leak into the model?

Quick check

A card fraud model sees a 1,849 dollar purchase. Which feature best shows it is unusual for this card?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q424What is data leakage?11 min
  2. Q423What is cross-validation?13 min
  3. Q425How do you handle class imbalance?12 min
  4. Q430What is a confusion matrix?10 min

Learn it in depth

Last updated on 27 November 2026

Building a model on your company's raw data?

I design and build AI products and agents, and the system and screens behind them. Book a short call and say what data you have and what you need it to decide.