A bank classifies loan applicants as eligible or not from income, credit score and repayment history. We choose an interpretable model โ a decision tree โ and, crucially, can explain every decision. Move the sliders and trace the path an applicant takes.
For loans, the model isn't just predicting โ it must justify. A rejected customer is legally owed a reason. So we prefer a transparent ("white-box") model whose logic anyone can follow.
Every decision is a short chain of human-readable rules ("credit < 650 โ reject"). Easy to explain to customers and regulators, audit for fairness, and turn into a policy. Handles mixed numeric/categorical features with little preprocessing.
Often slightly more accurate, but their reasoning is opaque. Hard to justify a single rejection, hard to audit, and risky where "adverse action" explanations are legally required. Usually not worth the loss of trust for lending.
Describe an applicant with the sliders. The tree lights up the exact path taken and lands on a leaf โ Approve or Reject โ and the trace below spells out the reason, rule by rule. This is the explainability a bank needs.
A false approve (approving someone who defaults) usually costs far more than a false reject (turning away a good customer). So a bank may tune the model toward fewer false approves.
Accuracy alone is not enough. Banks look at:
Two clear explainers from StatQuest with Josh Starmer โ how a decision tree is built, and how we measure its mistakes.
Videos are embedded from YouTube and belong to their creators. If a frame is blank, your network may block YouTube โ search the titles on youtube.com.
Train a decision tree, then read its rules โ that readability is exactly why we chose it. A logistic-regression comparison is included for justification.
import pandas as pd
from sklearn.model_selection import train_test_split
df = pd.read_csv("loan.csv")
df = df.dropna() # handle missing values
df = pd.get_dummies(df, drop_first=True) # encode categoricals
X = df.drop(columns=["Loan_Approved"])
y = df["Loan_Approved"]
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.25, random_state=1)
from sklearn.tree import DecisionTreeClassifier, plot_tree, export_text
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
import matplotlib.pyplot as plt
tree = DecisionTreeClassifier(max_depth=4, random_state=1)
tree.fit(X_tr, y_tr)
pred = tree.predict(X_te)
print("Accuracy:", accuracy_score(y_te, pred))
print(confusion_matrix(y_te, pred))
print(classification_report(y_te, pred))
# The whole point: read the rules the bank will follow
print(export_text(tree, feature_names=list(X.columns)))
plot_tree(tree, feature_names=X.columns, class_names=["Reject","Approve"], filled=True)
plt.show()
from sklearn.linear_model import LogisticRegression
# Compare with another interpretable model
lr = LogisticRegression(max_iter=1000).fit(X_tr, y_tr)
print("LogReg acc:", lr.score(X_te, y_te))
# Which features drive the decision? (justification)
import pandas as pd
imp = pd.Series(tree.feature_importances_, index=X.columns)
print(imp.sort_values(ascending=False).head())
# Pick the decision tree: comparable accuracy, fully explainable rules.
A decision-tree classifier was built to predict loan eligibility from applicant details. It achieved good accuracy while producing a small set of human-readable rules, and was compared with logistic regression. The tree was recommended because it is fully explainable โ essential for fair, auditable lending decisions, demonstrating CO3.