-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIris.py
More file actions
28 lines (20 loc) · 703 Bytes
/
Iris.py
File metadata and controls
28 lines (20 loc) · 703 Bytes
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
from sklearn.datasets import load_iris
from sklearn import tree
import numpy as np
iris = load_iris()
# initializing seperating index
test_index = [0, 50, 100]
# seperating data to test
train_data = np.delete(iris.data, test_index, axis=0)
# seperating targets to test
train_target = np.delete(iris.target, test_index)
# training portion of data
test_data = iris.data[test_index]
# training portion of targets
test_target = iris.target[test_index]
# initializing the classifier and the training algorithm
clf = tree.DecisionTreeClassifier()
clf = clf.fit(train_data, train_target)
# testing predictions
print("Actual result : ", test_target)
print("Predicted result : ", clf.predict(test_data))