macOS安装lightgbm排坑

作者: 路人乙yh | 来源:发表于2019-07-04 15:18 被阅读0次

第一步:安装brew(如果电脑已经有brew可略过)
在终端输入:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

第二步:用brew 安装cmake

brew install cmake
brew install gcc --without-multilib 

第三步:配置

export CXX=g++-7 CC=gcc-7  
cmake ..  
make -j4

在这一步出错Could not find compiler set in environment variable CC: gcc-7,查网上的解决办法都是改为export CXX=g++-8 CC=gcc-8,试了还是不行,思考可能是gcc版本没对上,想重装gcc,brew install gcc,弹出Warning: gcc 9.1.0 is already installed and up-to-date,于是改为export CXX=g++-9 CC=gcc-9,成功。

第四步:安装
切换到LightGBM/python-package, 输入python setup.py install

第五步:测试

import lightgbm as lgb

print(lgb.__version__)

data = np.random.rand(500, 10)  # 500 entities, each contains 10 features
label = np.random.randint(2, size=500)  # binary target

train_data = lgb.Dataset(data, label=label)
param = {'num_leaves': 31, 'objective': 'binary'}
param['metric'] = 'auc'
num_round = 10
bst = lgb.train(param, train_data, num_round)

# 预测
data = np.random.rand(7, 10)
ypred = bst.predict(data)
print(y_pred)

相关文章

网友评论

    本文标题:macOS安装lightgbm排坑

    本文链接:https://www.haomeiwen.com/subject/gfnlhctx.html