This project automates the prediction of loan defaults based on applicant details, financial history, and loan attributes using machine learning models. The system includes feature importance analysis, model training, and a user-friendly Flask API and Streamlit web application for real-time predictions. A chatbot has also been integrated for seamless interaction.
- Introduction
- Features
- Technologies Used
- Dataset
- Model and Approach
- Web Application
- Flask API
- Chatbot Integration
- Installation
- Usage
- Results
- Future Enhancements
- Learning Resources
- License
Loan default prediction is a critical task for financial institutions to reduce risks. This project automates the prediction of whether a loan will default based on various applicant details, loan features, and credit history, providing quick and accurate predictions to assist lenders in their decision-making process.
- Predictive Modeling: Uses a Light Gradient Boosting model to predict loan default risk.
- Real-Time Predictions: Available through both a Flask API and a Streamlit web app.
- Feature Importance Analysis: Highlights the key factors influencing loan default prediction.
- Robust Input Handling: Efficient handling of missing or invalid inputs.
- Chatbot Integration: A chatbot interface allows users to easily interact with the system for loan default predictions in a conversational manner.
- Programming Language: Python
- Libraries:
- Machine Learning:
scikit-learn
,numpy
,pandas
,lightgbm
- Visualization:
matplotlib
,seaborn
- Web Application:
streamlit
,flask
- Chatbot:
streamlit-chatbot
,GROQ
,gemma2-9b-it
- Machine Learning:
- Deployment: Docker, Gunicorn, Nginx
- Source: Dataset Source
- Attributes:
- Demographic:
person_age
,person_income
,person_home_ownership
,person_emp_length
- Loan Details:
loan_amnt
,loan_int_rate
,loan_intent
,loan_grade
- Credit History:
cb_person_cred_hist_length
,cb_person_default_on_file
- Demographic:
- Categorical features are one-hot encoded, and missing values are imputed during preprocessing.
-
Data Preprocessing:
- Handled missing values and one-hot encoded categorical variables.
- Scaled numerical features for compatibility with machine learning models.
-
Model:
- The model was trained using multiple classification algorithms such as Logistic Regression, Random Forest, AdaBoost, and LightGBM.
- Final Model: Light Gradient Boosting (LightGBM) was selected for its efficiency and high accuracy.
-
Evaluation:
- Metrics: Accuracy, Precision, Recall, F1-Score.
- LightGBM achieved an accuracy of approximately 93% and an F1-score of around 82%.
-
Deployment:
- The model is deployed with a Flask API and a Streamlit app for real-time interaction.
The Streamlit web application allows users to input loan details and receive a loan default prediction.
- Simple form-based interface to input loan details.
- Instant loan default predictions with easy-to-understand explanations.
AI Predictive Models for Loan Default Prediction - Streamlit App
The Flask API serves as an interface to interact with the trained loan default prediction model, enabling integration with other systems.
- POST endpoint to submit loan details and receive a default prediction.
- Handles JSON input and output, ensuring easy integration.
- Robust error handling for invalid input.
curl -X POST -H "Content-Type: application/json" -d '{
"person_age": 30,
"person_income": 50000,
"person_home_ownership": "MORTGAGE",
"person_emp_length": 10.0,
"loan_intent": "PERSONAL",
"loan_grade": "A",
"loan_amnt": 20000,
"loan_int_rate": 6.5,
"cb_person_default_on_file": "N",
"cb_person_cred_hist_length": 5
}' http://localhost:5000/predict
{
"prediction": "No Default"
}
A conversational AI chatbot has been integrated into the system to provide a more interactive and user-friendly experience. The chatbot guides users through the process of entering their loan details and provides predictions in real time.
- Interactive: Users can chat with the system to enter loan details in a conversational manner.
- Prediction: The chatbot uses the trained machine learning model to predict whether the loan will default.
- User-Friendly: The chatbot interface simplifies the process of loan default prediction for end-users.
- The chatbot is available in the Streamlit App, where users can interact with the model in a chat-based format to predict loan defaults.
-
Clone the Repository:
git clone https://github.com/JatinSharma496/AI_Predictive_Models_for_Loan_Default_Prediction.git cd AI_Predictive_Models_for_Loan_Default_Prediction
-
Set Up Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Flask API:
python app.py
-
Run the Streamlit App:
streamlit run app.py
- Flask API: Send POST requests to
http://localhost:5000/predict
with loan details in JSON format or use Postman. - Streamlit App: Navigate to
http://localhost:8501
to input loan details and receive a prediction. - Chatbot: Use the chatbot feature within the Streamlit app to interact with the loan default prediction model.
The model has been trained and evaluated, achieving high accuracy and providing valuable insights on loan default risk. Key features such as person_income
and loan_amnt
have a significant impact on predictions.
- Incorporate additional data sources to further improve prediction accuracy.
- Add user authentication for a personalized experience.
- Extend chatbot capabilities for deeper conversational insights.
- This project is licensed under the MIT License - see the LICENSE file for details.
Thank you for reading! If you like my project, feel free to give a ⭐ on GitHub!