DSA LABData Science Applications
Experiment 07 ยท CO3

Approve or Reject?

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.

Course IT416
Outcome CO3
Model Decision Tree
Key Explainability

Why this model wins for banking

TRACEABLE
0
Decision rules
0
Explainable
0
Error types
0
Concept videos
01

Lab Manual

Problem
A bank needs to classify loan applicants as eligible or not eligible based on details such as income, credit score and repayment history. Study the dataset, select an appropriate classification algorithm, build the model, and justify why it is suitable for decision-making.
Aim
To build a classification model that decides loan eligibility, and to justify the choice of an interpretable algorithm (decision tree / logistic regression) for high-stakes, regulated decisions.
Objectives
  • Study the dataset and identify predictive features.
  • Select a suitable, explainable classification algorithm.
  • Train the model and read off the decision rules.
  • Evaluate it and weigh the two kinds of error (approving a defaulter vs rejecting a good applicant).
Software
Python 3.x ยท Jupyter / Colab ยท Pandas, scikit-learn, Matplotlib.
Dataset
A loan-application dataset (e.g. the Kaggle "Loan Prediction" or UCI "German Credit" data) โ€” income, credit history, loan amount, term, employment, with an eligibility label.
Outcome
CO3 โ€” building a classification model and justifying it for decision-making.
02

Why Pick a Decision Tree?

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.

โœ“ White-box: Decision Tree / Logistic Regression

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.

โœ— Black-box: deep nets, large ensembles

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.

The trade-off: we accept a little less raw accuracy in exchange for transparency, fairness and accountability. In regulated decision-making, an explainable model you can defend beats a black box you can't.
03

The Decision, Traced

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.

Loan eligibility decision treean applicant must clear every gate to be approved
Credit score700
Annual incomeโ‚น8.0L
Debt-to-income (DTI)30%
Loan amountโ‚น25.0L
โ€”
Decision trace โ€” the bank's justification
    Try it: drop the credit score below 650 and the very first gate rejects the applicant โ€” one clear, defensible reason. Raise debt-to-income above 45% and watch a strong applicant get stopped at the debt gate.
    03a

    Two Errors, Two Costs

    Confusion matrix for lending

    Predicted Approve
    Predicted Reject
    Truly good
    โœ“ good loan
    lost customer
    Truly risky
    โœ— defaults!
    โœ“ avoided

    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.

    So how do we judge it?

    Accuracy alone is not enough. Banks look at:

    • Precision on "approve" โ€” of approved loans, how many were truly safe.
    • Recall on "risky" โ€” how many actual defaulters we caught.
    • ROC-AUC โ€” performance across all decision thresholds.
    • Fairness โ€” similar decisions across protected groups.
    Decision-making: set the approval threshold by the cost of each error, not by accuracy. An explainable tree makes that policy visible and auditable.
    04

    Watch the Concepts

    Two clear explainers from StatQuest with Josh Starmer โ€” how a decision tree is built, and how we measure its mistakes.

    StatQuestDecision & Classification TreesHow a tree chooses questions and splits to classify โ€” the model used here.
    StatQuestThe Confusion MatrixWhere false approves and false rejects come from, and the metrics they feed.

    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.

    05

    The Program

    Train a decision tree, then read its rules โ€” that readability is exactly why we chose it. A logistic-regression comparison is included for justification.

    1 โ€” load_prepare.py
    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)
    2 โ€” decision_tree.py
    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()
    3 โ€” justify_choice.py
    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.
    06

    Procedure & Result

    Steps followed

    1 ยท Study data
    Inspect features, missing values, class balance.
    2 ยท Prepare
    Clean, encode categoricals, split train/test.
    3 ยท Select model
    Choose an interpretable classifier (decision tree).
    4 ยท Train
    Fit the tree; cap depth to avoid overfitting.
    5 ยท Read rules
    Export the tree and feature importances.
    6 ยท Evaluate & justify
    Accuracy, confusion matrix, cost of errors.

    Result

    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.

    Conclusion: For high-stakes decisions like loans, the best model is not always the most accurate one โ€” it's the one whose decisions you can explain, defend and audit. A shallow decision tree gives competitive accuracy plus a transparent rule for every applicant, which is exactly what responsible decision-making requires.
    07

    Viva Questions

    Why is a decision tree well suited to loan decisions?
    It produces simple, human-readable if-then rules, so every approval or rejection can be explained and audited. It also handles mixed feature types and needs little preprocessing โ€” important for transparent, regulated decisions.
    What are the root, internal nodes and leaves of a tree?
    The root is the first test (top of the tree); internal nodes are further tests on features; leaves are the final outputs โ€” here "Approve" or "Reject".
    How does a decision tree decide where to split?
    It picks the feature and threshold that most reduce impurity (Gini impurity or entropy/information gain), making the resulting groups as pure (single-class) as possible.
    How do you prevent a decision tree from overfitting?
    Limit depth (max_depth), require a minimum number of samples per split/leaf, prune the tree, or use cross-validation to choose these settings.
    Why might accuracy be the wrong metric for loan approval?
    Classes are usually imbalanced and the two errors have very different costs. Approving a defaulter (false approve) is far costlier than rejecting a good applicant, so precision, recall and cost-sensitive metrics matter more.
    White-box vs black-box models โ€” what's the difference and why does it matter here?
    White-box models (trees, logistic regression) expose their reasoning; black-box models (deep nets, large ensembles) don't. Lending often legally requires an explanation for rejections, so explainability can outweigh a small accuracy gain.
    What is feature importance and how is it useful?
    It measures how much each feature contributes to the model's decisions. It helps justify and communicate which factors (e.g. credit score, DTI) drive eligibility, and can flag unfair or irrelevant features.
    How would you check the model is fair?
    Compare error rates and approval rates across protected groups, remove or audit sensitive proxies, and use fairness metrics. The tree's transparency makes such audits straightforward.