Show a model past loans and how they turned out. It learns to judge new ones.
Each dot is a past applicant, placed by two facts the lender knew at the time: their credit score (across) and their debt-to-income ratio, the share of monthly income already going to debt payments (up).
Those inputs are called features. What actually happened, repaid or defaulted, is the label. Learning from labelled examples like this is called supervised learning, and it is how most business AI works.
The test set
Some applicants are held back and never shown to the models. Turn on Show test set to see them. Every score on this page is measured on those unseen people, because, as module 01 showed, doing well on data you trained on proves very little.
Applicants are generated example data, not real people. Real credit models use many more features.
A decision tree asks yes-or-no questions, one after another.
The tree looks for the single question that best separates repaid from defaulted, such as "is the credit score below 640?". Then it does the same again inside each half, and again, building a flowchart.
The depth is how many questions it may ask in a row. Shaded blue areas get approved; red areas get denied. Below the chart are the exact rules, in plain language.
Watch the score
Raise the depth and the tree starts carving tiny boxes around individual dots. Training accuracy keeps climbing, but test accuracy stops improving and usually drops. It is the same overfitting you saw in module 01.
Why lenders like trees
Every decision can be explained as a short list of rules. That matters: in the US, a lender that turns someone down must tell them the specific reasons.
Find the most similar past applicants, and go with what happened to them.
Nearest neighbours barely learns anything up front. When a new applicant arrives, it finds the past applicants most similar to them and lets them vote. If most of the 9 closest people repaid, approve.
Click the chart to drop in an applicant and see who their neighbours are. The shading shows what it would decide anywhere on the map.
Choosing how many neighbours
With 1 neighbour, the map turns patchy: one unlucky dot can flip a whole area. With 41 it gets smooth but starts ignoring real patterns. Somewhere in between scores best on the test set.
A practical catch
"Similar" needs a sense of distance. A credit score runs into the hundreds while debt-to-income is a percentage, so the inputs have to be rescaled to the same range first, or the score would drown out everything else. This page does that for you.
Sometimes there is no right answer to learn from. Clustering finds the groups on its own.
These are example brokerage clients, placed by how often they trade (across) and how large their account is (up). Nobody has labelled them. The goal is just to find natural groups, called unsupervised learning.
k-means drops in a few group centres (the crosses), then repeats two moves: give every client to the nearest centre, then move each centre to the middle of its clients. Press One step to watch each move, or Run.
How many groups?
You choose. The chart below shows how tightly packed the groups are for each choice. It always improves with more groups, so look for the elbow, where adding another stops helping much.
Press New start a few times with 4 or 5 groups: different starting spots can settle on different answers. Real tools run it many times and keep the best.
Where it is used
Customer segmentation: deciding which clients get which service model, which products to pitch, and which accounts look unusual.
Which method wins? It depends on the data, so you test them.
Retrained in your browser each time. "Always approve" is the baseline: what you would score by not using a model at all.
| Method | How it decides | Easy to explain? |
|---|---|---|
| Logistic regression | Draws one straight dividing line, fitted with gradient descent from module 01 | Yes: a weight per feature |
| Decision tree | A flowchart of yes-or-no questions | Yes: a short list of rules |
| Random forest | Hundreds of slightly different trees vote | Partly: needs extra tools |
| Nearest neighbours | Copies the outcome of the most similar past cases | Partly: "people like you" |
The bars show each method's accuracy on the test applicants, using sensible settings. Press New data to draw a fresh set of applicants and run the contest again; the order shifts from run to run.
What the industry uses
For data in rows and columns, like loan files, transactions and account records, the strongest methods today are still built from trees: random forests and their stronger cousin, gradient-boosted trees. Deep learning wins on images, sound and language; trees usually win on spreadsheets.
On this small example, with only two features and a fairly straight boundary, simple logistic regression often comes out on top. Trees pull ahead on real files with dozens of features that interact in messy ways.
The trade-off
The most accurate model is not always the one a bank can use. Regulators expect lenders to explain decisions and show they are fair, so a slightly weaker model that can be explained often beats a stronger black box.
Next in the course, neural networks: the method that powers images, language and everything else in the Generative AI track.