lightgbm 错误:ValueError: Unknown label type: 'continuous'

之前在做阿里广告预测比赛,处理了半天,发现在使用 cv 方法验证模型,并使用lightgbm训练时候的发现了一个很奇怪的报错。

ValueError: Unknown label type: 'continuous'

What ??黑人问号脸??

百思不得其解。这是什么意思。百度无果,于是自己分析判断一下。

在我把全部数据的”instance_id”去重之后,这个问题消失了。

df.drop_duplicates('instance_id','first',True)

这是什么原因?? 于是我再往下看,下面我针对这个”instance_id”又做了一个“item_city_id”的one-hot处理,又用“instance_id”合并。

ont_hot_features = ['item_city_id']
ont_hot_list = df.loc[:,ont_hot_features + ['instance_id']]
ont_hot_list.loc[:,ont_hot_features] = ont_hot_list.loc[:,ont_hot_features].astype('str')
ont_hot_list = pd.get_dummies(ont_hot_list)
df = pd.merge(df,ont_hot_list,on='instance_id')

问题出现在merge这个函数和“instance_id”这个字段身上。

由于数据原因,instance_id 这个本该全局唯一的值在测试数据集和训练集上都有重复出现。所以在merge的时候,就算你指定了采用‘left’方式合并也会有笛卡尔积的重复。

所以我修改了下代码:

需要ont-hot处理

    ont_hot_features = ['item_city_id']
    ont_hot_list = df.loc[:,ont_hot_features + ['instance_id']]
    ont_hot_list.drop_duplicates('instance_id','first',True)
    ont_hot_list.loc[:,ont_hot_features] = ont_hot_list.loc[:,ont_hot_features].astype('str')
    ont_hot_list = pd.get_dummies(ont_hot_list)
    df = pd.merge(df,ont_hot_list,'left',on='instance_id')

先对“instance_id”进行去重,再进行左边Join。这样便不会出现笛卡尔乘积的情况。

至于为什么 lightgbm 训练的时候会对这个情况报错,需要我再进一步研究。

转自:https://blog.csdn.net/u010379324/article/details/79624795

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值