Project 6 of 10, for Paul
Loan Approval Tree
Approve or decline a loan from seven answers on the form, for 1,000 real applicants: a decision tree grown from scratch and read as questions, then a random forest from scratch and gradient boosting, judged by what their mistakes cost.
Sign up free to open itLog in
Act 6 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- PaulIf a lender says no, they should be able to explain it with actual questions written down, rather than just a score.
- PaulThere's a German bank's thousand applicants, public since the nineties, with seven answers each and whether they repaid.
- RiyaI've started growing one already. How deep can it go?
- PaulAs deep as the questions stay true, and then you stop.
loans.csv holds 1,000 real past applicants: their checking account (0 overdrawn, 1 under 200 DM, 2 200 DM or more, 3 none), the loan's length in months, their credit history (0 to 4, worse as it rises), the amount, their savings (0 to 4) and years in work (0 to 4), their age, and whether they repaid.
In loans.py:
- Grow a tree of yes-or-no questions from scratch, choosing each question by how well it sorts the applicants. Lock a fifth of the applicants away for testing, choose the depth on validation applicants, print the chosen tree as questions, and test it once against approving everyone.
- Grow a forest of 50 different trees from scratch: each tree learns from its own random draw of applicants, and each question looks at three columns chosen at random. Approve when half the trees say so.
- Boost small trees with scikit-learn, each fixing what the last got wrong.
- Compare them all on the test applicants by accuracy and by the bank's cost: 5 for a bad loan approved, 1 for a good one declined. Then the forest again, approving only when five trees in six agree.
depth training validation
1 0.718 0.700
2 0.747 0.685
3 0.778 0.735
4 0.793 0.735
5 0.808 0.715
6 0.838 0.675
8 0.888 0.680
Chosen depth: 3
checking <= 1.5?
yes: duration_months <= 22.5?
yes: history <= 1.5?
yes: decline
no: approve
no: savings <= 0.5?
yes: decline
no: approve
no: amount <= 10924.5?
yes: employment <= 2.5?
yes: approve
no: approve
no: amount <= 12714.5?
yes: decline
no: approve
accuracy cost
Approving everyone 0.645 1.775
One tree, depth 3 0.745 1.075
A forest of 50 trees 0.740 1.200
Boosting, 100 rounds 0.750 1.130
The forest, 5 in 6 sure 0.655 0.665What you learn
What's in it
- A chain of questions
- Follow the questions
- How mixed is a pile?
- How mixed is a pile
- Finding the best question
- How Paul would find one question
- Growing the tree
- Fix Riya's version
- Grow the loan tree
- A panel of guessers
- Fifty guessers
- A forest of different trees
- Drawn with putting back
- Each tree fixes the last
- How Paul would boost
- What a mistake costs
- Ask the whole forest
- Ship it