Day 19: Project: return-probability model — feature engineering
FitXpert project: predicting garment returns
Time to apply the week. Using tabular order data (garment category, size, price, customer history, whether the returned size differed from usual), you'll build a model that predicts return probability. Today is feature engineering — turning raw columns into signals a model can learn from. This is where domain knowledge beats algorithm choice: a good feature helps more than a fancier model.
Encoding categorical features
Models need numbers, but 'category = saree' is a string. One-hot encoding turns one categorical column into several 0/1 columns (one per value). Ordinal encoding maps categories to integers — only valid when there's a real order (XS < S < M < L). Using ordinal encoding on unordered categories accidentally tells the model 'shoes' is greater than 'shirt', a subtle bug.
import pandas as pd
# derived features that carry real return signal
orders["price_vs_category_avg"] = orders["price"] / orders.groupby("category")["price"].transform("mean")
orders["size_deviation"] = (orders["ordered_size_idx"] - orders["usual_size_idx"]).abs()
orders["is_first_purchase"] = (orders["prior_order_count"] == 0).astype(int)
# one-hot encode the unordered category column
orders = pd.get_dummies(orders, columns=["category"], prefix="cat")The unglamorous truth
In tabular ML, most of the win comes from features like size_deviation — a domain insight ('people who order a size different from usual return more often') expressed as a number. The roadmap calls dataset and feature craft 'the unglamorous 70%'; that framing applies here and returns in force at Stage 4.
Key terms
- Feature engineering
- Transforming raw data into informative numeric inputs (features) that expose signal to the model.
- One-hot encoding
- Representing an unordered categorical value as a set of 0/1 columns, one per possible value.
- Ordinal encoding
- Mapping categories to integers — valid only when the categories have a genuine order.
You encode garment category (shirt, dress, saree, shoes) as integers 0,1,2,3 and feed it to a linear model. What subtle problem does this introduce?