+3 votes
in Machine Learning by (29.6k points)
recategorized by

I trained a model using XGBClassifier, but when I try to get the score of features using get_score() function, it gives error : "TypeError: 'str' object is not callable". My code is as follows.

bst = xgb.XGBClassifier(**param).fit(X[tridx], Y[tridx])

preds = bst.predict_proba(X[teidx])

imps = bst.booster().get_score(importance_type='gain')

Traceback (most recent call last):
  File "classify_metavisits_new.py", line 208, in <module>
  File "classify_metavisits_new.py", line 199, in main
    classify_the_data (X, Y, metavisits_list)
  File "classify_metavisits_new.py", line 161, in classify_the_data
    imps = bst.booster().get_score(importance_type='gain')
TypeError: 'str' object is not callable

What should I do to fix it?

1 Answer

+1 vote
by (21.3k points)

If you have xgboost 0.7 and sklearn 0.19 on your machine, try get_booster() instead of booster(). It will work. if it doesn't work, you need to upgrade both xgboost and sklearn.

imps = bst.get_booster().get_score(importance_type='gain')