Day14 Machine Learning
Day14 Machine Learning
Data Understanding and Requirement Underst Applying Machine Learning Algorithm – Suppor
anding t Vector Mach...
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']
X.isnull().sum()
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.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 ! ! !