Xgboost: TypeError: 'str' object is not callable

Created on 11 Sep 2017  ·  11Comments  ·  Source: dmlc/xgboost

For bugs or installation issues, please provide the following information.
The more information you provide, the more easily we will be able to offer
help and advice.

Environment info

Operating System:
amazonlinux:latest container which is Red Hat 4.8.3-9

Compiler:
gcc/gcc-c++

Package used (python/R/jvm/C++):
python

xgboost version used:
tags/v0.60

If installing from source, please provide

  1. The commit hash (git rev-parse HEAD)
    4a8d63b6c8711fb839c71e26c659936252df1eb5
  2. Logs will be helpful (If logs are large, please upload as attachment).

If you are using jvm package, please

  1. add [jvm-packages] in the title to make it quickly be identified
  2. the gcc version and distribution
    gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)

If you are using python package, please provide

  1. The python version and distribution
    Python 3.6.2
    joblib==0.11
    numpy==1.13.1
    scipy==0.19.1
    scikit-learn==0.19.0

  2. The command to install xgboost if you are not installing from source

If you are using R package, please provide

  1. The R sessionInfo()
  2. The command to install xgboost if you are not installing from source

Steps to reproduce

  1. Train a model using the XGBClassifier
  2. Persist the model using joblib
  3. In another python process use joblib to load the model
  4. call any method on XGBClassifier that internally calls getbooster()
  5. result is a 'str' object is not callable

What have you tried?

  1. multiple versions of scikit-learn & xgboost
  2. replacing the internal XGBClassifier internal calls to booster() to self._Booster

It looks like when you load a XGBClassifier model that was trained and persisted in another python process when calling any method that internally calls booster() a TypeError: 'str' object is not callable is raised. What's weird is that the only thing booster() is doing is checking if self._Booster is None. So, I think something in the chain of scikit-learn, xgboost and joblib.load() is redefining booster() as a string. I was able to work around this by updating all calls to booster() in sklearn.py to self._Booster.

Most helpful comment

@Diyago Its apparent from the @Zambonilli's comment that *.booster() should be replaced by *._Booster and without brackets. they have added booster as a parameter to the xgboost sklearn family and its a string, thus not callable.

Hope this helps :)

All 11 comments

Is there any workaround?

Sorry, I should have been more clear in my write up above. We ended up adding the following command to our docker file. It's ugly but it works on the tags/v0.60 tag.

sed -i -e 's/booster()/_Booster/g' python-package/xgboost/sklearn.py

We have the same problem too

@Diyago Its apparent from the @Zambonilli's comment that *.booster() should be replaced by *._Booster and without brackets. they have added booster as a parameter to the xgboost sklearn family and its a string, thus not callable.

Hope this helps :)

怎么解决?

How to solve this problem
windows7 python3.6.1 sklearn0.19 xgboost0.7

@wuleiyuan Check my last comment and make the necessary changes in your code. It worked for me! I hope it works for u :)

Upgrading to xgboost0.7 helped solve the problem for me. The problem occurred on Ubuntu 16.04 w/xgboost0.6.

Sometimes using get_booster() instead of booster() just solved the problem.

使用get_booster()就可以解决

使用get_booster()就可以解决

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RanaivosonHerimanitra picture RanaivosonHerimanitra  ·  3Comments

trivialfis picture trivialfis  ·  3Comments

pplonski picture pplonski  ·  3Comments

tqchen picture tqchen  ·  4Comments

nicoJiang picture nicoJiang  ·  4Comments