How to install xgboost in python on MacOS?

前端 未结 9 777
别那么骄傲
别那么骄傲 2020-12-23 22:19

I am a newbie and learning python. Can someone help me- how to install xgboost in python. Im using Mac 10.11. I read online and did the below mentioned step, but not able to

相关标签:
9条回答
  • 2020-12-23 22:51

    It's a little more complicated if you want to use multi-threading. For the record, I am using a Mac with OS X 10.10 (Yosemite). It took me a while to work through the various issues, but it is now running nicely in my Anaconda (Py36) environment.

    For multi-threading you need to do the following first (install homebrew if you have not done so):

    brew install gcc --without-multilib
    

    You might get some warnings to unlink directories or delete them if you have other versions installed; follow the warnings/instructions.

    Next get the xgboost files from Github. I downloaded it to Anaconda/pkgs directory.

    git clone --recursive https://github.com/dmlc/xgboost
    

    The next series of steps differ from the documentation on the xgboost site, and I cobbled it together from lots of sources and also experimenting. The problem is that some key lines in the make files are commented out and also not fully specified.

    cd xgboost; cp make/config.mk ./config.mk
    

    Now, use your favorite editor (I used vi), and go into the file that you copied from /make to /xgboost

    vi config.mk
    

    Uncomment the lines near the top of the file:

    export CC = gcc

    export CXX = g++

    Change them to the following:

    export CC = gcc-6
    
    export CXX = g++-6
    

    It is possible that simply uncommenting the lines solves the problem. It did not for me; I needed to add the -6 to both lines. Save the file.

    Also, make changes to the file xgboost/Makefile; change lines:

    export CC = $(if $(shell which clang), clang, gcc)
    ...
    ...
    export CXX = $(if $(shell which clang++), clang++, g++)
    

    to the following:

    export CC = $(if $(shell which clang), clang, gcc-6)
    ...
    ...
    export CXX = $(if $(shell which clang++), clang++, g++-6)
    

    Again, I used vi for this editing.

    Save the file and now you need to run a cleaning step since you changed the Makefile.

    make clean_all && make -j4
    

    This should configure it cleanly and build the library. You still need to install it.

    cd python-package; python setup.py install
    

    Now restart Python/Anaconda and you should be able to import the library.

    0 讨论(0)
  • 2020-12-23 22:54

    For a newbie learning python and Machine Learning on Mac, I would strongly recommand to install Anaconda first (install doc).

    Anaconda is a freemium open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment.

    If you installed Anaconda for Python 2.7, then you should have no troubles installing XGBoost with:

    conda install -c aterrel xgboost=0.4.0
    

    If you already have Anaconda installed and that your pip XGBoost installation failed, you should try:

    conda remove xgboost
    conda install -c aterrel xgboost=0.4.0
    
    0 讨论(0)
  • 2020-12-23 22:54

    FOR PYTHON 2.7

    $ conda install -c aterrel xgboost=0.4.0
    

    OR

    $ conda install -c biconda xgboost=0.6a2
    

    FOR PYTHON 3.6

    $ brew install gcc@5
    $ pip install xgboost
    
    0 讨论(0)
  • 2020-12-23 22:57

    I followed Bryan Butler's answer and it worked, I just needed to make some changes:

    • gcc-7/g++-7 instead of gcc-6/g++-6.
    • While running make clean_all && make -j4 I had an error with as. So, I just had to run export PATH=/usr/bin:$PATH and it worked!
    0 讨论(0)
  • 2020-12-23 23:01

    If you have anaconda installed, this worked for me:

    Simply type in the terminal:

    conda install -c conda-forge xgboost
    
    0 讨论(0)
  • 2020-12-23 23:03

    You can pip install catboost. It is a recently open-sourced gradient boosting library, it has similar interfaces and is more accurate, than XGBoost, faster and has categorical features support out of the box. Here is the site of the library: https://catboost.yandex

    0 讨论(0)
提交回复
热议问题