1

centos7.9安装xgboost

 1 year ago
source link: https://shidawuhen.github.io/2023/01/16/centos7-9%E5%AE%89%E8%A3%85xgboost/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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方式安装最简单,pip3 install xgboost

不过该方式目前应该最高支持到1.7.3

C++源码

我们还可以通过编译xgboost的C++源码实现安装,该方式可安装各种版本,但操作也是最麻烦的。

想用centos7.9编译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

image-20220928212349934

环境配置完成后,即可开始编译,假设大家已经下载了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包已被安装。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK