-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIris.py
More file actions
35 lines (24 loc) · 787 Bytes
/
Iris.py
File metadata and controls
35 lines (24 loc) · 787 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
29
30
31
32
33
34
35
from sklearn.datasets import load_iris
from sklearn import tree
import numpy as np
# work with data, here is iris data for this example
iris = load_iris()
print (iris.feature_names)
print (iris.target_names)
print (iris.data[0])
print (iris.data[1])
print (iris.target[0])
print (iris.target[1])
for i in range(len (iris.target)):
print ("Example %d: Label %s, features %s" % (i, iris.target[i], iris.data[i]))
test_idx = [0, 50, 100]
# testing data and training data
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis=0)
# testing data
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]
clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target)
print (test_target)
print (clf.predict(test_data))