How to Install XGBoost and LightGBM on MacOS?
Last Updated :
18 Oct, 2021
In this article, we will learn how to install XGBoost and LightGBM in Python on macOS. XGBoost is an open-source software library that provides a regularizing gradient boosting framework for C++, Java, Python, R, Julia, Perl, and Scala.
LightGBM, short for Light Gradient Boosting Machine, is a free and open-source distributed gradient boosting framework for machine learning originally developed by Microsoft.
Installation for XGBoost:
Method 1: Using pip to install XGBoost
Follow the below steps to install the XGBoost package on macOS using pip:
Step 1: Install the latest Python3 in MacOS
Step 2: Check if pip3 and python3 are correctly installed.
python3 --version
pip3 --version
Step 3: Upgrade your pip to avoid errors during installation.
pip3 install --upgrade pip
Step 4: Enter the following command to install XGBoost using pip3.
pip3 install xgboost
Method 2: Using setup.py to install XGBoost (Recommended)
Follow the below steps to install the XGBoost package on macOS using the setup.py file:
Step 1: Download the latest source package of XGBoost for python3 from here.
curl https://files.pythonhosted.org/packages/cb/15/5a0e2977c2dca5dc374e6ba490674d7807d75e220b9bf2028d83a296d50f/xgboost-1.4.2.tar.gz > XGboost.tar.gz
Step 2: Extract the downloaded package using the following command.
tar -xzvf XGboost.tar.gz
Step 3: Go inside the folder and Enter the following command to install the package.
Note: Install cmake using pip3 before using setup.py to install xgboost
pip3 install cmake
Note: You must have developer tools for XCode MacOS installed in your system
cd xgboost-1.4.2
python3 setup.py install
Verifying XGBoost installation on macOS:
Make the following import in your python terminal to verify if the installation has been done properly:
import xgboost
If there is any error while importing the module then is not installed properly.
Installation for LightGBM:
Method 1: Using pip to install LightGBM
Follow the below steps to install the LightGBM package on macOS using pip:
Step 1: Install the latest Python3 in MacOS
Step 2: Check if pip3 and python3 are correctly installed.
python3 --version
pip3 --version
Step 3: Upgrade your pip to avoid errors during installation.
pip3 install --upgrade pip
Step 4: Enter the following command to install LightGBM using pip3.
pip3 install lightgbm
Method 2: Using setup.py to install LightGBM (Recommended)
Follow the below steps to install the LightGBM package on macOS using the setup.py file:
Step 1: Download the latest source package of LightGBM for python3 from here.
curl https://files.pythonhosted.org/packages/7a/6d/db0f5effd3f7982632111f37fcd2fa386b8407f1ff58ef30b71d65e1a444/lightgbm-3.2.1.tar.gz > LightGBM.tar.gz
Step 2: Extract the downloaded package using the following command.
tar -xzvf LightGBM.tar.gz
Step 3: Go inside the folder and Enter the following command to install the package.
Note: Install cmake, gcc, libomp using homebrew before using setup.py to install lightgbm
brew install cmake
brew install gcc
brew install libomp
Note: You must have developer tools for XCode MacOS installed in your system
cd lightgbm-3.2.1
python3 setup.py install
Verifying LightGBM installation on macOS:
Make the following import in your python terminal to verify if the installation has been done properly:
import lightgbm
If there is any error while importing the module then is not installed properly.
Share your thoughts in the comments
Please Login to comment...