Work / Explainable AI for Credit Scoring
Machine LearningMaking Credit Decisions More Transparent Through Explainable AI
A loan-approval classifier that is accurate and able to explain itself: three tree-based models compared on 100,000 credit records, then opened up with SHAP, LIME, DiCE and Anchor.
Screenshot comingimages/explainable-ai.png01Overview
Lenders increasingly use machine learning to decide who gets credit. The most accurate models, such as ensembles of hundreds of trees, are also the hardest to explain. That matters to applicants, who deserve to know why they were declined. It matters to regulators, who expect decisions to be fair and accountable. It also matters to the lenders themselves, who need to trust what the model has learned.
This project asked whether a credit-scoring model can keep its accuracy while still giving clear, human-readable reasons for each decision.
02Research question
How can explainable AI (XAI) techniques improve the interpretability of credit-scoring models without giving up predictive performance?
03Dataset
The public Credit Score Classification dataset (Kaggle) has 100,000 monthly records with 28 attributes. These include income, number of accounts and cards, interest rate, delayed payments, credit mix, outstanding debt, credit-utilisation ratio and payment behaviour. The target is a three-class credit score: Good, Standard or Poor.
- Cleaning: removed impossible ages and corrupted values, then parsed text fields such as “22 Years and 7 Months” into numbers. 62,224 usable rows remained.
- Encoding: label-encoded Credit Mix (an ordinal field) and one-hot encoded Payment of Min Amount and Payment Behaviour, giving 26 features.
- Balancing: classes were skewed (Standard 33,184 · Poor 18,061 · Good 10,979), so I oversampled them to equal sizes.
- Outliers and scaling: removed outliers with the IQR rule and standardised the features. The final set has 67,654 rows, split 70/30 into train and test.
04Models
I trained three tree-based classifiers and then tuned each one with RandomizedSearchCV (5-fold cross-validation). Test accuracy on 20,297 held-out records:
| Model | Baseline | Tuned |
|---|---|---|
| Random Forest | 0.89 | 0.89 |
| Decision Tree | 0.86 | 0.77 |
| XGBoost | 0.83 | 0.83 |
Random Forest led on every metric, with precision, recall and F1 all around 0.89. Tuning didn't help, and for the Decision Tree it hurt. The random search favoured larger leaves, which over-regularised the tree.


05Explainability
I applied four complementary techniques to the Random Forest. Each answers a different question someone might ask about a credit decision.
- SHAP: which features matter most overall, and in which direction? Shown through summary, dependence, force and decision plots.
- LIME (using AIX360's tabular explainer): why did the model score this applicant the way it did?
- DiCE: what would need to change for this applicant to get a different outcome? It generated five diverse counterfactuals per applicant.
- Anchor: what simple if-then rule locks in this prediction? One example: Outstanding_Debt ≤ 529.63 AND Payment_of_Min_Amount = Yes AND Credit_Mix > 2 AND Credit_History_Age ≤ 169, with 0.96 precision.




06Evaluation
I judged predictive performance with accuracy, precision, recall and F1 per class. I judged the explanations on whether different methods told a consistent story, and on whether a non-specialist could act on them.
The Random Forest found Good and Poor applicants reliably, with recall of 0.97 and 0.94. Standard was the hardest class (recall 0.77), because it sits between the other two and borrows patterns from both.
07Findings
- SHAP and LIME agreed on the main drivers: credit mix, interest rate, paying only the minimum amount, days past due and outstanding debt. Those are factors a credit officer would recognise, which builds trust in the model.
- Demographic-style features such as age and income ranked low for global importance. That is a useful signal for fairness reviews.
- The methods complement one another. SHAP gives the global picture, LIME and Anchor explain individual decisions in plain terms, and DiCE turns a decline into actionable next steps.
- Accuracy and transparency did not trade off here. The most accurate model was also fully explainable after the fact.
08Reflection
The Random Forest scored 1.00 on its training data, a clear sign of overfitting. Oversampling before the train/test split could also let near-duplicate records leak into the test set. Since the dissertation, I have refactored the notebook into modular, tested scripts: separate preprocessing, training and metrics modules, with pytest coverage. On that stricter pipeline the scores drop to a more conservative 0.77 (Random Forest), 0.74 (XGBoost) and 0.68 (Decision Tree).
Next steps: balance classes inside each training fold only, add fairness metrics across groups, calibrate probabilities, and limit DiCE counterfactuals to features an applicant can realistically change.
09Selected code
Explaining the Random Forest with SHAP and generating counterfactuals with DiCE:
shap_explainer = shap.TreeExplainer(rdf_model)
shap_values = shap_explainer.shap_values(X_test) # (20297, 26, 3)
shap.summary_plot(shap_values[:, :, 0], X_test) # class: Good
exp_genetic_rf = dice_ml.Dice(data_dice, model_dice, method="genetic")
cfs = exp_genetic_rf.generate_counterfactuals(
X_test[2:3], total_CFs=5, desired_class=2)
cfs.visualize_as_dataframe()
Next project
NaijaShield: Fraud Detection →
Screenshot comingimages/fraud-detection.png