| title | Credit Risk Analyzer |
|---|---|
| emoji | π³ |
| colorFrom | blue |
| colorTo | indigo |
| sdk | streamlit |
| app_file | app.py |
| pinned | false |
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.
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.
- 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
| 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) |
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
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
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)
| 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.
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 workThe 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.pyOpens at http://localhost:8501
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.pyThis will create a samples/sample_statement.pdf file you can upload to the Copilot.
Execute in order for full pipeline reproduction:
jupyter notebook notebooks/01_eda.ipynbβ data exploration and visualization02_preprocession_feature_scaling.ipynbβ preprocessing pipeline03_model_training.ipynbβ model training and evaluation04_shap_explainability.ipynbβ SHAP analysis
python src/train.py- 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
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.
This project is open-source under the MIT License.
Satyam Kumar
- GitHub: @SatyamKumarCS
- Project: Credit Risk Analyzer
