首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python导入LightGBM出错

Python导入LightGBM出错
EN

Stack Overflow用户
提问于 2017-05-21 22:33:03
回答 2查看 1.7K关注 0票数 6

我已经在Linux上安装了lightGBM,如下所示:

https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#linux-2

我能够使用CLI成功地运行图形处理器培训(和CPU):https://github.com/Microsoft/LightGBM/blob/master/docs/GPU-Tutorial.md#run-your-first-learning-task-on-gpu

但是,当我尝试导入python包(python 3.6)时,收到以下错误:

代码语言:javascript
复制
OSError: /home/anaconda3/lib/python3.6/site-packages/lightgbm-0.2-py3.6.egg/lightgbm/lib_lightgbm.so: symbol clCreateCommandQueueWithProperties, version OPENCL_2.0 not defined in file libOpenCL.so.1 with link time reference

我对链接和其他可能存在问题的东西的理解还很陌生。有没有人能提供一些容易遵循的建议?

EN

回答 2

Stack Overflow用户

发布于 2020-04-30 16:15:04

LightGBM现在提供了一个python API

代码语言:javascript
复制
import numpy as np
from lightgbm import LGBMClassifier
from sklearn.datasets import make_moons


model = LGBMClassifier(boosting_type='goss', num_leaves=31, max_depth=- 1, learning_rate=0.1, n_estimators=300, device = "gpu")

train, label = make_moons(n_samples=300000, shuffle=True, noise=0.3, random_state=None)

model.fit(train, label)

如果您设法为GPU构建了它,那么设置python接口可能需要几个步骤。

假设构建是成功的,并且库如下所示:

代码语言:javascript
复制
~/Codes/LightGBM$ tree -d -L 1
.
├── build
├── compute
├── docker
├── docs
├── examples
├── helpers
├── include
├── pmml
├── python-package
├── R-package
├── src
├── swig
├── tests
└── windows

只需使用以下命令设置python API即可。

代码语言:javascript
复制
cd python-package/
sudo python setup.py install --precompile

install LightGBM with GPU support的源代码详细指南

票数 1
EN

Stack Overflow用户

发布于 2017-06-13 16:08:48

要在python中使用LGBM,您需要为CLI安装一个python包装器。也许是像this.这样的东西,然后你需要把这个包装器指向命令行界面。您可以查找You分类器/正则表达式,其中有一个名为exec_path的变量。你应该在这里设置绝对路径。

希望这能有所帮助,我将以this wrapper为例,下面是示例:

代码语言:javascript
复制
import numpy as np
from sklearn import datasets, metrics, model_selection
from pylightgbm.models import GBMClassifier
exec = "~/Documents/apps/LightGBM/lightgbm"
X, Y = datasets.make_classification(n_samples=200, n_features=10)
x_train, x_test, y_train, y_test = model_selection.train_test_split(X, Y, test_size=0.2)
clf = GBMClassifier(exec_path=exec, min_data_in_leaf=1)
clf.fit(x_train, y_train, test_data=[(x_test, y_test)])
y_pred = clf.predict(x_test)
print("Accuracy: ", metrics.accuracy_score(y_test, y_pred))

`

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44098077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档