Project 02 · Classification

A decision tree on a 61-row loan sample

A small classification exercise that produced a high holdout score—and a clear lesson about sample size and model validation.

Download notebook ↓ · All projects

Data: loan.csv · 61 records · 8 original fields
Period: Course project
Tools: Python, pandas, scikit-learn, Seaborn, Matplotlib

Question

Can applicant attributes help a decision tree distinguish the recorded approved and denied loan outcomes?

Approach

I one-hot encoded the non-target columns, split the 61 rows 50/50, fit a default DecisionTreeClassifier, and reviewed accuracy, a classification report, and a confusion matrix.

  1. Inspect the sample

    The notebook checks fields, types, missingness, and outcome counts before preparing model inputs.

  2. Encode and split

    Categorical and numeric columns are one-hot encoded. A single 50/50 train-test split leaves only 31 records for evaluation.

  3. Evaluate the errors

    Accuracy is paired with class-level precision and recall and a confusion matrix, which is more informative than a score alone.

Findings and limitations

Observed finding

The saved run scored 30 of 31 test records correctly (96.8%). The confusion matrix shows 19 approved records classified correctly, one approved record misclassified, and all 11 denied records classified correctly in that split.

What to keep in mind

This is not evidence of real-world lending performance. The dataset is tiny, one-hot encoding expands it to 147 features, and the split has no fixed random seed. The result can change substantially with a different split; fairness, calibration, and external validation were not assessed.

Next iteration: For a stronger study, I would use stratified cross-validation, prune or regularize the tree, compare simple baselines, and test error rates across relevant groups. This model should never be used to make actual credit decisions.

Selected figures

Bar chart comparing approved and denied loan records in the small dataset.
The sample contains more approved than denied outcomes.
Confusion matrix for the saved decision-tree test split.
The matrix makes the single misclassified test record visible.
Decision tree produced by the original notebook.
The original tree is included as a record of the model, not as a recommended decision policy.

Notebook and source data

The notebook preserves the analysis code with saved outputs removed and data paths normalized to a local data folder. Dataset files are not bundled; consult the notebook README and obtain appropriately licensed source data before running it.

Download notebook · Notebook README