#用决策树来进行分类
from sklearn import tree#导入sklearn框架的tree模块,以便于构造决策树
x=iris_df.data
y=iris_df.target
clf = tree.DecisionTreeClassifier(max_depth=3)#构造最大深度为3的决策树
clf.fit(x, y)#使用训练集训练模型
print(clf.predict([[5.1,3.5,1.4,0.2]]))#注意这个有两个[],一个[]不行的
# 输出为[0]
from sklearn.tree import DecisionTreeClassifier
from sklearn2pmml.pipeline import PMMLPipeline
pipeline = PMMLPipeline([
("classifier", DecisionTreeClassifier())
])
pipeline.fit(x, y)
from sklearn2pmml import sklearn2pmml
sklearn2pmml(pipeline, "DecisionTreeIris2.pmml", with_repr = True)
from pypmml import Model
model = Model.load("DecisionTreeIris2.pmml")
model.predict([5.1,3.5,1.4,0.2])
#输出为[0.0, 0.0, 1.0]