AI-Powered Financial Insight Engine
End-to-End Loan Risk System
Author: Kishore Muruganantham
This project goes beyond building a loan risk model β it delivers a complete, intelligent system that predicts, explains, and simulates risk.
Your story: Not just a predictive model, but a business-ready engine that demonstrates technical, analytical, and creative skills.
- Converts raw model probability into actionable business tiers: Prime, Subprime, High-Risk
- Enables real-world lending strategies and decision automation
- Thresholds are configurable (e.g., Prime <20%, Subprime <50%, High-Risk β₯50%)
- Dedicated endpoint using SHAP to break the "black box"
- Reveals the "why" behind each decision: feature attributions, local/global importance, visual plots
- Shows mastery of responsible AI and regulatory compliance
- Accepts an application + modifications to simulate outcomes
- Demonstrates how changes (e.g., lower loan amount, higher income) affect risk tier and recommendations
- Turns your API into a collaborative financial advisor β the "wow" factor
financial_insight_engine/
βββ ml_service/
β βββ __init__.py
β βββ train_and_serve.py # ML, EDA, training, artifacts
β βββ requirements.txt
βββ fastapi_app/
β βββ __init__.py
β βββ main.py # All API endpoints
β βββ models.py
β βββ requirements.txt
βββ .env # NGROK URL goes here
βββ README.md # This full guide
ml_service/: All model training, EDA, and artifact generationfastapi_app/: The FastAPI backend, endpoints, and input validation.env: Paste your NGROK URL after training
Dataset:
Place 6S_AI_TASK-Loan_default_Loan_default.xlsx inside ml_service/.
- Create the exact project structure above.
- Copy code for each file into its location.
- Place your dataset in
ml_service/.
cd financial_insight_engine/ml_service
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
python train_and_serve.py- Script runs EDA, saves charts, trains model, prints NGROK URL.
- Copy the NGROK URL and leave this terminal running.
# Open a new terminal window
cd financial_insight_engine/fastapi_app
# Go to root, open .env, paste the NGROK URL
cd ..
nano .env
# Paste the NGROK URL
cd fastapi_app
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000- ML service running, served to the world via NGROK
- FastAPI API running locally
- Open http://127.0.0.1:8000/docs for interactive API documentation
curl -X 'POST' \
'http://127.0.0.1:8000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ "Age": 46, "Income": 84208, "LoanAmount": 129188, "CreditScore": 451, "MonthsEmployed": 26, "NumCreditLines": 3, "InterestRate": 21.17, "LoanTerm": 24, "DTIRatio": 0.31, "Education": "Master", "EmploymentType": "Unemployed", "MaritalStatus": "Divorced", "HasMortgage": "Yes", "HasDependents": "Yes", "LoanPurpose": "Auto", "HasCoSigner": "No" }'curl -X 'POST' \
'http://127.0.0.1:8000/explain' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ "Age": 46, "Income": 84208, "LoanAmount": 129188, "CreditScore": 451, "MonthsEmployed": 26, "NumCreditLines": 3, "InterestRate": 21.17, "LoanTerm": 24, "DTIRatio": 0.31, "Education": "Master", "EmploymentType": "Unemployed", "MaritalStatus": "Divorced", "HasMortgage": "Yes", "HasDependents": "Yes", "LoanPurpose": "Auto", "HasCoSigner": "No" }'curl -X 'POST' \
'http://127.0.0.1:8000/what-if' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ "original_application": { "Age": 46, "Income": 84208, "LoanAmount": 129188, "CreditScore": 451, "MonthsEmployed": 26, "NumCreditLines": 3, "InterestRate": 21.17, "LoanTerm": 24, "DTIRatio": 0.31, "Education": "Master", "EmploymentType": "Unemployed", "MaritalStatus": "Divorced", "HasMortgage": "Yes", "HasDependents": "Yes", "LoanPurpose": "Auto", "HasCoSigner": "No" }, "modifications": { "LoanAmount": 95000, "InterestRate": 15.5 } }'Required fields:
- Age (int)
- Income (float)
- LoanAmount (float)
- CreditScore (int)
- MonthsEmployed (int)
- NumCreditLines (int)
- InterestRate (float)
- LoanTerm (int)
- DTIRatio (float)
- Education (str)
- EmploymentType (str)
- MaritalStatus (str)
- HasMortgage (Yes/No)
- HasDependents (Yes/No)
- LoanPurpose (str)
- HasCoSigner (Yes/No)
Validation is enforced with Pydantic schemas for data integrity.
- Preprocessing: Imputation, encoding, scaling, outlier handling
- Feature Engineering: Derived features, ratios, buckets
- Modeling: Logistic Regression, Random Forest/XGBoost, cross-validation, tuning
- Evaluation: ROC-AUC, Precision-Recall, confusion matrix, business KPIs
- Artifacts: Model file, pipeline, SHAP explainer, charts/plots, evaluation report
- EDA charts (distributions, correlations) and model performance plots (ROC, PR, confusion matrix) in
ml_service/charts/ - SHAP global and local plots to explain predictions
- Short report in
ml_service/report.mdsummarizing insights and model performance
- Replace dataset in
ml_service/ - Activate venv, run
python train_and_serve.py - Artifacts and charts regenerate
- Restart FastAPI app to load new model
- Quality preprocessing & feature engineering
- Modeling rigor & evaluation depth
- API design, validation, error handling
- Clarity/insight in visualizations & explanation
- Modular code, repo hygiene, documentation
- Model File: serialized model artifact
- FastAPI Backend: endpoints, validation, error handling
- Data & Modeling Script: preprocessing, training, EDA, visualization
- Documentation & Visuals: this README, EDA charts, reports
- Open with the story: the 3 pillars, business impact
- Demo
/predictfor speed and usability - Use
/explainto showcase interpretability and responsible AI - Try
/what-iffor scenario simulation and actionable insights - Display charts, artifacts, and report for reproducibility
- Artifact loading errors? Check paths, venvs, file locations
- NGROK issues? Check account, tunnels, .env setup
- SHAP/large data: Use TreeExplainer for trees, limit sample size if needed
If you want to see more file details, please browse the repo directly on GitHub for the full file list.