Wednesday, February 15, 2017

Conda create environment commands


Conda create environment commands - super easy but nice to have as a reference:

# Python 2.7
$ conda create -n myenvname python=2.7 # Python 3.4 $ conda create -n myenvname python=3.4 # Python 3.x latest $ conda create -n myenvname python=3

$ source activate myenvname

More info: https://conda.io/docs/using/envs.html

If you then have a requirements.txt file, you can install the listed packages with:
conda install --yes --file requirements.txt

If you want to reproduce an existing conda environment on another machine, you can get a snapshot with:
conda env export > freeze.yml

which can then be restored via:
conda env create -f freeze.yml

Saturday, February 11, 2017

Install xgboost on OSX with full OpenMP support in an anaconda virtualenv

The default gcc with OSX doesn't support OpenMP which enables xgboost to utilise multiple cores when training.

These steps show how to install gcc-6 with OpenMP support and build xgboost to support multiple cores and contain the python setup in an Anaconda virtualenv.

Install/update brew to support installing gcc-6:
See http://brew.sh/

Install gcc-6 with OpenMP support:
brew install gcc --without-multilib
Run brew doctor to ensure gcc-6 and g++-6 are linked correctly

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

Build xgboost with gcc-6:
See https://xgboost.readthedocs.io/en/latest/build.html
cd xgboost; cp make/config.mk ./config.mk;
Ensure that the newly installed gcc-6 compliers are correct in config.mk (e.g. export CC = gcc-6; export CXX = g++-6)
make -j4
(This can take around 30 mins to build)

Create anaconda xgboost virtualenv:
conda create -n xgboost python=3.5
source activate xgboost

Install prerequisite numpy package in xgboost env:
conda install numpy

Set up xgboost for python xgboost virtualenv without sudo:
Ensure you are in the xgboost virtualenv (e.g. which python -> /Users/<user>/anaconda/envs/xgboost/bin/python)
cd <git_clone_location>/xgboost/python-package
python setup.py install
(This can take around 10 mins)

Test xgboost:
open a python session
Try import xgboost as xgb

Finally, set up Jupyter notebook:
If you want to access xgboost via Kernel > Change Kernel in Jupyter:
conda install jupyter

Helpful reference:
https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_on_Mac_OSX?lang=en