我已经训练了一个 XGBoost 模型并使用 plot_importance() 来绘制在训练模型中哪些特征是最重要的。虽然,情节中的数字有几个十进制值,这会淹没情节并且不适合情节。
我已经搜索了绘图格式化选项,但我只找到了如何格式化轴(尝试格式化 X 轴,希望它也会格式化相应的轴)
我在 Jupyter Notebook 中工作(如果这有什么不同的话)。代码如下:
xg_reg = xgb.XGBClassifier(
objective = 'binary:logistic',
colsample_bytree = 0.4,
learning_rate = 0.01,
max_depth = 15,
alpha = 0.1,
n_estimators = 5,
subsample = 0.5,
scale_pos_weight = 4
)
xg_reg.fit(X_train, y_train)
preds = xg_reg.predict(X_test)
ax = xgb.plot_importance(xg_reg, max_num_features=3, importance_type='gain', show_values=True)
fig = ax.figure
fig.set_size_inches(10, 3)
有什么我想念的吗?是否有要传递的格式化函数或参数?
我希望能够格式化特征重要性分数,或者至少去掉小数部分(例如“25”而不是“25.66521”)。在下面附上当前的图。