A machine learning project that predicts the likelihood of loan default using borrower and loan information.
This project was developed as part of the CodeAlpha Machine Learning Internship.
The goal is to build a machine learning model that analyzes credit-related information and predicts whether a borrower is likely to default on a loan.
The project uses Logistic Regression and compares a standard model with a class-balanced version.
The project uses the Credit Risk Dataset, which contains information about borrowers and their loans.
The dataset includes features such as:
- Person age
- Person income
- Home ownership
- Employment length
- Loan intent
- Loan grade
- Loan amount
- Loan interest rate
- Loan percentage of income
- Previous default history
- Credit history length
The target variable is:
0— No default1— Default
- Python
- Pandas
- NumPy
- Scikit-learn
- Joblib
- Matplotlib
- Seaborn
The project follows these steps:
- Load the dataset
- Inspect the data
- Handle missing values
- Remove duplicate records
- Separate features and target
- Encode categorical variables
- Split the dataset into training and testing sets
- Scale numerical features
- Train Logistic Regression models
- Evaluate model performance
- Compare baseline and balanced models
- Save the trained model
- Use the saved model to make new predictions
The baseline model uses standard Logistic Regression without class weighting.
The second model uses:
class_weight="balanced"
This gives additional importance to the default class and helps the model identify more potential default cases.
| Metric | Baseline Model | Balanced Model |
|---|---|---|
| Accuracy | 86.91% | 81.46% |
| Precision | 77.33% | 55.48% |
| Recall | 56.77% | 77.08% |
| F1-Score | 65.47% | 64.52% |
| ROC-AUC | 86.79% | 86.96% |
The two models demonstrate a trade-off between precision, recall, and overall accuracy.
The balanced model detected more of the actual default cases, while the baseline model achieved higher accuracy and precision.
The project includes predict.py, which allows a user to enter borrower information and receive a predicted credit-risk result.
Example:
Probability of default: 31.15%
Prediction: LOWER DEFAULT RISK
The prediction is generated by the trained machine learning model.
CodeAlpha_CreditScoringModel/
│
├── data/
│ └── credit_risk_dataset.csv
│
├── model/
│ └── credit_scoring_model.pkl
│
├── main.py
├── predict.py
├── requirements.txt
└── README.md
https://github.com/obinnakelvin-dev/CodeAlpha_CreditScoringModel.gitcd CodeAlpha_CreditScoringModelpip install -r requirements.txtpython main.pypython predict.pyFollow the prompts to enter the borrower's information.
Possible improvements include:
- Testing additional machine learning algorithms
- Hyperparameter tuning
- Cross-validation
- Better handling of class imbalance
- Feature engineering
- More comprehensive model validation
- Building a web interface for predictions
- Deploying the model as a web application
Through this project, I practiced:
- Data preprocessing
- Exploratory data analysis
- Categorical encoding
- Train/test splitting
- Feature scaling
- Logistic Regression
- Model evaluation
- Classification metrics
- Model comparison
- Model serialization
- Building a simple prediction system
Amala-Okechi Obinna Kelvin
Computer Engineering Student Machine Learning & Python Learner