Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views3 pages

Decision Tree Classifier

The document outlines a Python script that utilizes libraries such as NumPy, Matplotlib, and Pandas to analyze user data from a CSV file. It extracts independent and dependent variables, splits the data into training and test sets, applies standard scaling, and fits a Decision Tree classifier to predict outcomes. Finally, it evaluates the model's performance using a confusion matrix.

Uploaded by

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

Decision Tree Classifier

The document outlines a Python script that utilizes libraries such as NumPy, Matplotlib, and Pandas to analyze user data from a CSV file. It extracts independent and dependent variables, splits the data into training and test sets, applies standard scaling, and fits a Decision Tree classifier to predict outcomes. Finally, it evaluates the model's performance using a confusion matrix.

Uploaded by

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

[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])

You might also like