训练好的模型封装成PMML文件,就可以供数据直接调用。具体代码如下:
from sklearn import tree
from sklearn.datasets import load_iris
from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml
if __name__ == '__main__':
# 经典数据集
iris = load_iris()
# print(iris.keys())
# 样本特征
x = iris.data
# print(x)
# 分类目标
y = iris.target
# print(y)
# 用决策树分类
pipeline = PMMLPipeline([("classifier", tree.DecisionTreeClassifier())])
# 训练
result = pipeline.fit(x, y)
print(result)
# 输出PMML文件
sklearn2pmml(pipeline, "D:\iris.pmml", with_repr=True)