2017-08-13 59 views
0

我想用xgbfir包使用Xgboost包來運行示例代碼。我試圖執行的代碼如下:Xgboost TypeError:'str'對象不可調用

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的版本控制?我非常感謝幫助解決此問題的任何幫助。

+0

我沒有得到與版本任何錯誤'xgboost == 0.6a2'和'xgbfir = = 0.2'在Ubuntu上。 –

+0

這個問題可能與軟件包安裝不當有關(即使xgboost運行得很好,除了增強功能)。我在Mac上運行這個版本,版本是xgboost == 0.6和xgbfir == 0.2。你知道一個簡單的方法來將xgboost ==升級到0.6a2嗎? – zad0xlik

+0

那麼我重新安裝xgboost軟件包,它仍然無法正常工作,我不知道如何解決這個問題或去哪裏。 – zad0xlik

回答

0

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

+0

歡迎來到stackoverflow!儘量避免回答評論,除非你有特定的答案。請使用下面的評論框,一旦你有足夠的聲譽,你將能夠評論任何帖子。 :) –