在python中绘制决策树

时间:2016-03-09 23:05:52

标签: python plot

我想通过使用python中sklearn的数据集来绘制决策树的学习曲线。我试图编写代码来编写学习模型。

# prepare data
from sklearn import datasets
iris = datasets.load_iris()
data = iris.data
target = iris.target
# train a decision tree
from sklearn import tree
clf = tree.DecisionTreeClassifier()
clf.fit(data, target)
# predict from SVM model
print clf.predict([[5.1,3.5,1.4,0.2]]) #note that you need to pass a list of    list
print clf.predict([[5.1,3.5,1.4,0.2], [4.9,3.0,1.4,0.2]]) #since sometimes you  want to make more than one predictions in one call

0 个答案:

没有答案