如何处理Python机器学习中的缺失NaN值

在应用机器学习算法之前,如何处理数据集中的缺失值?

我注意到,直接删除缺失的NaN值并不是一个明智的做法。我通常使用pandas进行插值(计算平均值)来填补数据,这种方法在一定程度上有效,并能提高分类准确性,但可能不是最佳方法。

这里有一个非常重要的问题。处理数据集中的缺失值的最佳方法是什么?

例如,如果你看到这个数据集,只有30%的数据是原始数据。

Int64Index: 7049 entries, 0 to 7048Data columns (total 31 columns):left_eye_center_x            7039 non-null float64left_eye_center_y            7039 non-null float64right_eye_center_x           7036 non-null float64right_eye_center_y           7036 non-null float64left_eye_inner_corner_x      2271 non-null float64left_eye_inner_corner_y      2271 non-null float64left_eye_outer_corner_x      2267 non-null float64left_eye_outer_corner_y      2267 non-null float64right_eye_inner_corner_x     2268 non-null float64right_eye_inner_corner_y     2268 non-null float64right_eye_outer_corner_x     2268 non-null float64right_eye_outer_corner_y     2268 non-null float64left_eyebrow_inner_end_x     2270 non-null float64left_eyebrow_inner_end_y     2270 non-null float64left_eyebrow_outer_end_x     2225 non-null float64left_eyebrow_outer_end_y     2225 non-null float64right_eyebrow_inner_end_x    2270 non-null float64right_eyebrow_inner_end_y    2270 non-null float64right_eyebrow_outer_end_x    2236 non-null float64right_eyebrow_outer_end_y    2236 non-null float64nose_tip_x                   7049 non-null float64nose_tip_y                   7049 non-null float64mouth_left_corner_x          2269 non-null float64mouth_left_corner_y          2269 non-null float64mouth_right_corner_x         2270 non-null float64mouth_right_corner_y         2270 non-null float64mouth_center_top_lip_x       2275 non-null float64mouth_center_top_lip_y       2275 non-null float64mouth_center_bottom_lip_x    7016 non-null float64mouth_center_bottom_lip_y    7016 non-null float64Image                        7049 non-null object

回答:

处理数据集中的缺失值的最佳方法是什么?

没有所谓的最佳方法,每种解决方案/算法都有其优缺点(你甚至可以将它们混合使用,创建自己的策略,并调整相关参数以找到最适合你的数据的方法,关于这个话题有很多研究/论文)。

例如,均值填补快速简单,但它会低估方差,并且通过用均值替换NaN会扭曲分布形状,而KNN填补在处理大型数据集时可能在时间复杂度上不是理想的选择,因为它需要遍历所有数据点并为每个NaN值进行计算,并且假设NaN属性与其他属性相关。

在应用机器学习算法之前,如何处理数据集中的缺失值?

除了你提到的均值填补,你还可以考虑K-最近邻填补回归填补,并参考Imputer类在scikit-learn中的现有API来使用。

KNN填补

计算这个NaN点的k个最近邻的平均值。

回归填补

估计一个回归模型来预测一个变量的观测值基于其他变量,然后使用该模型来填补该变量缺失的情况。

这里链接到scikit的’缺失值填补‘部分。我还听说过Orange库用于填补,但还没有机会使用它。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注