Phase 02: ML Fundamentals

Handling Imbalanced Data

When 99% of your data is "normal," accuracy is a lie. Language: Python Implement SMOTE from scratch and explain how synthetic oversampling differs from random duplication. Evaluate imbalanced classifiers using F1, AUPRC, and Matthews Correlation Coefficient instead of accuracy. Compare class weighting, threshold tuning, and resampling strategies and select the right approach for a given imbalance ratio. Build a complete imbalanced data pipeline that combines SMOTE, class weights, and threshold optimization. You build a fraud detection model. It gets 99.9% accuracy. You celebrate. Then you realize it predicts "not fraud" for every single transaction. This is not a bug. It is the rational thing to do when only 0.1% of transactions are fraudulent. The model learns that always guessing the majority class minimizes overall error. It is technically correct and completely useless. This happens everywhere real classification matters. Disease diagnosis: 1% positive rate. Network intrusion: 0.01% attacks. Manufacturing defects: 0.5% defective. Spam filtering: 20% spam. Churn prediction: 5% churners. The more consequential the minority class, the rarer it tends to be. Accuracy fails because it treats all correct predictions equally. Correctly labeling a legitimate transaction and correctly catching fraud both count as one point of accuracy. But catching fraud is the entire reason the model exists. We need metrics, techniques, and training strategies that force the model to pay attention…

Handling Imbalanced Data: When 99% of your data is "normal," accuracy is a lie. Language: Python Implement SMOTE from scratch and explain how synthetic…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.