Installing LightGBM on MacOSX with Python wrapper
JeanFrancoisPuget 2700028FGP Comment (1) Visits (16427)
There is a new kid in machine learning town: LightGBM. It is an implementation of gradient boosted decision trees (GBDT) recently open sourced by Microsoft. GBDT is a family of machine learning algorithms that combine both great predictive power and fast training times. Interested readers can find a good introduction on how GBDT work here.
Why does LightGBM matter? It matters because it is way faster to train than the reference implementation for GBDT ( XGBoost.) I learned about LightGBM few days ago and decided to give it a try.
Given LightGBM has been developed at Microsoft I don't expect any installation issue on Windows. However, I found that the instructions provided for inst
Let's start. We'll follow the Installation Guide provided on LightGBM GitHub repository. The first step is to launch terminal. We first launch the launchpad by clicking on this icon:
In the Launchpad windows, we select other, then we select terminal.
Once we have a terminal window, we type the following.
brew install cmake
Bad start, as this yields an error
Fortunately, the error message explains how to fix it. We need to install some prerequisite software. I wish all error messages were that helpful ...
Let's do it.
A windows pops up, indicating yet another dependency:
We click on Install, which brings a licence agreement we agree with. After some time another windows pops up, and some download begins. Download may take few minutes, depending on your internet connection. When it finishes, the software is installed:
After clicking the done button, we can resume our installation with this:
brew install cmake
This time installation proceeds, with downloads of Python packages then some compilation. Overall build takes about 5 minutes on my machine.
That was the first step of the instructions. Next step is this:
brew install gcc --without-multilib
I so happens that I already installed gcc as output shows:
However, a warning is a bit suspicious. It says my OS version isn't supported yet by gcc.
We need to install a newer version of g++. Another reason for that is that LighGBM build assumes we are using g++-6 whereas we have g++-5 installed. I found this tutorial to be useful for installing g++-6 on MacOSX Sierra. Let's follow its instructions. Beware, this takes at least one hour.
Once done, we add a soft link in /usr/local/bin to the newly built compiler so that it can be easily invoked:
Next is to download the code for LightGBM. Before that, let's go to where we want to have the code. For instance, we can create a code directory in our home directory:
Then we can download the code:
git clone --recursive http
Next commands are:
mkdir build ; cd buildcmake -DCM
This completes fine. LightGBM should be usable now. The executable is now in the top of the directory we used when cloning code, i.e. ~/code/LightGBM in my case. This command
The executable is lightgbm. Let's try it using one of the examples provided with the code:
This trains lightgbm using the train-config configuration. Seems everything worked fine given the end of output:
Using LightGBM via the OS command line is fine, but I much prefer use it from Python as I can leverage other tools in that environment. Fortunately, ArdalanM already provides a Python wrapper for LightGBM on github: http
Let's follow the installation instructions. We just installed latest LightGBM release. Next is to install the Python package via the following.
This will install it in the default Python environment. I am using Anaconda with Python 3.5. You may experience something different with a different Python version or different Python distribution.
Installation went fine. Let's try it in a Python script , adapted from Ardalan's example as I am not using the same scikit-learn version as him:
Execution went fine, output ending with:
Seems we are good to go!
I hope the above will help readers. I welcome comments about issues or installation with another Python environment.