gpt4 book ai didi

gpu - 带 gpu 的 Lightgbm 分类器

转载 作者:行者123 更新时间:2023-12-03 22:00:07 24 4
gpt4 key购买 nike

model = lgbm.LGBMClassifier(n_estimators=1250, num_leaves=128,learning_rate=0.009,verbose=1)`enter code here`

使用 LGBM 分类器
这几天有没有办法在 gpu 上使用它?

最佳答案

首先,您需要为 GPU 构建 LightGBM,例如:

git clone --recursive https://github.com/Microsoft/LightGBM 
cd LightGBM && mkdir build && cd build
cmake -DUSE_GPU=1 ..
make -j4
pip uninstall lightgbm
cd ../python-package/ && python setup.py install

之后您可以使用 device="gpu"在 params 中在 GPU 上训练您的模型,例如:
lgbm.train(params={'device'='gpu'}, ...)

或者
lgbm.LGBMClassifier(device='gpu')

较大数据集的时差:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import lightgbm as lgbm
X,y = make_classification(n_samples=10000000, n_features=100, n_classes=2)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
%%timeit
model = lgbm.LGBMClassifier(device="gpu")
model.fit(X_train, y_train)
19.9 s ± 163 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%%timeit
model = lgbm.LGBMClassifier(device="cpu")
model.fit(X_train, y_train)
1min 23s ± 46.4 s per loop (mean ± std. dev. of 7 runs, 1 loop each)

关于gpu - 带 gpu 的 Lightgbm 分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60360750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com