python下载安装教程mac-教程|如何在mac上为Python安装XGBoost!

原标题:教程|如何在mac上为Python安装XGBoost!

摘要:XGBoost是一个开发非常快速和准确的梯度增强模型的库,它在Kaggle数据科学竞赛中被大量的kaggle选手选用,其中包括两个以上kaggle比赛的夺冠方案。在本教程中,你将了解如何在macOS上为Python安装XGBoost库。

e85a0fd0193e4f14a5d092252c046c36.jpeg

教程概述

本教程分为以下3个部分:

1.安装MacPorts;

2.构建XGBoost;

3.安装XGBoost。

注意:我在一系列不同的macOS版本上都是使用这个过程。本教程是在macOS High Sierra(10.13.1)上编写和测试的。

安装MacPorts

你需要安装GCC和Python环境,以便为Python构建和安装XGBoost。

我推荐GCC 7和Python 3.6,我建议使用MacPorts安装这些软件。

1.有关逐步安装MacPorts和Python环境的帮助,请参阅本教程:

如何在Mac OS X上安装Python 3环境以进行机器学习和深度学习

2.安装MacPorts和一个可用的Python环境之后,可以按如下方式安装GCC 7:

sudo port install gcc7sudo port select --set gcc mp-gcc7

3.通过查看GCC版本来确定GCC是否安装成功,如下所示:

gcc -v

你应该看到GCC的版本打印; 例如:

gcc version 7.2.0(MacPorts gcc7 7.2.0_0)

构建XGBoost

下一步是为你的系统下载和编译XGBoost。

1.首先,从GitHub下载代码库:

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

2.更改到xgboost目录:

cd xgboost/

3.从下载的make目录里面复制用来编译XGBoost的配置文件:

cp make/config.mk ./config.mk

4.编译XGBoost; 携带你指定系统上的核心数(例如8,根据需要更改):

make -j8

构建过程可能需要一分钟,如果编译正常则不会产生任何错误消息,虽然可能会看到一些警告,但是这些警告可以忽略。

例如,编译的最后一个片段可能如下所示:

a - build/learner.oa - build/logging.oa - build/c_api/c_api.oa - build/c_api/c_api_error.oa - build/common/common.oa - build/common/hist_util.oa - build/data/data.oa - build/data/simple_csr_source.oa - build/data/simple_dmatrix.oa - build/data/sparse_page_dmatrix.oa - build/data/sparse_page_raw_format.oa - build/data/sparse_page_source.oa - build/data/sparse_page_writer.oa - build/gbm/gblinear.oa - build/gbm/gbm.oa - build/gbm/gbtree.oa - build/metric/elementwise_metric.oa - build/metric/metric.oa - build/metric/multiclass_metric.oa - build/metric/rank_metric.oa - build/objective/multiclass_obj.oa - build/objective/objective.oa - build/objective/rank_obj.oa - build/objective/regression_obj.oa - build/predictor/cpu_predictor.oa - build/predictor/predictor.oa - build/tree/tree_model.oa - build/tree/tree_updater.oa - build/tree/updater_colmaker.oa - build/tree/updater_fast_hist.oa - build/tree/updater_histmaker.oa - build/tree/updater_prune.oa - build/tree/updater_refresh.oa - build/tree/updater_skmaker.oa - build/tree/updater_sync.oc++ -std=c++ 11-Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/ include-Irabit/ include-I/ include-O3 -funroll-loops -msse2 -fPIC -fopenmp -o xgboost build/cli_main.o build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/common/hist_util.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/predictor/cpu_predictor.o build/predictor/predictor.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_fast_hist.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a -pthread -lm -fopenmp

安装XGBoost

现在准备在你的系统上安装XGBoost。

1.将目录切换到xgboost项目的Python包中:

cd python-package

2.安装Python XGBoost包:

sudo python setup.py install

安装非常快,在安装结束时,你可能会看到以下消息:

Installed /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.eggProcessing dependencies for xgboost==0.6Searching for scipy==1.0.0Best match: scipy 1.0.0Adding scipy 1.0.0 to easy-install.pth fileUsing/opt/ local/ Library/Frameworks/Python.framework/ Versions/ 3.6/lib/python3 .6/site-packagesSearching fornumpy== 1.13.3Best match: numpy 1.13.3Adding numpy 1.13.3toeasy-install.pth fileUsing/opt/ local/ Library/Frameworks/Python.framework/ Versions/ 3.6/lib/python3 .6/site-packagesFinished processing dependencies forxgboost== 0.6

3.通过打印xgboost版本来确认安装是否成功:

将以下代码保存到名为version.py的文件中:

importxgboostprint( "xgboost", xgboost.__version__)

从命令行运行脚本:

python version.py

如果看到XGBoost版本打印到屏幕上,则说明安装成功:

xgboost 0.6

原文:https://machinelearningmastery.com/install-xgboost-python-macos/?spm=a2c4e.11153959.blogcont460393.10.2096234ee2ZFp8

抓住AI时代机遇,从学习开始:返回搜狐,查看更多

责任编辑:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值