Arli94
Arli94

Reputation: 720

ImportError : cannot import name "XGBClassifier"

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 ..

Upvotes: 10

Views: 29041

Answers (5)

Shreyansh Singh
Shreyansh Singh

Reputation: 1

Install xgboost on anaconda3, pip install xgboost

After that when importing the library use

from xgboost.sklearn import XGBRegressor

Works perfectly

Upvotes: 0

Nehal
Nehal

Reputation: 1

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

Upvotes: 0

Abhinav Mane
Abhinav Mane

Reputation: 41

use this instead : -

import xgboost as xgb
xgb_regressor = xgb.XGBRegressor()

This worked for me.......

Upvotes: 1

Fai Lambrechts
Fai Lambrechts

Reputation: 316

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

Upvotes: 26

Arli94
Arli94

Reputation: 720

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

Upvotes: 5

Related Questions