Lesson · ⏱ 7 min read
🛠️ Feature engineering: turning raw data into useful inputs
EnglishHinglish
🏠 Real-life example
A cricket selector doesn't just look at 'runs scored'. They compute strike rate, average against fast bowlers, and form over the last 5 matches. Those calculated numbers predict future performance far better than raw totals. Creating such helpful inputs is feature engineering.
💡 In simple words
Models only see the numbers you give them, so better features often beat a better algorithm. Common techniques: extract parts of dates (day of week, festival season), create ratios (amount ÷ average amount), and encode categories as numbers (one-hot encoding). Scale numeric features so big numbers don't dominate. Fill missing values sensibly, perhaps adding a flag that says 'was missing'. Domain knowledge, meaning knowing the business, is your biggest advantage here. Never use information from the future, such as 'was refunded', to predict the past. That's data leakage.
🪜 Step by step
- Brainstorm with domain experts: what signals do they use today to decide?
- Create ratios and differences: EMI to income ratio, change in spending vs last month.
- Create time features: days since last login, day of week, festival season flag.
- Encode categories (one hot or target encoding), handle missing values and scale numbers if the model needs it.
- Keep features that improve validation scores; drop the rest to keep the model simple.
🔑 Key terms
- One-hot encoding
- Turning a category like city into 0/1 columns.
- Scaling
- Putting numeric features on similar ranges.
- Data leakage
- Accidentally giving the model info it won't have at prediction time.
👀 See it in action
df["order_hour"] = df["created_at"].dt.hour
df["is_weekend"] = df["created_at"].dt.dayofweek >= 5
df["amount_vs_usual"] = df["amount"] / df.groupby("user_id")["amount"].transform("mean")
df = pd.get_dummies(df, columns=["city"]) # one-hot encode city'Amount vs this user's usual amount' is a classic fraud feature.
⚠️ Common mistakes to avoid
- Leakage: features calculated using future information or the answer itself.
- Computing features differently in training and in the live app. Use one shared function or pipeline.
✅ Quick check
To predict whether a loan will default, you include 'number of missed payments in the next 6 months'. What's wrong?
- Nothing, it's a great feature
- It needs scaling
- Data leakage: it's future information
Show answer
C. Data leakage: it's future information: At decision time you can't know future missed payments. The model would look great in testing and fail in real use.
🙋 Questions learners ask
Do deep learning models need feature engineering?
Less for images and text, because they learn features from raw data. For tabular business data, good features still matter a lot.
How do I know which features matter?
Use feature importance or SHAP values, and test by removing a feature and seeing if validation scores drop.
📌 Remember
Good features + domain knowledge > fancy algorithms. Watch out for leakage.
📖 Words from this lesson (AI dictionary)
Learn this as part of a full course
Track your progress, take the quick checks and follow the lessons in the right order. This lesson is part of:
Continue in the course