This project is a demonstration of a Financial Risk Assessment application that predicts risk tolerance based on user-provided financial data. It combines machine learning models (Logistic Regression and LightGBM), FastAPI for the backend, and Streamlit for the frontend to create an interactive web application.
The goal of this project is to showcase the integration of machine learning models into a web-based financial risk assessment tool. It includes:
- Data generation (mock data for demonstration purposes).
- Risk assessment models (Logistic Regression and LightGBM).
- A FastAPI backend for handling user requests.
- A Streamlit frontend for user interaction.
The project is organized as follows:
financial_demo/
│
├── data/
│ └── financial_data.csv
│
├── scripts/
│ ├── generate_data.py
│ ├── risk_assessment.py
│ └── ...
│
├── models/
│ ├── risk_assessment_model.joblib
│ ├── risk_assessment_model_xgb.joblib
│ └── ...
│
├── app.py
├── streamlit_app.py
├── requirements.txt
└── README.md
-
data/: Contains the mock financial dataset.
-
scripts/: Includes Python scripts for data generation and model training.
-
models/: Stores trained machine learning models.
-
app.py: The FastAPI backend for risk assessment.
-
streamlit_app.py: The Streamlit frontend for user interaction.
-
requirements.txt: Lists project dependencies.
To run the project locally, follow these steps:
-
Clone this repository to your local machine:
git clone https://github.com/fshnkarimi/Financial-Risk-Assessment-using-LightGBM.git cd Financial-Risk-Assessment-using-LightGBM
-
Set up a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install project dependencies:
pip install -r requirements.txt
-
Generate mock financial data:
python scripts/generate_data.py
-
Train the risk assessment model (Logistic Regression or LightGBM):
python scripts/risk_assessment.py
-
Start the FastAPI backend:
uvicorn app:app
-
In a separate terminal, run the Streamlit app:
streamlit run streamlit_app.py
-
Access the Streamlit app in your web browser (usually at http://localhost:8501).
-
Open the Streamlit app in your web browser.
-
Enter your financial data, including income and expenses.
-
Click the "Assess Risk" button to receive a risk assessment result.
- scikit-learn
- fastapi
- pydantic
- lightgbm
- streamlit
- joblib
- requests
For a complete list of dependencies, see requirements.txt.