ImportError : cannot import name "XGBClassifier"
Asked Answered
P

5

9

I am under anaconda notebook.

I have recently installed xgboost but I cannot access XGBClassifier :

from xgboost import XGBClassifier

When I import only xgboost and write xgboost it prints that the module is here ..

Peacoat answered 1/7, 2017 at 7:0 Comment(0)
P
5

The issue was that I did not install xgboost for anaconda, so writing :

conda install -c conda-forge xgboost=0.6a2

solved my problem, thank you

Peacoat answered 1/7, 2017 at 7:27 Comment(2)
The following packages are not available from current channels:- xgboost=0.6a2 is what giving me in anaconda promptLima
How to install XGBClassifier using pip?Rheinland
R
26

Mine works after renaming the py file I was working on. I my case, from 'xgboost' to something else.

P.S. Restarting anaconda/spyder didn't work for me

Residual answered 16/6, 2018 at 15:53 Comment(1)
A file named xgboost.py overwrites the module you're trying to load. You'll need to make sure there are no files of that name in your working directory.Dagnah
P
5

The issue was that I did not install xgboost for anaconda, so writing :

conda install -c conda-forge xgboost=0.6a2

solved my problem, thank you

Peacoat answered 1/7, 2017 at 7:27 Comment(2)
The following packages are not available from current channels:- xgboost=0.6a2 is what giving me in anaconda promptLima
How to install XGBClassifier using pip?Rheinland
C
1

use this instead : -

import xgboost as xgb
xgb_regressor = xgb.XGBRegressor()

This worked for me.......

Concettaconcettina answered 11/9, 2020 at 12:28 Comment(0)
L
0

Install xgboost in anaconda, conda install conda-forge::xgboost

Linotype answered 18/2 at 4:6 Comment(0)
L
0

Install xgboost on anaconda3, pip install xgboost

After that when importing the library use

from xgboost.sklearn import XGBRegressor

Works perfectly

Landsman answered 8/3 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.