-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_start1.py
More file actions
28 lines (23 loc) · 777 Bytes
/
ai_start1.py
File metadata and controls
28 lines (23 loc) · 777 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from sklearn.datasets import load_iris # Iris花的一个数据集
from sklearn import tree
iris = load_iris()
# print(iris.feature_names)
## ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
# print(iris.target_names)
## ['setosa' 'versicolor' 'virginica']
# print(iris.data[0])
## [5.1 3.5 1.4 0.2]
# print(iris.target[0])
## 0
test_id = [0,50,100] # 选择3个data和target用作测试
train_data = np.delete(iris.data, test_id, axis=0)
train_target = np.delete(iris.target, test_id)
test_data = iris.data[test_id]
test_target = iris.target[test_id]
clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target)
print(test_target)
print(clf.predict(test_data))