theme: channing-cyan
XGBoost是一个优化的分布式梯度增强库,旨在实现高效,灵活和便携。
它在 Gradient Boosting 框架下实现机器学习算法。XGBoost提供并行树提升(也称为GBDT,GBM),可以快速准确地解决许多数据科学问题。相同的代码在主要的分布式环境(Hadoop,SGE,MPI)上运行,并且可以解决数十亿个示例之外的问题。
要想使用xgboost,必须先进行安装,官方网址为:https://xgboost.readthedocs.io/en/latest/build.html#building-python-package-from-source。
xgboost可以使用两种方式进行安装。
pip
使用pip方式安装最简单,pip3 install xgboost
不过该方式目前应该最高支持到1.7.3
C++源码
我们还可以通过编译xgboost的C++源码实现安装,该方式可安装各种版本,但操作也是最麻烦的。
想用centos编译C++源码,需要安装正确版本的cmake,升级gcc和g++。
yum install cmake,自动安装版本为2.8.12.2,版本太低,至少需要3.14以上。
# 删除gcc
yum remove gcc
#升级gcc g++
yum install centos-release-scl
yum install devtoolset-8-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
# 安装cmake
wget https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5.tar.gz
tar -zxvf cmake-3.15.5.tar.gz
cd cmake-3.15.5
./configure --prefix=/usr/local/cmake
make && make install
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
如果报如下问题,需要删除cmakecahe.txt、cmakefiles
环境配置完成后,即可开始编译,假设大家已经下载了C++源码xgboost-master.zip。
unzip xgboost-master.zip
cd xgboost-master/
mkdir build
cd build/
cmake ..
make -j$(nproc)
cd ../python-package
sudo python setup.py install
执行完install命令后,通过pip list | grep xgboost,便能查看到指定xgboost包已被安装。
最后
大家如果喜欢我的文章,可以关注我的公众号(程序员麻辣烫)
我的个人博客为:https://shidawuhen.github.io/
往期文章回顾: