我有一个简单的 lgbm 数据集:
import lightgbm as lgbm
dataset = lgbm.Dataset(data=X, label=y, feature_name=X.columns.tolist())
其中X是 pandas df,y是 pandas 系列。我想在我的自定义目标函数中访问X的特定列。但是当我尝试时:
data = dataset.get_field('data')
我收到此错误消息:
Traceback (most recent call last):
File "<ipython-input-71-34d27860b9e3>", line 1, in <module>
data = dataset.get_field('data')
File "/Users/***/anaconda3/envs/py3k/lib/python3.6/site-packages/lightgbm/basic.py", line 1007, in get_field
ctypes.byref(out_type)))
File "/Users/***/anaconda3/envs/py3k/lib/python3.6/site-packages/lightgbm/basic.py", line 48, in _safe_call
raise LightGBMError(_LIB.LGBM_GetLastError())
LightGBMError: b'Field not found'
而这运作良好:
y = dataset.get_field('label')
谢谢!