Xgboost TypeError:' str'对象不可调用

时间:2017-08-13 03:48:51

标签: python xgboost

我正在尝试使用带有xgbfir包的Xgboost包运行示例代码。我试图执行的代码如下:

from sklearn.datasets import load_iris, load_boston
import xgboost as xgb
import xgbfir

# loading database
boston = load_boston()

# doing all the XGBoost magic

xgb_rmodel = xgb.XGBRegressor().fit(boston['data'], boston['target'])

# saving to file with proper feature names
xgbfir.saveXgbFI(xgb_rmodel, feature_names=boston.feature_names, OutputXlsxFile = 'bostonFI.xlsx')

# loading database
iris = load_iris()

# doing all the XGBoost magic
xgb_cmodel = xgb.XGBClassifier().fit(iris['data'], iris['target'])

# saving to file with proper feature names
xgbfir.saveXgbFI(xgb_cmodel, feature_names=iris.feature_names, OutputXlsxFile = 'irisFI.xlsx')

我收到以下错误,无法理解为什么会这样。似乎booster()无法在Xgboost中调用,但我不知道如何解决这个问题或从哪里开始。

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-152-af422c4cc325> in <module>()
     10 
     11 # saving to file with proper feature names
---> 12 xgbfir.saveXgbFI(xgb_rmodel, feature_names=boston.feature_names, OutputXlsxFile = 'bostonFI.xlsx')
     13 
     14 

/Users/xxxxxxx/anaconda/lib/python2.7/site-packages/xgbfir/main.pyc in saveXgbFI(booster, feature_names, OutputXlsxFile, MaxTrees, MaxInteractionDepth, MaxDeepening, TopK, MaxHistograms, SortBy)
    589     if not 'get_dump' in dir(booster):
    590         if 'booster' in dir(booster):
--> 591             booster = booster.booster()
    592         else:
    593             return -20

T

ypeError: 'str' object is not callable

这可能是由于Xgboost的版本控制吗?我非常感谢帮助解决这个问题的任何帮助。

1 个答案:

答案 0 :(得分:0)

xgbfir.saveXgbFI(xgb_rmodel.get_booster(),feature_names = boston.feature_names,OutputXlsxFile ='bostonFI.xlsx')