1

以下代码会引发错误,提示“意外的关键字arguemnt 'max_bin'”。后来我发现'max_bin' 已贬值。那么如何使用'params'传递max_bin?谁能给我看一段示例代码?

lgb.Dataset(x_train, lable=y, max_bin=56)

/anaconda3/lib/python3.6/site-packages/lightgbm/basic.py:648: LGBMDeprecationWarning: max_bin 参数已弃用,将在 2.0.12 版本中删除。请使用 params 传递此参数。'请使用 params 传递此参数。', LGBMDeprecationWarning)

4

2 回答 2

2

错误消息中params提到的参数是指传递给train()函数的参数。如果您使用 python API 的 sklearn 类,则某些参数也可用作分类器__init__()方法中的关键字参数。

例子:

import lightgbm as lgb
import numpy as np

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

iris = datasets.load_iris()

X_train, X_test, y_train, y_test = train_test_split(iris.data,
                                                    iris.target,
                                                    test_size=0.2)
lgb_train = lgb.Dataset(X_train, y_train)

# here are the parameters you need
params = {
    'task': 'train',
    'boosting_type': 'gbdt',
    'objective': 'multiclass',
    'num_class': 3,
    'max_bin': 4  # <-- max_bin
}

gbm = lgb.train(params,
                lgb_train,
                num_boost_round=20)

y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration)
y_pred = np.argmax(y_pred, axis=1)
print("Accuracy: ", accuracy_score(y_test, y_pred))

对于详细的示例,我建议查看LGBM 附带的python 示例。

于 2018-01-30T15:51:50.637 回答
0

max_bin在字典中设置params,然后将其传递给lgb.Dataset构造函数。请注意,在官方文档max_bin中指定为 Dataset 参数。

import lightgbm as lgb

lgb.Dataset(x_train, label=y_train, params={"max_bin": 63})
于 2021-02-20T11:53:46.363 回答