0% found this document useful (0 votes)
5 views21 pages

Day14 Machine Learning

The document outlines a Machine Learning course focusing on loan prediction using Python, detailing the steps from data understanding and preprocessing to applying various machine learning algorithms. It includes handling missing values, transforming categorical data, and splitting the dataset for training and testing. The course also covers the implementation of algorithms like Logistic Regression, Support Vector Machines, Decision Trees, and KNeighborsClassifier, along with their evaluation metrics.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views21 pages

Day14 Machine Learning

The document outlines a Machine Learning course focusing on loan prediction using Python, detailing the steps from data understanding and preprocessing to applying various machine learning algorithms. It includes handling missing values, transforming categorical data, and splitting the dataset for training and testing. The course also covers the implementation of algorithms like Logistic Regression, Support Vector Machines, Decision Trees, and KNeighborsClassifier, along with their evaluation metrics.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

NATIONAL INSTITUTE OF ELECTRONICS AND INFORMATION TECHNOLOGY

Sumit Complex, A-1/9, Vibhuti Khand, Gomti Nagar, Lucknow,

Setting Up User Accounts

Machine Learning using Python


1 Day 14
Course: Machine Learning using Python
Module: Day 14
2 Index
 Loan Prediction Problem Regression

 Data Understanding and Requirement Underst  Applying Machine Learning Algorithm – Suppor
anding t Vector Mach...

 Data Pre-processing  Applying Machine Learning Algorithm – Decisio


Handling Null Values – Categorical Features n Tree Class...

 Handling Null Values – Numerical Features


 Applying Machine Learning Algorithm –
KNeighborsClassifier
 Changing Categorical Values into Numerical Va
lues  Applying Machine Learning Algorithm

 Train and Test Split


 Applying Machine Learning Algorithm – Logistic
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
3 Loan Prediction Problem
 A Finance company deals in all home loans.
 They have presence across all urban, semi urban and rural areas.
 Customer first apply for home loan after that company validates the customer eligibility for loan.
 Company wants to automate the loan eligibility process (real time) based on customer detail
provided while filling online application form.
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
4 Loan Prediction Problem
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
5 Data Understanding and Requirement Understanding
import pandas as pd
df=pd.read_csv('train.csv')

df.head()

df.describe()
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
6 Data Understanding and Requirement Understanding
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
7 Data Pre-processing
 Preparing X and y

X=df.drop(['Loan_Status','Loan_ID'], axis=1)
y=df['Loan_Status']

 Checking Missing Values

X.isnull().sum()

 Counting frequency in ‘Credit_History’

X['Credit_History'].value_counts()

X['Gender'].value_counts()
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
8 Handling Null Values – Categorical Features
X['Gender'].fillna("Male", inplace=True)
X.isnull().sum()

X['Married'].value_counts()

X['Married'].fillna("Yes", inplace=True)
X.isnull().sum()

X['Dependents'].value_counts()
X['Dependents'].fillna(0,inplace=True)

X['Self_Employed'].value_counts()
X['Self_Employed'].fillna('No',inplace=True)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
9 Handling Null Values – Numerical Features
mean_loan=X['LoanAmount'].mean()
X['LoanAmount'].fillna(mean_loan,inplace=True)
X.isnull().sum()

X['Loan_Amount_Term'].fillna(X['Loan_Amount_Term'].mean(),inplace=True)

X['Credit_History'].fillna(X['Credit_History'].mean(),inplace=True)

X.isnull().sum()
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
10 Changing Categorical Values into Numerical Values
 One-hot Encoding
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
11 Changing Categorical Values into Numerical Values
X=pd.get_dummies(X)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
12 Train and Test Split
from sklearn.model_selection import train_test_split

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.30)

X_train.shape

X_test.shape

y_test.shape
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
13 Applying Machine Learning Algorithm – Logistic Regression
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()

model.fit(X,y)

model.score(X,y)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
14 Applying Machine Learning Algorithm – Support Vector Machines
from sklearn.svm import SVC
svc = SVC()

svc.fit(X, y)

svc.score(X,y)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
15 Applying Machine Learning Algorithm – Decision Tree Classifier
from sklearn.tree import DecisionTreeClassifier

dtf = DecisionTreeClassifier()

dtf.fit(X_train, y_train)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
16 Applying Machine Learning Algorithm – Gaussian NB
from sklearn.naive_bayes import GaussianNB

n_b = GaussianNB()

n_b.fit(X_train, y_train)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
17 Applying Machine Learning Algorithm - KNeighborsClassifier
from sklearn.neighbors import KNeighborsClassifier

knn = KNeighborsClassifier()

knn.fit(X_train, y_train)
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
18 Applying Machine Learning Algorithm
print(lr.score(X_test, y_test))

print(dtf.score(X_test, y_test))

print(n_b.score(X_test, y_test))

print(knn.score(X_test, y_test))

print(svc.score(X_test, y_test))
Course:
Course: NIELITLearning
Machine ‘O’ Levelusing
(IT) Python
Module:
Module: DayM2-R5:
14 Introduction to ICT Resources
0.786666666666666
19 Applying Machine Learning Algorithm
6

0.693333333333333
4
0.78
0.646666666666666
6
0.64
Course: Machine Learning using Python
Module: Day 14
20 References
• Wikipedia.org

• Tutorialspoint.com

• https://www.geeksforgeeks.org/

• https://www.kaggle.com/

• https://github.com/
Course: Machine Learning using Python
Module: Day 14
21

Thank
You ! ! !

You might also like