← All Base Form ML projects
BL-05NOT STARTEDBASE FORM · CLASSICAL MLMLPYTHON

Loan decision explainer

A decision tree that approves or rejects loans and prints its reasoning as plain if-then rules.

EST.7 h
REWARD+100 XP
AFTERBreiman et al.

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
accuracy at the same depth
GOAL · within 1%
sklearn DecisionTreeClassifier—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

When a bank says no, the applicant deserves a reason. Many models can't give one, but a decision tree can: it is a list of questions, and the path an applicant takes is the explanation. In this project you grow a tree from scratch, check it against scikit-learn, and print its logic as plain if-then rules.

The data is the Statlog (German Credit Data) dataset from the UCI Machine Learning Repository. It has 1,000 past loan applicants with 20 attributes, such as checking account status, loan duration, credit history and purpose, and a label of good or bad credit risk. 700 are good and 300 are bad. The raw file uses codes like A11 for categories, so read the dataset description to name them.

A tree is built greedily. At each node you try every feature and every threshold, and keep the split that makes the two children purest. Purity is measured with Gini impurity, where pkp_k is the share of class kk in the node:

G=1−∑kpk2.G = 1 - \sum_k p_k^2.

A split into left and right children is scored by the weighted impurity nLnGL+nRnGR\frac{n_L}{n} G_L + \frac{n_R}{n} G_R, and the best split has the lowest score. Then you repeat on each child until you hit a depth limit or the node is pure. This is the CART method from Breiman and colleagues, and it is also what sklearn's DecisionTreeClassifier does.

VISUALFig. 1
checking balance < 0? yesno duration ≤ 22 mo? duration ≤ 36 mo? yesno yesno approven=160 rejectn=90 approven=480 rejectn=70 RULES IF balance < 0 AND duration ≤ 22THEN approve (160) IF balance < 0 AND duration > 22THEN reject (90) IF balance ≥ 0 AND duration ≤ 36THEN approve (480) IF balance ≥ 0 AND duration > 36THEN reject (70)
A depth-2 tree and the rules it prints. Features and counts are illustrative. Why it's here: Shows the two outputs objective 5 asks for side by side: the tree and the same tree as rules.
HINT · OBJECTIVE 2
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 4
Stuck? Hints stay hidden until you ask.

DATA · a public credit dataset

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. At every depth from 1 to 8, your test accuracy is within 1% of sklearn DecisionTreeClassifier on the same split. Record your accuracy at your chosen depth with `python tools/mlarena.py record BL-05 "<your accuracy>"`.
  2. The rule printout for a depth-3 tree reads as plain English and agrees with export_text on the same data.
  3. The README says which depth you would ship and why, using the train and test accuracy curves.

Side quests

The dataset ships with a cost matrix where approving a bad loan costs five times rejecting a good one. Pick the leaf threshold that minimises that cost and report it.
The data includes personal status and sex, and whether the applicant is a foreign worker. Train without them and compare both the accuracy and which rules change.

Terms in plain words

Decision tree
A model that asks a chain of yes/no questions about the features and gives the answer stored at the leaf it ends up in.
Gini impurity
The chance that two applicants drawn at random from a node have different labels. 0 means the node is pure.
Split
One question of the form "is feature j at most t?", which sends each row to the left or right child.
CART
Classification and Regression Trees, the greedy recipe of picking the best split, recursing on each side, and stopping at a depth or size limit.
Overfitting
A deep tree can memorise the training rows and do worse on new ones. Limiting depth is the simplest cure.