How to install xgboost in Anaconda Python (Windows platform)?

前端 未结 21 2473
北恋
北恋 2020-11-30 19:25

I am a new Python user. I downloaded the latest Anaconda 3 2.4.1 (Python 3.5) from the below link: https://www.continuum.io/downloads

My PC Configurations are: Windo

相关标签:
21条回答
  • 2020-11-30 19:48

    Anaconda3 version 4.4.0check image Go to Anaconda -> Environments -> from the dropdown select not installed -> If you can see xgboost pr Py-xgboost select and click apply.

    0 讨论(0)
  • 2020-11-30 19:52

    if you found an issue when you try to import xgboost (my case it is Windows 10 and anaconda spyder) do the following:

    1. Click on the windows icon (start button!)
    2. Select and expand the anaconda folder
    3. Run the Anaconda Prompt (as Administrator)
    4. Type the following command as it is mentioned in https://anaconda.org/anaconda/py-xgboost

    conda install -c anaconda py-xgboost

    That's all...Good luck.

    0 讨论(0)
  • 2020-11-30 19:53

    After trying some things the only thing that worked for me is:

    conda install -c anaconda py-xgboost
    
    0 讨论(0)
  • 2020-11-30 19:54

    I was able to install xgboost for Python in Windows yesterday by following this link. But when I tried to import using Anaconda, it failed. I recognized this is due to the fact that Anaconda has a different Python distribution. I then searched again and found this great article which made it!

    The trick is after installing successfully for regular Python, to have it work for Anaconda, you just need to pull up the Anaconda prompt and cd into this folder "code\xgboost\python-package", then run:

    python setup.py install
    

    And voila! The article says you need to add the path, but for me it worked directly. Good luck!

    Also copied below the original contents in case the link is not available...

    Once the last command completes the build is done. We can now install the Python module. What follows depends on the Python distribution you are using. For Anaconda, I will simply use the Anaconda prompt, and type the following in it (after the prompt, in my case [Anaconda3] C:\Users\IBM_ADMIN>):

    [Anaconda3] C:\Users\IBM_ADMIN>cd code\xgboost\python-package
    The point is to move to the python-package directory of XGBoost.  Then type:
    [Anaconda3] C:\Users\IBM_ADMIN\code\xgboost\python-package>python setup.py install
    

    We are almost done. Let's launch a notebook to test XGBoost. Importing it directly causes an error. In order to avoid it we must add the path to the g++ runtime libraries to the os environment path variable with:

    import os
    
    mingw_path = 'C:\\Program Files\\mingw-w64\\x86_64-5.3.0-posix-seh-rt_v4-rev0\\mingw64\\bin'
    
    os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']
    

    We can then import xgboost and run a small example.

    import xgboost as xgb 
    import numpy as np
    data = np.random.rand(5,10) # 5 entities, each contains 10 features
    label = np.random.randint(2, size=5) # binary target
    dtrain = xgb.DMatrix( data, label=label)
    
    dtest = dtrain
    
    param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'binary:logistic' }
    param['nthread'] = 4
    param['eval_metric'] = 'auc'
    
    evallist  = [(dtest,'eval'), (dtrain,'train')]
    
    num_round = 10
    bst = xgb.train( param, dtrain, num_round, evallist )
    
    bst.dump_model('dump.raw.txt')
    

    We are all set!

    0 讨论(0)
  • 2020-11-30 19:54

    The package directory states that xgboost is unstable for windows and is disabled:

    pip installation on windows is currently disabled for further invesigation, please install from github.

    https://pypi.python.org/pypi/xgboost/

    0 讨论(0)
  • 2020-11-30 19:55

    You can install it using pip:

    pip3 install --default-timeout=100 xgboost
    
    0 讨论(0)
提交回复
热议问题