1、skleran中需要模型,但是模型本身没有提供,有种方式可以用:
def adaboost_regression(xx_train, xx_test, y_train, y_test,train=True):
model=None
if train:
model = AdaBoostRegressor(n_estimators=10)
model.fit(xx_train, y_train)
# 保存模型
with open("./AdaBoostRegressor","wb") as f:
pickle.dump(model,f)
else:
#导入模型
with open("./AdaBoostRegressor","rb") as f:
model=pickle.load(f)
print(model,type(model))
for decesion in model.estimators_:
tree.plot_tree(decesion,fontsize=15) #显示决策树的数据
# dot_data = tree.export_graphviz(decesion,
# filled = True, #填充颜色
# rounded = True #画出的方块无棱角
# )
# graph = graphviz.Source(dot_data)
# graph.save("./1.gv")
y_predict = model.predict(xx_test)
return y_predict