Professional Documents
Culture Documents
Report
Report
00
00
by grammer jtp
General metrics
16,704 2,053 229 8 min 12 sec 15 min 47 sec
characters words sentences reading
speaking
time time
Writing Issues
No issues found
Plagiarism
This text hasn’t been checked for plagiarism
Sentence Length 9
Measures average sentence length words per sentence
00
Code:
Importing Libraries
import numpy as np
import pandas as pd
test_loan = pd.read_csv('/kaggle/input/loan-eligible-
dataset/loan-test.csv')
train_loan.info()
Output:
Output:
train_loan.isna().sum()
# round((train_loan.isna().sum() / len(train_loan)) * 100,
2)
Output:
msno.bar(train_loan)
Output:
msno.matrix(train_loan )
Output:
train_loan['Credit_History'].fillna(train_loan['Credit_Histo
ry'].mode(), inplace=True) # Mode
test_loan['Credit_History'].fillna(test_loan['Credit_Histor
y'].mode(), inplace=True) # Mode
train_loan['LoanAmount'].fillna(train_loan['LoanAmount']
.mean(), inplace=True) # Mean
test_loan['LoanAmount'].fillna(test_loan['LoanAmount'].
mean(), inplace=True) # Mean
train_loan.Loan_Status =
train_loan.Loan_Status.replace({"Y": 1, "N" : 0})
# test_loan.Loan_Status =
test_loan.Loan_Status.replace({"Y": 1, "N" : 0})
train_loan.Gender = train_loan.Gender.replace({"Male":
1, "Female" : 0})
test_loan.Gender = test_loan.Gender.replace({"Male": 1,
"Female" : 0})
train_loan.Married = train_loan.Married.replace({"Yes":
1, "No" : 0})
test_loan.Married = test_loan.Married.replace({"Yes": 1,
"No" : 0})
train_loan.Self_Employed =
train_loan.Self_Employed.replace({"Yes": 1, "No" : 0})
test_loan.Self_Employed =
test_loan.Self_Employed.replace({"Yes": 1, "No" : 0})
train_loan['Gender'].fillna(train_loan['Gender'].mode()[0],
inplace=True)
test_loan['Gender'].fillna(test_loan['Gender'].mode()[0],
inplace=True)
train_loan['Dependents'].fillna(train_loan['Dependents'].
mode()[0], inplace=True)
test_loan['Dependents'].fillna(test_loan['Dependents'].m
ode()[0], inplace=True)
train_loan['Married'].fillna(train_loan['Married'].mode()
[0], inplace=True)
test_loan['Married'].fillna(test_loan['Married'].mode()[0],
inplace=True)
train_loan['Credit_History'].fillna(train_loan['Credit_Histo
ry'].mean(), inplace=True)
test_loan['Credit_History'].fillna(test_loan['Credit_Histor
y'].mean(), inplace=True)
Columns like Property_Area, Dependents, and Education
contain various values. Therefore, we can employ the
LabelEncoder from the sklearn package.
Data Visualisation
Here, we are presenting visual insights derived from the
dataset. To achieve this, we require certain packages,
namely matplotlib and seaborn.
import matplotlib.pyplot as plt
%matplotlib inline
train_loan
Output:
train_loan.plot(figsize=(18, 8))
plt.show()
Output:
plt.figure(figsize=(18, 6))
plt.subplot(1, 2, 1)
train_loan['ApplicantIncome'].hist(bins=10)
plt.title("Loan Application Amount ")
plt.subplot(1, 2, 2)
plt.grid()
plt.hist(np.log(train_loan['LoanAmount']))
plt.title("Log Loan Application Amount ")
plt.show()
Output:
plt.figure(figsize=(18, 6))
plt.title("Relation Between Application Income vs Loan
Amount ")
plt.grid()
plt.scatter(train_loan['ApplicantIncome'] ,
train_loan['LoanAmount'], c='k', marker='x')
plt.xlabel("Applicant Income")
plt.ylabel("Loan Amount")
plt.show()
Output:
plt.figure(figsize=(12, 6))
plt.plot(train_loan['Loan_Status'],
train_loan['LoanAmount'])
plt.title("Loan Application Amount ")
plt.show()
Output:
plt.figure(figsize=(12,8))
sns.heatmap(train_loan.corr(), cmap='coolwarm',
annot=True, fmt='.1f', linewidths=.1)
plt.show()
Output:
Modelling
# import machine learning model from sklearn package
train_x = train_loan[train_features].values
train_y = train_loan['Loan_Status'].values
test_x = test_loan[train_features].values
model_logistic.fit(train_x, train_y)
Output:
predicted = model_logistic.predict(test_x)
Conclusion
Loan eligibility prediction using Machine Learning is a
remarkable advancement in the financial sector. It
streamlines the lending process, making it efficient,
objective, and responsive to individual needs. As
technology evolves and ethical considerations are
addressed, ML-powered lending has the potential to
revolutionize the financial landscape, making credit
accessible to those who need it while maintaining
transparency and fairness.