installing xgboost on windows

How to install Xgboost on Windows using Anaconda

Xgboost is one of the most effective algorithms for machine learning competitions these days. The only problem in using this in Python, there is no pip builder available for this. So when I tried using pip builder I got this error.

Its installation on windows is not straightforward and might seem daunting at first. Also, if you are using anaconda environment then there are few specific steps which you need to take for installing Xgboost package.

I have recently installed Xgboost and am sharing the codes and steps which worked for me.

Required Software for installing xgboost
  • Anaconda environment
  • Git Bash
  • MINGW

You can install Git from here

Start Git Bash and type following commands:

  1. cd /c/Xgboost/Xgboost_install” – This will point to the directory where we will download Xgboost files. If this folder is not there, then you can manually create it.
  2. git clone –recursive https://github.com/dmlc/xgboost” – This will clone git hub folder into your local folder.
  3. cd Xgboost
  4. git submodule init
  5. git submodule update

This will initialize your local configuration file, and fetch all the data from that project and check out the appropriate commit listed in the super project.

Now we have got required Xgboost files on our system. Next step will be to build it on our machine. For this, you can download compiler from here.

If it asks for permission, then give it. And click next

In the next installation screen, select X86_64 option.

It will install this in program files and path for it will be like: –

C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin

We will need to add this path to the system variable. You can check instructions for adding it to the system variable here.

After adding above mentioned path to the system variables, restart GIT Bash terminal so that the new path is added. Just to check whether it has been done correctly or not, you can type “which mingw32-make” in the Git Bash and if it is correct, it will return “C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin /mingw32-make”

Now we are almost there.

We will build Xgboost on our system next.

In your Git Bash go to the directory where Xgboost was cloned i.e. C:\Xgboost_install\Xgboost and type below commands: –

  • cd dmlc-core
  • mingw32-make –j4
  • cd ../rabit
  • mingw32-make lib/librabit_empty.a –j4
  • cd ..
  • cp mingw32-make/mingw64.mk config.mk
  • mingw32-make –j4

Now the build is completed but we will need to add it to our anaconda environment.

Start anaconda prompt and go to the directory “Xgboost\python-package”. Here you will get your prompt “C:\Xgboost_install\Xgboost\python-package>”

Type “python setup.py install

Restart anaconda and launch your jupyter notebook and add this path before importing Xgboost.

Now it is done and you can use Xgboost package in anaconda environment.