-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecision Tree.py
More file actions
159 lines (63 loc) · 1.62 KB
/
decision Tree.py
File metadata and controls
159 lines (63 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
# coding: utf-8
# In[96]:
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion_matrix,classification_report
# Load Dataset
# In[59]:
df=pd.read_csv("C:/Users/3yearb1/Desktop/ML_datasets/PlayTennis.csv")
# In[60]:
display(df)
# In[47]:
print(df.describe())
# In[48]:
outlook = df["Outlook"].str.get_dummies(" ")
print(outlook)
# In[49]:
temp = df["Temperature"].str.get_dummies(" ")
print(temp)
# In[50]:
hum = df["Humidity"].str.get_dummies(" ")
print(hum)
# In[51]:
wind = df["Wind"].str.get_dummies(" ")
print(wind)
# In[52]:
playtennis = df["Play Tennis"].str.get_dummies(" ")
print(playtennis)
# In[61]:
df.drop(['Outlook','Temperature','Humidity','Wind','Play Tennis'],axis=1,inplace=True)
# In[62]:
df=pd.concat([outlook,temp,hum,wind,playtennis],axis=1)
# In[66]:
display(df)
# Prepare X and Y
# In[67]:
x=df.drop(['Yes','No'],axis=1)
y=df[['Yes']]
# Split X & Y into training and testing dataset
# In[89]:
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=42)
# Building Model
# In[90]:
dt=DecisionTreeClassifier(criterion = 'entropy')
# Training Model
# In[91]:
dt.fit(X_train,y_train)
# Testing Model
# In[92]:
y_pred = dt.predict(X_test)
# In[93]:
print(y_pred)
# Calculating Confusion matrix and Classification report
# In[94]:
m=confusion_matrix(y_test,y_pred)
# In[95]:
m
# In[100]:
report = classification_report(y_test, y_pred)
display(report)
# In[ ]: