0

I'm getting the following error while importing LGBMResgressor to lightgbm:

ImportError
Traceback (most recent call last)
<ipython-input-38-1a53b4f7b770> in <module>()
      5 from sklearn.kernel_ridge import KernelRidge
      6 import lightgbm as lgb
----> 7 from lightgbm import LGBMRegressor
      8 # from lightgbm.sklearn import LGBMRegressor
      9 from sklearn.base import BaseEstimator, TransformerMixin, RegressorMixin, clone

ImportError: cannot import name 'LGBMRegressor'

lightgbm's version is 2.0.5, and it is installed on Windows 10 by pip install lightgbm.

Zhixin Zhang
  • 71
  • 1
  • 3
  • 7

1 Answers1

0

My environment is linux (python 3.6.1) and I installed with pip install lightgbm, opened a ipython terminal and copy your imports and not occurred error, but i can see an 'inconsistence' in your imports. On line six you make:

import lightgbm as lgb

And on the next line

from lightgbm import LGBMRegressor

On line 6 you already import all module as lgb (line 7 is unnecessary), for use LGBMRegressor just do:

lgb.LGBMRegressor

Finnaly, to make sure that the module are insalled, type in a command line:

python -c "import lightgbm; print(lightgbm.__version__)"

Output:

2.0.1
Sidon
  • 1,316
  • 2
  • 11
  • 26
  • You are right.But on windows,I met this problem,how should I do? – Zhixin Zhang Aug 17 '17 at 07:18
  • First of all, make sure that the module is installed with command `python -c "import lightgbm; print(lightgbm.__version__)"` in line command, the output will be the package's version (2.0.1 in my context). If ok, try to remove line 7 of your imports and when you need to use lightgbm, use this way: lgb.lightgbm – Sidon Aug 17 '17 at 12:20
  • Another test you can do is simply remove the line 6. Keep in mind that you need to be sure that the package is installed, don't forget of the command: `python -c "import lightgbm; print(lightgbm.__version__)"` – Sidon Aug 17 '17 at 12:26