gpt4 book ai didi

python - 带有 Tweedie 的 Lightgbm

转载 作者:太空宇宙 更新时间:2023-11-04 04:50:45 25 4
gpt4 key购买 nike

我正在尝试使用 Tweedie 发行版运行 lightgbm。我相信这段代码应该足以看出问题所在:

lgb_train=lgb.Dataset(X_train,y_train,weight=W_train,categorical_feature=cat_features)
lgb_test=lgb.Dataset(X_test,y_test,weight=W_test,reference=lgb_train,categorical_feature=cat_features)

params = {
'boosting': 'gbdt',
'application': 'tweedie',
'metric': 'tweedie',
'tweedie_variance_power':1.5,
'num_leaves': 31,
'learning_rate': 0.05,
'feature_fraction': 1,
'bagging_fraction': 1,
'bagging_freq': 0,
'verbose': 1,
'early_stopping_round':5,
'num_iterations':1000
}

mod1=lgb.train(params,lgb_train,valid_sets=[lgb_test])

当使用应用程序和度量作为泊松时,这运行良好,但是对于 Tweedie,我得到了这个回溯:

LightGBMError: b'No object function provided'
---------------------------------------------------------------------------
LightGBMError Traceback (most recent call last)
<ipython-input-348-84061fea80fd> in <module>()
18 }
19
---> 20 mod1=lgb.train(params,lgb_train,valid_sets=[lgb_test])
C:\Python\anaconda3\lib\site-packages\lightgbm\engine.py in train(params, train_set, num_boost_round, valid_sets, valid_names, fobj, feval, init_model, feature_name, categorical_feature, early_stopping_rounds, evals_result, verbose_eval, learning_rates, keep_training_booster, callbacks)
197 evaluation_result_list=None))
198
--> 199 booster.update(fobj=fobj)
200
201 evaluation_result_list = []
C:\Python\anaconda3\lib\site-packages\lightgbm\basic.py in update(self, train_set, fobj)
1437 _safe_call(_LIB.LGBM_BoosterUpdateOneIter(
1438 self.handle,
-> 1439 ctypes.byref(is_finished)))
1440 self.__is_predicted_cur_iter = [False for _ in range_(self.__num_dataset)]
1441 return is_finished.value == 1
C:\Python\anaconda3\lib\site-packages\lightgbm\basic.py in _safe_call(ret)
46 """
47 if ret != 0:
---> 48 raise LightGBMError(_LIB.LGBM_GetLastError())
49
50
LightGBMError: b'No object function provided'

我假设我缺少一个参数,但我很确定我已经在文档中放置了所有引用 Tweedie 的内容。

请问你能帮忙吗?

干杯

最佳答案

这也让我感到困惑,但事实证明 Tweedie 支持是最近才添加的。只需重建 lightgbm 并记住还要重新安装 python 包。在 Linux 上:

git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake ..
make -j4
cd LightGBM/python-package
python setup.py install

关于python - 带有 Tweedie 的 Lightgbm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48390484/

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