- Introduction
- Project Overview
- Technologies Used
- Exploratory Data Analysis (EDA)
- Preprocessing
- Classification Models
- Model Evaluation
- Results
- Conclusion
- Project Structure
- License
- Contact
This project predicts loan eligibility based on several applicant features, using machine learning classification algorithms. It aims to assist financial institutions in making efficient and accurate decisions regarding loan approvals.
The project follows these main steps:
- Exploratory Data Analysis (EDA): Understanding data patterns, distributions, and correlations.
- Preprocessing:
- Feature Selection and Extraction: Converting categorical variables, applying One Hot Encoding, and normalizing the data.
- Classification: Applying multiple machine learning algorithms to classify applicants.
- Model Evaluation: Using metrics such as F1 score, Jaccard index, and Log Loss to evaluate model performance.
- Programming Language: Python
- Libraries:
- Data Analysis: Pandas, NumPy
- Visualization: Matplotlib, Seaborn
- Machine Learning: Scikit-Learn
- Metrics: Scikit-Learn metrics (F1 score, Jaccard, Log Loss)
The EDA step involved understanding data distribution, checking for missing values, and identifying patterns and correlations in the features. Key insights from EDA helped guide the preprocessing and feature engineering steps.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Load data
data = pd.read_csv('loan_data.csv')
# Check for missing values
missing_values = data.isnull().sum()
# Distribution of target variable
sns.countplot(x='Loan_Status', data=data)
plt.title("Loan Status Distribution")
plt.show()This step involves preparing the data by converting categorical features to numerical values, selecting important features, and applying One Hot Encoding.
- Categorical to Numerical Conversion: Converting text features (e.g., gender, education) to numerical values.
- One Hot Encoding: Used to convert categorical variables into binary columns.
- Normalization: Scaling the data to improve model performance.
from sklearn.preprocessing import OneHotEncoder, StandardScaler
# One Hot Encoding categorical variables
data = pd.get_dummies(data, columns=['Gender', 'Education'], drop_first=True)
# Normalize numeric features
scaler = StandardScaler()
data[['ApplicantIncome', 'LoanAmount']] = scaler.fit_transform(data[['ApplicantIncome', 'LoanAmount']])Several machine learning algorithms were used to predict loan eligibility:
- K-Nearest Neighbors (KNN): A simple yet effective algorithm for binary classification.
- Decision Tree: A tree-based model that captures non-linear relationships.
- Support Vector Machine (SVM): A model that maximizes the margin between classes.
- Logistic Regression: A linear model useful for binary classification problems
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Model initialization
knn = KNeighborsClassifier()
dt = DecisionTreeClassifier()
svm = SVC()
lr = LogisticRegression()
# Training each model
knn.fit(X_train, y_train)
dt.fit(X_train, y_train)
svm.fit(X_train, y_train)
lr.fit(X_train, y_train)The models were evaluated using the following metrics:
- F1 Score: Balances precision and recall.
- Jaccard Index: Measures the similarity between predicted and actual results.
- Log Loss: Penalizes incorrect predictions, with a focus on probabilistic outputs.
from sklearn.metrics import f1_score, jaccard_score, log_loss
# Predictions
y_pred_knn = knn.predict(X_test)
y_pred_dt = dt.predict(X_test)
y_pred_svm = svm.predict(X_test)
y_pred_lr = lr.predict(X_test)
# Evaluation
print("KNN F1 Score:", f1_score(y_test, y_pred_knn))
print("Decision Tree Jaccard Score:", jaccard_score(y_test, y_pred_dt))
print("SVM Log Loss:", log_loss(y_test, svm.predict_proba(X_test)))
print("Logistic Regression F1 Score:", f1_score(y_test, y_pred_lr))The results indicate the accuracy and effectiveness of each classification model. Below is a summary of model performance based on F1 score, Jaccard index, and Log Loss.
| Model | f1-score | Jaccard | logloss |
|---|---|---|---|
| K-Nearest Neighbors | 0.6468253968253967 | 0.6468253968253967 | NA |
| Decision Tree | 0.6304176516942475 | 0.6304176516942475 | NA |
| SVM | 0.6378600823045267 | 0.6378600823045267 | NA |
| Logistic Regression | 0.6304176516942475 | 0.6304176516942475 | 0.5164726137314147 |
The project demonstrates effective preprocessing, model training, and evaluation for loan eligibility prediction. Logistic Regression provided [interpret results here, e.g., the highest accuracy, balance, etc.].
loan-eligibility-prediction/
│
├── data/
│ ├── loan_data.csv
│
├── notebooks/
│ ├── EDA.ipynb
│ ├── Model_Training.ipynb
│
├── src/
│ ├── preprocessing.py
│ ├── model_training.py
│
├── README.md
└── LICENSEThis project is licensed under the Apache-2.0 License. See the LICENSE file for details.
Mohammed Ammaruddin md.ammaruddin2020@gmail.com