2

This is related to Names features importance plot after preprocessing

In my case the problem is in the graph:

for importance_type in ('weight', 'gain', 'cover'):
    print('%s:' % importance_type,bst.get_score(importance_type = importance_type))
    node_params = {'shape': 'box', #Green
                   'style' : 'filled, rounded',
                   'fillcolor': '#78fcb'}
xgb.to_graphviz(clf_xgb,size = '10,10',condition_node_params= node_params)
graph_data = xgb.to_graphviz(clf_xgb,size = '10,10',condition_node_params=node_params)
graph_data.view(filename= 'xgboost_response')
plt.show()
for importance_type in ('weight', 'gain', 'cover'):
    print('%s:' % importance_type,bst.get_score().items(importance_type = importance_type))

I add feature_names as an inside function , when I tried adding "feature_cols" manually ,which contains the feature names, I had an error. This code doesn't show feature names

Any suggestion would be appreciated

*EDITED

    feature_cols = data_set_sub.columns[0:-1]
    X = data_set_sub[feature_cols] # Independent variables - features
    y = data_set_sub.New # Dependent variables - class
    y = y.to_list()
    le = preprocessing.LabelBinarizer()
    y = le.fit_transform(y)
    #* here goes the training/test split
TheUndecided
  • 187
  • 1
  • 12

1 Answers1

0

Answer is in here: How do I include feature names in the plot_tree function from the XGBoost library? by FChm

Several notes: first column starts with 0, second with your feature name and third with feature type: i.e: "q" / "i". Look out for duplicates! they can confuse your results

fmap added

xgb.to_graphviz(clf_xgb, size='10,10', condition_node_params=node_params,fmap='feature_map.txt')
            graph_data = xgb.to_graphviz(clf_xgb, size='10,10', condition_node_params=node_params,fmap='feature_map.txt')
            graph_data.view(filename='xgboost_response2')
            plt.show()
TheUndecided
  • 187
  • 1
  • 12