Skip to content

SatyamKumarCS/Default-Credit-Card-Prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

48 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

title Credit Risk Analyzer
emoji πŸ’³
colorFrom blue
colorTo indigo
sdk streamlit
app_file app.py
pinned false

Credit Risk Analyzer & Agentic Underwriting Copilot

Explainable AI Lending System with Automated OCR Agent

An end-to-end machine learning system that predicts credit card default risk, provides explainable AI insights via SHAP, and features a built-in LangChain Agentic Copilot to automate document parsing via OCR.


Problem Statement

Consumer credit default costs financial institutions billions annually. Traditional manual underwriting misses complex patterns, and loan officers spend countless hours manually extracting data from messy bank statements.

This project solves both problems by building a complete credit risk pipeline. It includes an Automated Underwriting Copilot that uses an LLM to extract data from raw PDFs, runs it through the machine learning model, relies on SHAP explainability, and enforces a "Human-in-the-Loop" workflow for grey-zone risk predictions.


Demo

CreditRisk Enterprise Dashboard


Features

  • Agentic AI Copilot β€” LangChain-powered ReAct agent that automates document data extraction and context-aware financial Q&A (Powered by Groq Llama 3.3).
  • Automated Underwriting OCR β€” Intelligent PDF text parsing connected directly to the structured feature pipeline models.
  • Human-in-the-Loop Risk Profiling β€” Grey-zone escalation flow requiring manual review when AI confidence dips below safe thresholds.
  • Full ML Pipeline β€” data ingestion, feature engineering, preprocessing, model training, evaluation, and serving
  • Explainability β€” SHAP-based feature importance analysis for every prediction (why did the model decide this?)
  • Production UI β€” dark-themed fintech dashboard built with Streamlit, responsive and deployment-ready
  • Engineered Features β€” 8 derived financial indicators (credit utilization, payment ratio, delay severity, bill trends)
  • Data-Driven Insights β€” automated risk factor analysis explaining each prediction with color-coded reasoning
  • Deployment-Ready β€” environment variable configuration, absolute path resolution, single-command launch

Tech Stack

Layer Technology
Language Python 3.12
ML Framework scikit-learn
Explainability SHAP
Web UI Streamlit
Data Pandas, NumPy
Serialization Joblib
Dataset UCI Taiwan Credit Card Default (30,000 records)

System Design

flowchart TB
    subgraph DATA["Data Layer"]
        A[UCI Dataset β€” 30K records] --> B[Data Loader]
        B --> C[Preprocessing & Scaling]
    end

    subgraph ML["ML Pipeline"]
        C --> D[Feature Engineering]
        D --> E["Model Training<br/>(Logistic Regression)"]
        E --> F[Evaluation β€” ROC-AUC]
        E --> G[SHAP Explainability]
    end

    subgraph AGENT ["Agentic AI Copilot"]
        RAW[Raw Bank Statement PDF] -->|OCR+LLM| Agent[LangChain Agent]
    end

    subgraph SERVE["Serving Layer"]
        Agent -.->|Structured Features| I
        H[Streamlit Dashboard] --> I[User Input]
        I --> J[Feature Transform]
        J --> K[Model Inference]
        K --> L[Risk Score + Insights]
        L --> H
        L -.->|Report Gen| Agent
    end

    subgraph ARTIFACTS["Persisted Artifacts"]
        E --> M[best_model.pkl]
        C --> N[scaler.pkl]
        M --> K
        N --> J
    end
Loading

Project Structure

credit-risk-analyzer/
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ 01_eda.ipynb                          # Exploratory data analysis
β”‚   β”œβ”€β”€ 02_preprocession_feature_scaling.ipynb # Preprocessing & scaling
β”‚   β”œβ”€β”€ 03_model_training.ipynb               # Model training & evaluation
β”‚   └── 04_shap_explainability.ipynb          # SHAP feature importance
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data.py                               # Data loading utilities
β”‚   β”œβ”€β”€ features.py                           # Feature engineering (8 derived features)
β”‚   β”œβ”€β”€ preprocess.py                         # Preprocessing & scaling pipeline
β”‚   β”œβ”€β”€ train.py                              # Model training script
β”‚   └── predict.py                            # Inference utilities
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ best_model.pkl                        # Trained Logistic Regression model
β”‚   └── scaler.pkl                            # Fitted StandardScaler
β”œβ”€β”€ app.py                                    # Streamlit dashboard (single-file, self-contained)
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ credit_card_default_dataset.csv       # Raw UCI dataset
β”‚   └── processed_data.pkl                    # Preprocessed feature matrix
β”œβ”€β”€ screenshots/
β”‚   └── ui.png                                # Dashboard screenshot
β”œβ”€β”€ requirements.txt
└── README.md

Machine Learning Pipeline

Raw Data (30K records, 24 features)
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Feature Engineering        β”‚
β”‚  + AVG_BILL_AMT             β”‚
β”‚  + CREDIT_UTILITY           β”‚
β”‚  + AVG_PAY_DELAY            β”‚
β”‚  + PAYMENT_TO_BILL          β”‚
β”‚  + MAX_PAY_DELAY            β”‚
β”‚  + NUM_LATE_MONTHS          β”‚
β”‚  + PAYMENT_STD              β”‚
β”‚  + SEVERE_DELAY_FLAG        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
Preprocessing (One-Hot Encoding + Standard Scaling)
    β”‚
    β–Ό
Model Training (Logistic Regression β€” selected via cross-validation)
    β”‚
    β–Ό
Evaluation (ROC-AUC, Confusion Matrix, Classification Report)
    β”‚
    β–Ό
SHAP Explainability (Global + Local Feature Importance)
    β”‚
    β–Ό
Streamlit Dashboard (Real-Time Prediction + Data-Driven Insights)

Model Performance

Metric Score
ROC-AUC ~0.75
Algorithm Logistic Regression
Training Set 30,000 records (UCI Taiwan Credit)

Interpretation: A ROC-AUC of 0.75 indicates the model correctly ranks a random defaulter above a random non-defaulter 75% of the time. While not production-threshold for autonomous decisions, it provides strong directional guidance for human-in-the-loop lending workflows.


Installation & Setup

Prerequisites: Python 3.10+

# 1. Clone the repository
git clone https://github.com/SatyamKumarCS/credit-risk-analyzer.git
cd credit-risk-analyzer

# 2. Create virtual environment
python -m venv venv
source venv/bin/activate        # macOS/Linux
# venv\Scripts\activate         # Windows

# 3. Install dependencies
pip install -r requirements.txt

# 4. Environment Variables
cp .env.example .env
# Open .env and add your GROQ_API_KEY for the AI Copilot to work

Usage

Run the Dashboard & AI Copilot

The dashboard is now a multi-page app. The home page is the manual risk analyzer, and the sidebar contains the AI Underwriting Copilot.

streamlit run app.py

Opens at http://localhost:8501

Generate Sample Statement

If you want to test the AI Copilot without using a real bank statement, generate the dummy PDF by running:

python scripts/generate_sample_pdf.py

This will create a samples/sample_statement.pdf file you can upload to the Copilot.

Run the Notebooks

Execute in order for full pipeline reproduction:

jupyter notebook notebooks/
  1. 01_eda.ipynb β€” data exploration and visualization
  2. 02_preprocession_feature_scaling.ipynb β€” preprocessing pipeline
  3. 03_model_training.ipynb β€” model training and evaluation
  4. 04_shap_explainability.ipynb β€” SHAP analysis

Retrain the Model

python src/train.py

Future Improvements

  • Threshold Optimization β€” tune decision threshold using precision-recall tradeoff for business-specific cost matrices
  • Model Upgrades β€” experiment with XGBoost, LightGBM, and neural networks for improved AUC
  • Cloud Deployment β€” containerize with Docker, deploy to Streamlit Community Cloud / Render
  • Monitoring β€” add prediction drift detection and model performance tracking
  • Batch Processing β€” CSV upload for bulk risk assessment
  • API Layer β€” FastAPI endpoint for programmatic integration

Key Highlights

Designed for recruiters and reviewers scanning in 30 seconds.

  • Agentic Underwriting Copilot: Automates PDF extraction and decision orchestration via LangChain & Groq Llama 3.3.
  • Human-in-the-Loop: Safely flags "Grey Zone" applicants for mandatory manual overriding.
  • End-to-End ML System: Data ingestion β†’ Features β†’ Model β†’ Explainability β†’ UI.
  • SHAP-powered explainability: Not just raw predictions, but why they happened.
  • Production-grade: Streamlit dashboard with dark fintech aesthetics and environment management.

License

This project is open-source under the MIT License.


Author

Satyam Kumar

About

End-to-end credit risk analysis system with ML pipeline, SHAP explainability, and an AI-powered underwriting copilot for automated financial data extraction.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors