python画图时报错无法使用,
classifier=GradientBoostingClassifier(loss='deviance',criterion='mae',n_estimators=5)
fig,ax = plt.subplots(figsize=(10,15))
plot_importance(classifier,
height=0.5,
ax=ax,
max_num_features=50,
importance_type='gain')
报错如下:
ValueError Traceback (most recent call last)
<ipython-input-139-554a6ae0973b> in <module>
12 ax=ax,
13 max_num_features=50,
---> 14 importance_type='gain')
D:\ProgramData\Anaconda3\lib\site-packages\xgboost\plotting.py in plot_importance(booster, ax, height, xlim, ylim, title, xlabel, ylabel, fmap, importance_type, max_num_features, grid, show_values, **kwargs)
69 importance = booster
70 else:
---> 71 raise ValueError('tree must be Booster, XGBModel or dict instance')
72
73 if not importance:
ValueError: tree must be Booster, XGBModel or dict instance
根据之前方法查看文件:plotting.py没有问题,麻烦帮看下,谢谢,
进入xgboost.plot_importance函数定义, plotting.py , 把 booster.get_score(importance_type=importance_type) 改成 booster.get_score(importance_type=importance_type, fmap=fmap) 亲测好使
版权声明:本文为CSDN博主「若星汉灿烂」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:
代码估计是写错了把