[2] import numpy as nm
import matplotlib. pyplot as mtp
import pandas as pd
#importing dat asets
da·ta_set=pd. read_c sv ( 'User _Data. csv ' )
#Extracting Independent and dependent Variable
x=data_set.iloc [ :, [ 2, 3] ] .values
y=data_set.iloc [ :,4 ] . va l ues
print ( data_set )
User ID Gender Age Es tima11:edSalary Purc ha s ed
0 15624510 Male 19 19000 0
1 15810944 Male 35 20000 0
2 i5668575 Female 26 43000 0
3 15603246 Female 27 57000 0
4 15804002 Male 19 76000 0
395 15691863 Female 46 41000 1
396 15706071 Male 51 23000 1
397 15654296 Female 50 20000 1
398 15755018 Male 36 33000 0
399 15594041 Female 49 36000 1
✓
Os
(3) from sklearn.model_se l ection import train_test_split
x_train,x_test, y_train,y_test=train_test_ split ( x,y,test_size=0.25 ,random_state=0)
✓
Os 0 from sklearn.preprocessing import StandardScaler
st_x=StandardScaler()
x_train=st_x.fit_transform ( x_train )
x_test=st_x.transform ( x_test )
✓
Os
(6) #Fitting Decision Tree classifier to the training s et
from sklearn. t ree import DecisionTreeClassifie r
classifier=DecisionTreeClassifier (criterion='ent r opy' ,random_state=0 )
classifier.fit ( x_train, y_train)
• DecisionTreeClassifier
DecisionTreeClassif ier ( criterion='entropy', random_ state=0)
✓ [8]
Os
#Predicting the test set result
y_pred=cla ss ifier.predict ( x_test )
print (y_pred )
(0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 0 1 0 0 1 0 , 1 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1
0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1]
✓
ls 0 #Creating the Confusion matrix
from sklearn.metrics i mport confusi on_matrix
cm=confusion_matrix (y_test,y_pred )
print ( cm )
(3 [(62 6)
[ 3 29])