DecisionTree Classifier

➜ test ✗ cat DecisionTree.py
from sklearn import tree

# 训练集
X = [[0, 0], [1, 1]]
Y = [0, 1]

# 定义一个DecisionTreeClassifier分类器
clf = tree.DecisionTreeClassifier()

# 拟合X, Y数据
clf.fit(X, Y)

# 预测结果
print(clf.predict([[2, 2]]))

运行, 输出预测结果

➜ test ✗ python3 DecisionTree.py
[1]