An AI-powered credit risk assessment system with explainable predictions using machine learning and SHAP values.
Your application is already running!
- Frontend: http://localhost:8082
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
Open http://localhost:8082 in your browser to start analyzing credit risk!
- Features
- Architecture
- Getting Started
- Usage
- API Documentation
- Model Information
- Testing
- Deployment
- Contributing
- β Machine Learning Model: Gradient Boosted Trees (LightGBM/XGBoost/CatBoost)
- β Explainable AI: SHAP values for feature importance
- β RESTful API: FastAPI with automatic documentation
- β Data Pipeline: Automated preprocessing and feature engineering
- β Model Evaluation: Comprehensive metrics and visualizations
- β Class Imbalance Handling: Proper handling of imbalanced datasets
- β CORS Support: Ready for frontend integration
- β Modern UI: React with TypeScript and Tailwind CSS
- β Real-time Validation: Form validation with immediate feedback
- β Risk Visualization: Clear display of risk levels and factors
- β Explainable Results: Human-readable explanations for predictions
- β Responsive Design: Works on desktop and mobile
- β Error Handling: Graceful error messages and loading states
βββββββββββββββββββ HTTP/REST βββββββββββββββββββ
β β βββββββββββββββββββ β β
β React Frontend β β FastAPI Backendβ
β (Port 8082) β β (Port 8000) β
β β β β
βββββββββββββββββββ ββββββββββ¬βββββββββ
β
β Loads
β
βββββββββββββββββββ
β ML Model + β
β SHAP Explainer β
β Artifacts β
βββββββββββββββββββ
Backend:
- Python 3.8+
- FastAPI (Web framework)
- LightGBM/XGBoost/CatBoost (ML models)
- SHAP (Explainability)
- Pandas, NumPy (Data processing)
- Scikit-learn (Preprocessing)
Frontend:
- React 18+
- TypeScript
- Tailwind CSS
- Vite (Build tool)
- Shadcn/ui (UI components)
- Python 3.8+
- Node.js 16+
- npm or yarn
- Clone the repository
cd /path/to/CreditScore- Install Backend Dependencies
cd backend
pip install -r requirements.txt- Install Frontend Dependencies
npm installpython train_model.pyThis will:
- Load and preprocess the training data
- Train multiple model variants (LightGBM, XGBoost, CatBoost)
- Evaluate and select the best model
- Save model artifacts to
backend/artifacts/ - Generate evaluation plots
Terminal 1 - Backend:
cd backend
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadTerminal 2 - Frontend:
npm run devAccess the application at http://localhost:8082
- Navigate to http://localhost:8082
- Fill in the credit assessment form with applicant details
- Click "Analyze Credit Risk"
- View the prediction results:
- Default probability (0-100%)
- Risk label (LOW/MEDIUM/HIGH)
- Top risk factors with explanations
Health Check:
curl http://localhost:8000/api/healthPredict Credit Risk:
curl -X POST http://localhost:8000/api/predict \
-H "Content-Type: application/json" \
-d '{
"age": 35,
"annual_income": 60000,
"debt_to_income_ratio": 0.45,
"revolving_utilization": 0.6,
"open_credit_lines": 5,
"delinquencies_2yrs": 2,
"dependents": 1,
"fico_score": 720,
"loan_amount": 25000,
"employment_length": 5
}'Get Model Schema:
curl http://localhost:8000/api/schemaInteractive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Returns the health status of the API and model loading status.
Response:
{
"status": "ok",
"model_loaded": true,
"version": "1.0.0"
}Predicts credit default probability for an applicant.
Request Body:
{
"age": 35,
"annual_income": 60000,
"debt_to_income_ratio": 0.45,
"revolving_utilization": 0.6,
"open_credit_lines": 5,
"delinquencies_2yrs": 2,
"dependents": 1,
"fico_score": 720,
"loan_amount": 25000,
"employment_length": 5
}Response:
{
"default_probability": 0.665,
"risk_label": "HIGH",
"top_factors": [
{
"feature": "loan_to_income_ratio",
"impact": 0.471,
"direction": "increases_risk",
"human_readable_reason": "Higher loan-to-income ratio increases default risk"
}
],
"model_version": "1.0"
}Returns model metadata and feature definitions.
- Source:
loan_processed_data.csv - Target: Binary classification (default vs. non-default)
- Features: 14 features including FICO score, income, DTI, utilization, etc.
Gradient Boosted Trees (best of LightGBM, XGBoost, CatBoost selected based on validation performance)
- FICO Score (300-850)
- Annual Income ($)
- Debt-to-Income Ratio (0-1)
- Revolving Utilization (0-1)
- Open Credit Lines (count)
- Delinquencies in Last 2 Years (count)
- Loan Amount ($)
- Employment Length (years)
- Age (years)
- Dependents (count)
- Monthly Income (derived)
- Loan-to-Income Ratio (derived)
- High Utilization Flag (derived)
- Term Length (months)
- LOW: < 33% default probability
- MEDIUM: 33% - 66% default probability
- HIGH: β₯ 66% default probability
Check backend/artifacts/model_evaluation_results.csv for detailed metrics including:
- ROC AUC
- Precision
- Recall
- F1 Score
- KS Statistic
See TESTING_RESULTS.md for comprehensive test results.
Example Test Cases:
Low Risk:
{
"age": 45, "annual_income": 85000, "debt_to_income_ratio": 0.25,
"revolving_utilization": 0.30, "open_credit_lines": 8,
"delinquencies_2yrs": 0, "dependents": 2, "fico_score": 780,
"loan_amount": 15000, "employment_length": 10
}Expected: ~23% default probability, LOW risk
High Risk:
{
"age": 28, "annual_income": 35000, "debt_to_income_ratio": 0.65,
"revolving_utilization": 0.95, "open_credit_lines": 3,
"delinquencies_2yrs": 4, "dependents": 0, "fico_score": 580,
"loan_amount": 30000, "employment_length": 1
}Expected: ~82% default probability, HIGH risk
Before deploying to production:
- Add authentication (JWT, OAuth)
- Set up database for prediction history
- Implement rate limiting
- Configure HTTPS/SSL
- Set up logging and monitoring
- Add input sanitization
- Configure environment variables
- Set up CI/CD pipeline
- Add automated tests
- Configure backup and recovery
Backend:
- AWS EC2 / Lambda
- Google Cloud Run
- Azure App Service
- Heroku
- DigitalOcean
Frontend:
- Vercel
- Netlify
- AWS S3 + CloudFront
- GitHub Pages
CreditScore/
βββ backend/ # Backend API
β βββ app/
β β βββ main.py # FastAPI application
β β βββ config.py # Configuration
β β βββ schemas.py # Pydantic models
β β βββ preprocessing.py # Data preprocessing
β β βββ inference.py # Model inference & SHAP
β β βββ utils.py # Utilities
β βββ training/
β β βββ data_loader.py # Data loading
β β βββ train_model.py # Model training
β β βββ evaluate_model.py # Model evaluation
β βββ artifacts/ # Model artifacts
β βββ requirements.txt # Python dependencies
β βββ README.md # Backend docs
βββ src/ # Frontend source
β βββ pages/
β β βββ Assessment.tsx # Main page
β βββ services/
β β βββ api.ts # API service
β βββ components/ # UI components
βββ data/ # Training data
βββ train_model.py # Training script
βββ start_backend.py # Backend launcher
βββ QUICKSTART.md # Quick start guide
βββ PROJECT_STATUS.md # Project status
βββ TESTING_RESULTS.md # Test results
βββ README.md # This file
Contributions are welcome! Areas for improvement:
- Authentication & Authorization: Add user management
- Database Integration: Store predictions and user data
- Model Monitoring: Track model performance over time
- Batch Processing: Support CSV uploads for bulk predictions
- Advanced Features: A/B testing, model versioning, etc.
- Mobile App: Native iOS/Android applications
- Advanced Visualizations: More detailed charts and graphs
This project is licensed under the MIT License.
For questions or issues:
- Check the documentation files (
QUICKSTART.md,PROJECT_STATUS.md,TESTING_RESULTS.md) - Review the API documentation at http://localhost:8000/docs
- Check the backend logs in the terminal
- Check the browser console for frontend errors
- Built with FastAPI, React, and modern ML tools
- SHAP library for explainable AI
- Gradient boosting libraries (LightGBM, XGBoost, CatBoost)
- Shadcn/ui for beautiful UI components
π Start using your Credit Risk Analyzer at http://localhost:8082
Last updated: October 27, 2025