Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Machine Learning for Finance & Accounting Level Two · Lesson 4 of 9

Module Three

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
4
Module 3: Classification for Financial Decisions for Young Coders
⭐ Module 3 · Level Two

Classification for
Financial Decisions

⚖️ Sorting the world into yes, no, or "which one?"

🎯 What you'll learn in this module

  • ✔ How logistic regression predicts yes/no outcomes
  • ✔ How decision trees make rules you can read
  • ✔ How Naive Bayes and K‑nearest neighbors work
  • ✔ How to handle class imbalance in financial datasets
  • ✔ How to read a confusion matrix, precision, recall, and F1
  • ✔ How ROC curves and AUC help in credit and fraud contexts
🎯
What Is Classification?
The Big Idea

Classification predicts a category — a choice among options. Will this customer pay or default? Is this transaction fraud or legitimate? Which category does this expense belong to?

Where regression predicts numbers ("how much?"), classification predicts labels ("which one?"). In finance, many of the most important decisions are classification problems: approve/decline, fraud/not fraud, high risk / low risk.

🚦 Regression asks "what's the speed?" Classification asks "should we stop or go?" Both are useful — but in different situations.
📉
Logistic Regression: The Probability Machine
Model

Logistic regression predicts a probability between 0 and 1. It's the workhorse of binary classification in finance — especially for credit scoring.

Each feature contributes to the probability. If the probability crosses a threshold (say 50%), you predict "yes." The model is interpretable: each feature's coefficient tells you how it shifts the odds of default.

It's still widely used today because regulators love it — you can explain every prediction in plain language.

🎚️ A dimmer switch for the probability of an event: each input nudges the dial slightly up or down.
🌳
Decision Trees: Rules You Can Read
Model

A decision tree asks a series of yes/no questions, narrowing down to a final prediction:

"Is income > $50,000?" → "Yes" → "Is debt < $10,000?" → "Yes" → "Approve loan."

You can literally read the tree and understand it. That's why regulators, doctors, and business teams love it. But trees alone overfit easily — they memorize the training data. That's why we also learn about forests later.

🌲 A tree is like a game of 20 Questions: each answer narrows down the possibilities until there's only one left.
🔮
Naive Bayes & K‑Nearest Neighbors
Model

Naive Bayes uses probabilities of each feature given each class, then applies Bayes' rule to predict. It's simple, fast, and surprisingly strong for text — e.g., classifying expense descriptions ("AMZN" → "Office Supplies").

K‑nearest neighbors (KNN) predicts by looking at the K closest training examples in feature space. If your neighbors mostly defaulted, you probably will too. Very intuitive — and great for detecting unusual patterns.

👥 Naive Bayes is like reasoning about probabilities. KNN is like asking your five closest friends how they voted.
⚖️
Class Imbalance: When One Side Wins Too Often
Challenge

Most financial classification problems are imbalanced: only 2% of loans default, only 0.1% of transactions are fraud. A naive model can say "no one defaults" and still be 98% accurate — but useless.

Fixes: class weighting (tell the model to care more about the rare class), oversampling (duplicate or synthesize minority examples), undersampling (drop some majority examples), and threshold tuning (predict the rare class more easily).

🎯 If 98 out of 100 darts hit blue and 2 hit red, "always guess blue" is 98% accurate — and you'll never find a red dart.
🧩
Confusion Matrix, Precision, Recall & F1
Evaluation

The confusion matrix shows every prediction against reality:

Predicted Fraud
Predicted OK
Actually Fraud
True Positive ✅
False Negative ❌
Actually OK
False Positive ⚠️
True Negative ✅

Precision = of the ones we flagged, how many were real? Recall = of the real ones, how many did we catch? F1 balances both. In finance, the right balance depends on the cost of false alarms vs. missed fraud.

🚨 A fire alarm: precision = "how often the alarm is a real fire." Recall = "how many real fires we detect." A sensitive alarm catches more fires (high recall) but alarms on toast (low precision).
📈
ROC Curves & AUC
Evaluation

The ROC curve plots true positive rate vs. false positive rate at every possible threshold. A model with a strong curve sits close to the top‑left corner — catching most positives without too many false alarms.

AUC (Area Under the Curve) summarizes the whole curve in one number. 0.5 = random guessing. 1.0 = perfect model. In credit scoring and fraud detection, AUC is one of the most‑cited metrics — and easy to compare across models.

🎼 The ROC curve is the whole song; AUC is the review score (from 0.5 "meh" to 1.0 "masterpiece").
⚠️ Accuracy isn't everything: In imbalanced finance problems, a model with 95% accuracy can be worse than useless — it can miss every fraud case. Always look at precision, recall, F1, and AUC together, and always ask: what's the cost of false positives vs. false negatives?

🛠️ Hands-on activities (no boring stuff!)

1

Binary thinking: List three financial decisions that are classification problems and three that are regression problems. Explain each in one sentence.

2

Tree rules: Write a small decision tree by hand for a "should I lend money?" scenario. Use 3–4 yes/no questions. Test it on three imaginary applicants and see who gets approved.

3

Imbalance math: In a fraud dataset, 995 transactions are legitimate, 5 are fraud. What's the accuracy of "always say not fraud"? What's the recall? Explain why this "high‑accuracy" model is useless.

4

Confusion matrix reading: Given a 2x2 confusion matrix with TP=8, FP=4, FN=2, TN=86, compute precision and recall by hand. Then compare: which is more important for fraud detection — precision or recall?

5

Alarm tradeoff: Set a low threshold — you catch every fraud but get lots of false alarms. Set a high threshold — you catch few frauds but few false alarms. Describe the real‑world tradeoff in 2 sentences. Which matters most for a card issuer?

6

Model selector: For each scenario, pick logistic regression, decision tree, or KNN and justify: (a) you need to explain every rejection to a customer; (b) you're classifying short transaction descriptions; (c) you're detecting unusual vendor patterns.

🏆

By the end of this module, you'll be able to: build classifiers with logistic regression, trees, Naive Bayes, and KNN, handle class imbalance, read confusion matrices, compute precision and recall, and interpret ROC/AUC like a finance pro.

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→