Names show importance after preprocessing

Before building the model, I do the scaling as follows:

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

and after plotting the importance of functions

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

enter image description here

The problem is that instead of the names of the elements, we get f0, f1, f2, f3, etc. ...... How to return the names of objects?

thank

+7
source share
2 answers

first we get a list of function 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')

what all

+10
source

For xgboost 0.82, the answer is quite simple, just replace the element name attribute with a list of element name strings.

trained_xgbmodel.feature_names = feature_name_list
xgboost.plot_importance(trained_xgbmodel)
0
source

Source: https://habr.com/ru/post/1649222/


All Articles