(原创)lightgbm 一些错误情况处理
Posted tech-engin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(原创)lightgbm 一些错误情况处理相关的知识,希望对你有一定的参考价值。
1、做多分类问题时候(mutticlass),如果遇到
lightgbm.basic.LightGBMError: b‘Number of classes should be specified and greater than 1 for multiclass training‘
需要在params里面添加num_class参数项
import lightgbm as lgb from sklearn import datasets from sklearn.model_selection import train_test_split iris=datasets.load_iris() X_train,X_test,y_train,y_test=train_test_split(iris.data,iris.target,test_size=0.3) import numpy as np train_data=lgb.Dataset(X_train,label=y_train) validation_data=lgb.Dataset(X_test,label=y_test) params={ ‘learning_rate‘:0.1, ‘lambda_l1‘:0.1, ‘lambda_l2‘:0.2, ‘max_depth‘:4, ‘objective‘:‘multiclass‘, ‘num_class‘:3, #lightgbm.basic.LightGBMError: b‘Number of classes should be specified and greater than 1 for multiclass training‘ } clf=lgb.train(params,train_data,valid_sets=[validation_data]) from sklearn.metrics import roc_auc_score,accuracy_score y_pred=clf.predict(X_test) y_pred=[list(x).index(max(x)) for x in y_pred] print(y_pred) print(accuracy_score(y_test,y_pred))
以上是关于(原创)lightgbm 一些错误情况处理的主要内容,如果未能解决你的问题,请参考以下文章