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)
The problem is that instead of feature's names we get f0, f1, f2, f3 etc..... How to return feature's names?
thanks
first we get list of feature names before preprocessing
dtrain = xgb.DMatrix( X, label=y)
dtrain.feature_names
Then
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')
that's all