Module 10 · Feature Engineering: Making Data Model-Ready · Lesson 34 of 51
Building a feature table from raw data
Turn 4,420 order rows into one row per branch per day, build recency, frequency and spend (RFM) features for customers, and judge which features carry signal.
In this lesson · about 45 minutes
- Aggregate event rows into one row per thing you want to predict
- Build recency, frequency and monetary (RFM) features with a cut-off date
- Rank features by their relationship with the target and drop weak or redundant ones
One row per branch per day
Exercise
Build the branch-day table
Make day with one row per branch and date and columns orders (distinct order ids), sales (sum of total) and app_share (share of rows paid with "App"). Then set n_rows to the number of rows, and best to the (branch, date as "YYYY-MM-DD") with the highest sales.
Code that runs before yours
import pandas as pd
import numpy as np
orders = pd.read_csv("kc_orders.csv", parse_dates=["date"])Exercise
RFM for loyalty-card customers
The loyalty system logs purchases with a card id. Build rfm with one row per card and columns recency (days from the last purchase to the cut-off 2026-06-30), frequency (number of purchases) and monetary (total spend). Then set top to the card with the highest monetary value and avg_recency to the mean recency rounded to 1 decimal.
Code that runs before yours
import pandas as pd
log = pd.DataFrame({
"card": ["C1", "C2", "C1", "C3", "C2", "C1", "C4", "C3", "C2", "C1"],
"date": pd.to_datetime(["2026-04-02", "2026-04-10", "2026-05-01", "2026-05-03", "2026-05-20", "2026-06-01", "2026-03-15", "2026-06-25", "2026-06-28", "2026-06-29"]),
"spend": [8.5, 22.0, 6.0, 15.5, 30.0, 9.0, 4.5, 12.0, 41.0, 7.5],
})Which features to keep?
More features isn't always better: weak ones add noise, and near-duplicates confuse linear models. Quick checks:
- Relationship with the target: churn rate by feature band, correlation, or mutual information (
sklearn.feature_selection.mutual_info_classif), which also catches non-linear patterns. - Redundancy: if two features correlate above about 0.9, keep the one that's easier to explain.
- Variance: a column that's the same for 99% of rows rarely helps.
- Model importance: after fitting (Module 12), permutation importance shows what the model really uses.
And always the common-sense check: would a manager believe this feature could cause or signal the outcome?
Which member features relate to churn?
Exercise
Rank features by correlation
Set ranking to the list of the numeric columns age, tenure_months, visits_90d, avg_spend, app_user and complaints, ordered by the absolute correlation with churned, strongest first. Set strongest to that top correlation (with its sign) rounded to 3 decimals.
Code that runs before yours
import pandas as pd
import numpy as np
members = pd.read_csv("kc_members.csv")Flashcards
Module 10 flashcards
0 of 10 known
Say the answer out loud, flip the card, then be honest: cards you miss come back at the end.
Practice exam
Module 10 checkpoint
10 questions, 12 minutes.
- 10 questions · 12 minutes
- No feedback until you submit. Flag questions to come back to them.
- Aim for 85% or better before you move on. The real exam's 750 out of 900 is roughly 80–83%.
Exercises solved: 0 of 3
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.