我在Linux上安装了lightGBM:
https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#linux-2
我能够使用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
我很了解链接和其他可能存在问题的事情。有人能提供一些易于理解的建议吗?
答案 0 :(得分: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))
`
答案 1 :(得分:0)
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