1

I'm trying to import xgboost into jupyter-notebook but get the following error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-9-a585b270d0df> in <module>
      1 import pandas as pd
      2 import numpy as np
----> 3 import xgboost

~/.local/lib/python3.6/site-packages/xgboost/__init__.py in <module>
     14 from . import tracker  # noqa
     15 from .tracker import RabitTracker  # noqa
---> 16 from . import dask
     17 try:
     18     from .sklearn import XGBModel, XGBClassifier, XGBRegressor, XGBRanker

~/.local/lib/python3.6/site-packages/xgboost/dask.py in <module>
     31 from .training import train as worker_train
     32 from .tracker import RabitTracker
---> 33 from .sklearn import XGBModel, XGBClassifierBase, xgboost_model_doc
     34 
     35 # Current status is considered as initial support, many features are

ModuleNotFoundError: No module named 'xgboost.sklearn'

I've downloaded sklearn as well as sci-kit learn and they work fine... Any idea what the problem is?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Sam_K
  • 31
  • 1
  • 2
  • Hi Sam_K, please familiarise yourself with [asking questions](https://stackoverflow.com/help/how-to-ask) before you write your next question! Enjoy your stay at SO :) – Diggy. May 14 '20 at 14:44
  • @Sam_K did you, after that, download xgboost using pip ? – Perl Del Rey May 14 '20 at 14:47
  • 1- close `jupyter notebook`, 2- install your package (`pip(3)`) 3- make sure you are installing and running from the same place(not install on machine's python and run on virtual environment) – Ehsan May 15 '20 at 15:03

3 Answers3

2

You might need to install your packages properly. For best practice, you'll need to use a conda environment. Check out how it works here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Once you have created your environment, activate it and then install all the packages you need. Presumably, you'll have to run the command:

  • conda install -c conda-forge xgboost
  • pip install -U scikit-learn

To install your machine learning packages.

White
  • 305
  • 2
  • 11
1

XGBoost is in the xgboost module. It should be imported as:

from xgboost import XGBRegressor
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Wasiu
  • 41
  • 1
  • 6
0

Install these 2 packages:

pip install xgboost
pip install scikit-learn

or

python -m pip install xgboost
python -m pip install scikit-learn

for ipynb file:

!pip install xgboost
!pip install scikit-learn
Ryan M
  • 18,333
  • 31
  • 67
  • 74
tpd
  • 11
  • 4