首页 > 解决方案 > 目标标签中的缺失值

问题描述

我想在我的具有类不平衡的数据中填充目标列/因变量 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]]

标签: pythondata-sciencemissing-data

解决方案


只需建立一个基于其他特征的模型来预测它。这应该保持你的分布。并且由于您的缺失数据是分类数据,因此使用均值或中位数没有意义。即使它是数字,我仍然建议不要这样做,因为使用平均值或中位数会使分布的方差更小,从而改变分布。

此外,如果您构建基于树的模型,它将能够处理丢失的数据。决策树、随机森林、gbdt。请参阅 lightgbm、xgboost 包。


推荐阅读