预处理后的名称特征重要性图 [英] Names features importance plot after preprocessing

查看:51
本文介绍了预处理后的名称特征重要性图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建模型之前,我会像这样缩放

Before building a model I make scaling like this

X = StandardScaler(with_mean = 0, with_std = 1).fit_transform(X)

并在构建特征重要性图之后

and after build a features importance plot

xgb.plot_importance(bst, color='red')
plt.title('importance', fontsize = 20)
plt.yticks(fontsize = 10)
plt.ylabel('features', fontsize = 20)

问题是,我们得到的不是特征名称,而是 f0、f1、f2、f3 等......如何返回功能的名称?

The problem is that instead of feature's names we get f0, f1, f2, f3 etc..... How to return feature's names?

谢谢

推荐答案

在预处理之前我们首先得到特征名称列表

first we get list of feature names before preprocessing

dtrain = xgb.DMatrix( X, label=y)
dtrain.feature_names

然后

bst.get_fscore()
mapper = {'f{0}'.format(i): v for i, v in enumerate(dtrain.feature_names)}
mapped = {mapper[k]: v for k, v in bst.get_fscore().items()}
mapped
xgb.plot_importance(mapped, color='red')

就这些

这篇关于预处理后的名称特征重要性图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆