βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LOAN APPROVAL SYSTEM β
βββββββββββββββββββ¬ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ€
β Frontend β Backend API β ML Pipeline β
β (React/Vite) β (FastAPI) β (scikit-learn/XGB) β
β β β β
β loan-ui/ β api/ β src/ β
β ββ App.jsx β ββ main.py β ββ data/ β
β ββ Predict.jsx β ββ routes.py β ββ features/ β
β ββ predict.js β ββ schema.py β ββ models/ β
β β β ββ pipelines/ β
β Port: 5173 β Port: 8000 β ββ utils/ β
βββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ
ββββββββββββββββ HTTP POST /predict ββββββββββββββββββββ
β β βββββββββββββββββββββββββββΊ β β
β React UI β JSON Request β FastAPI Server β
β (Vite Dev) β β (Uvicorn) β
β β βββββββββββββββββββββββββββ β β
ββββββββββββββββ JSON Response ββββββββββ¬ββββββββββ
{approval, probability, β
risk_level, explanations, β
insights} β
β calls
βΌ
ββββββββββββββββββββ
β Prediction β
β Engine β
β β
β ββββββββββββββ β
β β best_model β β
β β .pkl β β
β ββββββββββββββ β
β ββββββββββββββ β
β β SHAP β β
β β Explainer β β
β ββββββββββββββ β
ββββββββββββββββββββ
| Item | Detail |
|---|---|
| Framework | React 19 + Vite 8 |
| UI Library | Material UI (MUI) v7 |
| HTTP Client | Axios |
| Theme | Custom dark/gold "Premium Loan Analytics" theme |
| Dev Server | http://localhost:5173 |
File Structure:
loan-ui/
βββ src/
β βββ App.jsx # Main app β form inputs, result display, MUI theme
β βββ components/
β β βββ Predict.jsx # Predict button with loading/error states
β βββ api/
β β βββ predict.js # Axios POST to backend /predict endpoint
β βββ main.jsx # React entry point
β βββ App.css
β βββ index.css
βββ index.html
βββ vite.config.js
βββ package.json
βββ tailwind.config.js
Data Flow:
- User fills in the loan application form (11 fields)
- Clicks "Generate Analysis"
predict.jssends a POST request tohttp://127.0.0.1:8000/predict- Response is rendered: approval status, confidence, SHAP-based feature impacts, and insights
| Item | Detail |
|---|---|
| Framework | FastAPI |
| Server | Uvicorn |
| Middleware | CORS (allow all origins for dev) |
| Validation | Pydantic BaseModel |
File Structure:
api/
βββ main.py # FastAPI app creation, CORS middleware, router include
βββ routes.py # POST /predict endpoint β calls prediction engine
βββ schema.py # LoanRequest Pydantic model (11 input fields)
Endpoints:
| Method | Path | Description |
|---|---|---|
GET |
/ |
Health check β returns {"message": "Loan Approval API running"} |
POST |
/predict |
Accepts LoanRequest, returns prediction result |
Request Schema (LoanRequest):
{
"no_of_dependents": int,
"education": str, # "Graduate" | "Not Graduate"
"self_employed": str, # "Yes" | "No"
"income_annum": float,
"loan_amount": float,
"loan_term": float,
"cibil_score": float,
"residential_assets_value": float,
"commercial_assets_value": float,
"luxury_assets_value": float,
"bank_asset_value": float
}Response Schema:
{
"status": "success",
"prediction": {
"approval": "Approved | Rejected",
"probability": 0.0 - 1.0,
"risk_level": "Low Risk | Medium Risk | High Risk",
"explanations": { "feature_name": shap_value, ... },
"insights": ["feature X increased chances of approval", ...]
}
}src/
βββ data/
β βββ load_data.py # Loads CSV data via pandas
β βββ preprocess.py # Cleans columns, maps target, fixes negatives
βββ features/
β βββ feature_engineering.py # (placeholder)
βββ models/
β βββ train.py # Entry point β runs training pipeline
β βββ predict.py # Loads model, runs prediction + SHAP explanation
β βββ evaluate.py # (placeholder)
βββ pipelines/
β βββ training_pipeline.py # Full training pipeline: load β preprocess β train β save
βββ utils/
βββ helpers.py # (placeholder)
Raw CSV Data
β
βΌ
βββββββββββββββββββ
β Load & Clean β Read CSV, strip columns, map target (Approvedβ1, Rejectedβ0)
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Feature Split β X = all features (drop loan_id, loan_status)
β β y = loan_status
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Preprocessor β ColumnTransformer:
β β β’ Numerical β StandardScaler
β β β’ Categorical (education, self_employed) β OneHotEncoder
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Train/Test β 80/20 split, stratified by target
β Split β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Model Training β 4 models trained in sklearn Pipeline:
β β β’ Logistic Regression
β β β’ Decision Tree (max_depth=5)
β β β’ Random Forest (150 trees, max_depth=6)
β β β’ XGBoost (300 trees, lr=0.05, regularized)
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Evaluation β F1 Score comparison β best model selected
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Save Model β joblib.dump β models/best_model.pkl
βββββββββββββββββββ
Input Dict (11 features)
β
βΌ
ββββββββββββββββββββ
β Load Model β joblib.load(best_model.pkl)
β + SHAP Explainerβ shap.TreeExplainer on model step
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Predict β model.predict() β Approved/Rejected
β β model.predict_proba() β confidence score
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β SHAP Explain β Compute SHAP values on preprocessed input
β β Normalize β top 8 features by impact
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Risk Assessment β probability > 0.7 β Low Risk
β + Insights β probability > 0.4 β Medium Risk
β β else β High Risk
ββββββββββββββββββββ
data/
βββ raw/
β βββ loan_data.csv # Original dataset
βββ processed/
βββ clean_data.csv # Cleaned dataset (post-preprocessing)
loan_approval_dataset.csv # Root-level copy of dataset
Features (11 input columns):
| Feature | Type | Description |
|---|---|---|
no_of_dependents |
int | Number of dependents |
education |
categorical | Graduate / Not Graduate |
self_employed |
categorical | Yes / No |
income_annum |
float | Annual income |
loan_amount |
float | Requested loan amount |
loan_term |
float | Loan term in months |
cibil_score |
float | Credit score |
residential_assets_value |
float | Residential asset value |
commercial_assets_value |
float | Commercial asset value |
luxury_assets_value |
float | Luxury asset value |
bank_asset_value |
float | Bank/liquid asset value |
Target: loan_status β Approved (1) / Rejected (0)
# config/config.yaml
model:
test_size: 0.2
random_state: 42
training:
models:
- logistic_regression
- decision_tree
- random_forest
- xgboostmodels/
βββ best_model.pkl # Serialized sklearn Pipeline (preprocessor + best model)
βββ metrics.json # (placeholder for evaluation metrics)
| Layer | Technology |
|---|---|
| Frontend | React 19, Vite 8, MUI 7, Axios |
| Backend | FastAPI, Uvicorn, Pydantic |
| ML Models | scikit-learn, XGBoost |
| Explainability | SHAP (TreeExplainer) |
| Data Processing | pandas, NumPy |
| Serialization | joblib |
| Config | YAML |
| Notebooks | Jupyter (EDA) |
# 1. Install Python dependencies
pip install -r requirements.txt
# 2. Train the model (if needed)
python -m src.models.train
# 3. Start the API server
uvicorn api.main:app --host 0.0.0.0 --port 8000
# 4. Start the frontend (in a separate terminal)
cd loan-ui
npm install
npm run devOr use the startup script for the API:
PORT=8000 bash start.shUser fills form in React UI
β
βΌ
POST http://127.0.0.1:8000/predict
Body: { no_of_dependents, education, ... }
β
βΌ
FastAPI validates request via Pydantic (LoanRequest)
β
βΌ
routes.py β calls predict(request.dict())
β
βΌ
predict.py:
1. Converts dict β DataFrame
2. model.predict() β approval decision
3. model.predict_proba() β confidence
4. Preprocessor transforms input
5. SHAP TreeExplainer β feature importance
6. Normalizes & ranks top 8 features
7. Generates human-readable insights
8. Computes risk level
β
βΌ
JSON response returned to React UI
β
βΌ
UI renders: Verdict, Confidence %, Feature Impact Bars, Strategic Insights
loan-approval-system/
βββ api/ # FastAPI backend
β βββ main.py
β βββ routes.py
β βββ schema.py
βββ config/
β βββ config.yaml # Model/training config
βββ data/
β βββ raw/
β β βββ loan_data.csv
β βββ processed/
β βββ clean_data.csv
βββ loan-ui/ # React frontend
β βββ src/
β β βββ api/predict.js
β β βββ components/Predict.jsx
β β βββ App.jsx
β β βββ main.jsx
β βββ package.json
β βββ vite.config.js
βββ models/
β βββ best_model.pkl # Trained model artifact
β βββ metrics.json
βββ notebooks/
β βββ eda.ipynb # Exploratory Data Analysis
βββ src/ # ML source code
β βββ data/
β β βββ load_data.py
β β βββ preprocess.py
β βββ features/
β β βββ feature_engineering.py
β βββ models/
β β βββ train.py
β β βββ predict.py
β β βββ evaluate.py
β βββ pipelines/
β β βββ training_pipeline.py
β βββ utils/
β βββ helpers.py
βββ requirements.txt
βββ start.sh
βββ README.md