python - 目标标签中的缺失值
问题描述
我想在我的具有类不平衡的数据中填充目标列/因变量 Complaint-Status 中存在的缺失值 (18543)。目标列中有五个类(多类分类问题)。
在不增加类不平衡的情况下填充这些值的最佳方法是什么?
数据集
将这些缺失值替换为列模式,即“以解释关闭”,只会增加类不平衡。
uniq, kounts = np.unique(df_ohe['Complaint-Status'], return_counts=True)
print(np.asarray((uniq, kounts)).T)
[['' 18543]
['Closed' 809]
['Closed with explanation' 34300]
['Closed with monetary relief' 2818]
['Closed with non-monetary relief' 5018]
['Untimely response' 321]]
目标班级百分比
100*c_count.values/c_count.values.sum()
# array([55.49353654, 30.00048537, 8.11855879, 4.55920659, 1.30887088,
0.51934184])
预期输出:
[['class_label', 18543]
['Closed' 809]
['Closed with explanation' 34300]
['Closed with monetary relief' 2818]
['Closed with non-monetary relief' 5018]
['Untimely response' 321]]
解决方案
只需建立一个基于其他特征的模型来预测它。这应该保持你的分布。并且由于您的缺失数据是分类数据,因此使用均值或中位数没有意义。即使它是数字,我仍然建议不要这样做,因为使用平均值或中位数会使分布的方差更小,从而改变分布。
此外,如果您构建基于树的模型,它将能够处理丢失的数据。决策树、随机森林、gbdt。请参阅 lightgbm、xgboost 包。
推荐阅读
- android - 片段未从另一个片段启动
- typescript - RXJS / Angular 6:将多个请求反跳/分组为一个超时
- xcode - 如何在 Xcode Playground 中使用 C 模块映射?
- python - 使用 discord.py 欢迎/再见
- vba - 带有 RC 表示法和 vlookup 的 activecell.formula 无法正常工作 vba
- amazon-web-services - AWS API GATEWAY 配置从 lambda 返回二进制 pdf 文件
- php - 无法为新的自定义帖子类型注册分类
- node.js - 从本地应用程序以快递方式接收 webhook
- python - 将列表从海量字典转换为数据框的问题
- python - 清除事件不会停止其他线程