Python导入LightGBM出现错误

6

我已按照这里的方式在Linux上安装了lightGBM。

我能够成功地使用CLI运行GPU训练(和CPU):

https://github.com/Microsoft/LightGBM/blob/master/docs/GPU-Tutorial.md#run-your-first-learning-task-on-gpu

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

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

我对链接和其他可能引起问题的事情还不是很了解。有人能提供一些易于理解的建议吗?


你正在使用哪个Python包? - Nick M
2个回答

1

LightGBM现在带有Python API

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接口可能只有几个步骤之遥。
假设构建成功,并且仓库看起来像这样:
~/Codes/LightGBM$ tree -d -L 1
.
├── build
├── compute
├── docker
├── docs
├── examples
├── helpers
├── include
├── pmml
├── python-package
├── R-package
├── src
├── swig
├── tests
└── windows

只需使用以下命令设置Python API。

cd python-package/
sudo python setup.py install --precompile

这是一份详细的指南,介绍如何安装支持GPU的LightGBM


0

要在Python中使用LGBM,您需要安装一个用于CLI的Python包装器。也许像this.这样的东西。然后,您需要将此包装器指向CLI。您可以查找GBMClassifier / Regressor,在其中有一个名为exec_path的变量。在这里设置绝对路径。

希望这可以帮助, 我将举一个例子this wrapper 这是一个例子:`

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))

`


我已经添加了Python包装器。我想知道你是否有一个带有exec_path的示例?那样能解决错误吗? - B_Miner
@B_Miner 当然,我会在答案中添加它。 - Nick M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接