gpt4 book ai didi

python - 如何在 LightGBM 中设置 max_bin 参数

转载 作者:行者123 更新时间:2023-12-01 02:14:32 25 4
gpt4 key购买 nike

以下代码抛出错误,提示“意外的关键字 argumentmnt 'max_bin'”。后来我发现'max_bin' is depreciated 。那么如何使用“params”传递 max_bin 呢?谁能给我看一段示例代码吗?

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

/anaconda3/lib/python3.6/site-packages/lightgbm/basic.py:648: LGBMDeprecationWarning: The max_bin parameter is deprecated and will be removed in 2.0.12 version. Please use params to pass this parameter. 'Please use params to pass this parameter.', LGBMDeprecationWarning)

最佳答案

错误消息中提到的params指的是Parameters传递给 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))

有关详细示例,我建议查看 python examples LGBM 附带的。

关于python - 如何在 LightGBM 中设置 max_bin 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48448626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com