Skip to content

Commit

Permalink
Merge pull request #3 from ShankarAnbalagan/master
Browse files Browse the repository at this point in the history
id3 using functions
  • Loading branch information
ShivamNagpal authored Dec 8, 2019
2 parents 54911ad + ec0bf8b commit 262e79b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Alternatives/03.ID3_using_sklearn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import csv
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import LabelEncoder

train_data=list(csv.reader(open('ds2.csv')))[1:]
test_data=['Rainy','Mild','High','True','NaN']
train_data.append(test_data)

train_data=np.array(train_data).transpose()
encoder=LabelEncoder()
for i in range(len(train_data)):
data[i]=encoder.fit_transform(train_data[i])

x=train_data[:-1].transpose()
y=train_data[-1]
test_data=x[-1]

tree=DecisionTreeClassifier()
tree.fit(x[:-1],y[:-1])
pred=tree.predict([x[-1]])

if pred[0]=='2':
print('Can play tennis')
elif pred[0]=='1':
print('Cannot play tennis')

0 comments on commit 262e79b

Please sign in to comment.