XGBoost is a library for developing very fast and accurate gradient boosting models.
It is a library at the center of many winning solutions in Kaggle data science competitions.
In this tutorial, you will discover how to install the XGBoost library for Python on macOS.
Tutorial Overview
This tutorial is divided into 3 parts; they are:
- Install MacPorts
- Build XGBoost
- Install XGBoost
Note: I have used this procedure for years on a range of different macOS versions and it has not changed. This tutorial was written and tested on macOS High Sierra (10.13.1).
1. Install MacPorts
You need GCC and a Python environment installed in order to build and install XGBoost for Python.
I recommend GCC 7 and Python 3.6 and I recommend installing these prerequisites using MacPorts.
- 1. For help installing MacPorts and a Python environment step-by-step, see this tutorial:
>> How to Install a Python 3 Environment on Mac OS X for Machine Learning and Deep Learning
- 2. After MacPorts and a working Python environment are installed, you can install and select GCC 7 as follows:
- 3. Confirm your GCC installation was successful as follows:
You should see the version of GCC printed; for example:
What version did you see?
Let me know in the comments below.
2. Build XGBoost
The next step is to download and compile XGBoost for your system.
- 1. First, check out the code repository from GitHub:
- 2. Change into the xgboost directory.
- 3. Copy the configuration we intend to use to compile XGBoost into position.
- 4. Compile XGBoost; this requires that you specify the number of cores on your system (e.g. 8, change as needed).
The build process may take a minute and should not produce any error messages, although you may see some warnings that you can safely ignore.
For example, the last snippet of the compilation might look as follows:
Did this step work for you?
Let me know in the comments below.
3. Install XGBoost
You are now ready to install XGBoost on your system.
- 1. Change directory into the Python package of the xgboost project.
- 2. Install the Python XGBoost package.
The installation is very fast.
For example, at the end of the installation, you may see messages like the following:
- 3. Confirm that the installation was successful by printing the xgboost version, which requires the library to be loaded.
Save the following code to a file called version.py.
Run the script from the command line:
You should see the XGBoost version printed to screen:
How did you do?
Post your results in the comments below.
Further Reading
This section provides more resources on the topic if you are looking to go deeper.
- How to Install a Python 3 Environment on Mac OS X for Machine Learning and Deep Learning
- MacPorts Installation Guide
- XGBoost Installation Guide
Summary
In this tutorial, you discovered how to install XGBoost for Python on macOS step-by-step.
Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.
No comments:
Post a Comment