This project was developed as a foundational phase of the AIML Summer Internship, focusing on building a robust machine learning pipeline to predict whether a loan application will be approved or rejected based on historical applicant data.
The Loan Decision Support Platform is an interactive web application that provides a complete, end-to-end machine learning workflow. Built using Python, Scikit-Learn, and Streamlit, the platform allows users to explore the underlying dataset, evaluate the performance of various predictive models, and perform real-time loan approval inference through a user-friendly interface.
- Build a clean and robust Machine Learning application.
- Implement comprehensive data analysis and preprocessing techniques.
- Address dataset class imbalance to ensure fair and accurate predictions.
- Train, evaluate, and compare multiple machine learning algorithms to select the best performing model.
- Deploy the final model through an intuitive web dashboard.
- Exploratory Data Analysis (EDA)
- Data Preprocessing
- Data Balancing using SMOTE
- Logistic Regression
- Random Forest
- XGBoost
- Model Comparison
- Loan Approval Prediction
- Streamlit Deployment
The model is trained on a banking dataset containing key financial and demographic attributes used to evaluate loan applications:
- Applicant & Co-applicant Income: Primary and secondary income sources.
- Loan Amount & Term: The principal requested and the duration of the loan.
- Credit History: A binary indicator of past credit health (1.0 = Good, 0.0 = Poor).
- Demographics: Gender, Marital Status, Dependents, Education, and Property Area.
- Frontend: Streamlit, Plotly
- Machine Learning: Scikit-Learn, XGBoost, Imbalanced-Learn (SMOTE)
- Data Engineering: Pandas, NumPy
- Model Serialization: Joblib
LoanApprovalPrediction/
├── app.py # Main Streamlit application entry point
├── config/ # Configuration and path settings
├── data/ # Training dataset (train.csv)
├── models/ # Saved models and evaluation metrics
├── pages/ # Streamlit dashboard pages (EDA, Prediction, Evaluation)
├── training/
│ └── train_models.py # Automated pipeline for training models
└── utils/ # Helper modules (Predictor, UI components)
To ensure high model accuracy, the data undergoes strict preprocessing:
- Derived Features: Calculation of
TotalIncomeandIncome_Loan_Ratio. - Missing Values Handling: Numeric features are imputed using the median, while categorical features use the most frequent value.
- Encoding & Scaling: Categorical variables are One-Hot Encoded, and numeric features are scaled using
StandardScaler.
Historical loan datasets are often heavily skewed towards approvals. To prevent the model from becoming biased against minority classes (rejections), we apply SMOTE (Synthetic Minority Over-sampling Technique). This generates synthetic examples of the minority class, ensuring the models train on a perfectly balanced dataset.
The training script (training/train_models.py) automates the entire learning process:
- Splits the data into 80% training and 20% testing sets.
- Applies the preprocessing pipeline and SMOTE.
- Trains three distinct classifiers:
- Logistic Regression (Baseline)
- Random Forest (Ensemble Bagging)
- XGBoost (Ensemble Boosting)
- Saves all serialized models to the
models/directory. - Automatically selects the best performing model based on the F1 Score and promotes it to
best_model.pklfor active use in the web application.
Every trained model is evaluated against the unseen 20% test set. The application tracks and displays the following metrics:
- Accuracy: The overall percentage of correct predictions.
- Precision: The proportion of predicted approvals that were actually correct.
- Recall: The ability of the model to find all actual approvals.
- F1 Score: The harmonic mean of Precision and Recall, used as the primary metric for model selection.
- ROC-AUC: Evaluates the model's ability to distinguish between classes at various threshold settings.
- Confusion Matrix: A visual breakdown of True Positives, True Negatives, False Positives, and False Negatives.
Before starting, ensure you have the following prerequisites:
- Python Version: Python 3.10, 3.11, or 3.12 is required.
- Dataset: Ensure
data/train.csvis present in the repository. - Model Files: Inference requires
models/best_model.pklandmodels/evaluation_metrics.json. If missing, you must run the training pipeline first. - Virtual Environment: All execution scripts automatically create and utilize a Python virtual environment (
venv) to prevent global dependency conflicts.
We provide automated scripts that handle virtual environment creation, pip upgrades, dependency installation, and application launching in a single command.
For Windows (CMD/PowerShell):
run_project.batFor Linux (Ubuntu/Arch):
chmod +x run_project.sh
./run_project.shAlternatively, you can use the pure Python automated setup utilities:
# Step 1: Configure the environment and install dependencies
python setup_project.py
# Step 2: Validate the environment and launch Streamlit
python launch.pyIf you need to retrain the models, update features, or if the models/ directory is empty, run the training pipeline manually. Ensure your virtual environment is activated first:
# On Linux/macOS
source venv/bin/activate
# On Windows
venv\Scripts\activate
# Run the training script
python training/train_models.pyThis will evaluate Logistic Regression, Random Forest, and XGBoost, saving the best performing model to models/best_model.pkl.
- Diagnostic Tool: If you experience any issues, run
python check_environment.pyto get a detailed PASS/FAIL diagnostic report of your Python version, dataset existence, and dependency health. - Missing Module Error (
ModuleNotFoundError): Ensure you are running the application using the automated scripts, or that your virtual environment (venv) is activated. - Missing Dataset Error: Verify that
train.csvexists inside thedata/directory. - Model Loading Error: If the dashboard fails to load model metrics, ensure
models/best_model.pklandmodels/evaluation_metrics.jsonexist. Run the training script if they are absent.