WEEK 2 Lesson 5
Title:
Feature Engineering Basics
Theme
Turning Raw Data into Machine Intelligence
Why This Lesson Exists
Most beginners believe better models create better AI.
In reality:
Good features beat complex models.
A simple model with strong features often outperforms a complex neural network trained on poor data.
Feature engineering is where domain understanding meets machine learning.
This lesson teaches students how to transform raw data into signals models can actually learn from.
Lesson Objective
By the end of this lesson, students will:
✔ Understand why features matter more than algorithms
✔ Apply scaling and normalization correctly
✔ Encode categorical data for ML models
✔ Extract basic features from text data
✔ Develop intuition about feature importance
Lesson Structure.
1. What is a Feature?
A feature is any measurable property used by a model.
Example — Loan Prediction Dataset
Raw Data | Feature Used by Model
Age | Numeric feature
City | Encoded category
Salary | Scaled numeric
Transaction history Aggregated feature
Models do not understand meaning — only numbers.
Your job: Convert reality into numbers intelligently.
2. Why Features Matter More Than Models
Demonstration Concept.
Same dataset:
Model A: Logistic Regression + strong features → 85% accuracy
Model B: Neural Network + poor features → 65% accuracy
Lesson:
AI success = Data Representation Quality.
Key Principle:
Performance ≈ Data Quality × Feature Quality × Model Choice
Not the other way around.
3. Scaling & Normalization
Many algorithms assume comparable numeric ranges.
Problem Example:
Feature | Value Range
Income | 10,000–2,000,000
Age | 18–60
Income dominates learning unfairly.
Standard Scaling (Z-score)
Centers data around zero.
Python
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
df[['income','age']] = scaler.fit_transform(df[['income','age']])
Min-Max Normalization
Rescales between 0 and 1.
Python
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
df[['income']] = scaler.fit_transform(df[['income']])
When to Scale
✓ KNN
✓ Neural networks
✓ Gradient descent models
Usually unnecessary for:
❌ Tree-based models (Random Forest, XGBoost)
4. Encoding Categorical Variables
Machines cannot read text categories directly.
One-Hot Encoding
Python
pd.get_dummies(df['city'])
Result:
Lagos | Abuja | Accra
1 0 | | 0
Best for:
Low-cardinality categories.
Label Encoding
Python
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df['gender'] = le.fit_transform(df['gender'])
Use carefully — may introduce false ordering.
Practical African Context
Common categorical data:
Language
Region
Payment type
Device type
Network provider
Students learn to encode responsibly.
5. Basic Text Feature Extraction
Text must also become numbers.
Bag of Words
Python
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(df['message'])
Counts word frequency.
TF-IDF (Better Baseline)
Python
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf = TfidfVectorizer()
X = tfidf.fit_transform(df['message'])
Highlights meaningful words.
Example Use Cases
SMS fraud detection
Customer feedback analysis
Social media sentiment
Support ticket classification.
6. Feature Importance Intuition
Not all features help equally.
Students learn to ask:
Which variables actually influence predictions?
Which features add noise?
Example (Tree Model)
Python
model.feature_importances_
Visualization helps explain models.
Why This Matters
Feature importance enables:
✔ Explainable AI
✔ Bias detection
✔ Better data collection decisions
7. Feature Engineering Mindset
Students adopt this thinking loop:
Observe data
↓
Hypothesize useful signal
↓
Create feature
↓
Test performance
↓
Iterate
AI development becomes experimental science, not guesswork.
Mini Practice Exercise
Students will:
Load dataset.
Encode categorical columns.
Scale numeric features.
Create one derived feature:
Example: income_per_age.
Train simple model and compare results.
Common Beginner Mistakes (Important Section)
❌ Scaling before train/test split (data leakage)
❌ Encoding categories inconsistently
❌ Creating too many useless features
❌ Ignoring domain knowledge
Real-World Insight
In industry:
Data scientists spend 60–80% of time on feature engineering and data preparation — not modeling.
This lesson reveals the reality of AI work.
Lesson Outcome
By the end of Lesson 5, students can:
✔ Transform raw datasets into ML-ready features
✔ Apply scaling and normalization correctly
✔ Encode categorical variables safely
✔ Extract numerical features from text
✔ Understand why feature design drives model performance
Next:
Week 2 — Lesson 6: Model Lifecycle & Production Thinking
—the integration lesson that turns students from learners into AI system thinkers
Powered by Soft AI Africa | Training the Next Generation of AI Leaders in Africa.