gpt4 book ai didi

python - 如何在 python 中处理缺失的 NaN 以进行机器学习

转载 作者:太空狗 更新时间:2023-10-29 20:51:48 25 4
gpt4 key购买 nike

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

我注意到删除缺失的 NAN 值并不是一件明智的事情。我通常使用 pandas 进行插值(计算均值)并填充数据,这种方法可以提高分类精度,但可能不是最好的做法。

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

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

Int64Index: 7049 entries, 0 to 7048
Data columns (total 31 columns):
left_eye_center_x 7039 non-null float64
left_eye_center_y 7039 non-null float64
right_eye_center_x 7036 non-null float64
right_eye_center_y 7036 non-null float64
left_eye_inner_corner_x 2271 non-null float64
left_eye_inner_corner_y 2271 non-null float64
left_eye_outer_corner_x 2267 non-null float64
left_eye_outer_corner_y 2267 non-null float64
right_eye_inner_corner_x 2268 non-null float64
right_eye_inner_corner_y 2268 non-null float64
right_eye_outer_corner_x 2268 non-null float64
right_eye_outer_corner_y 2268 non-null float64
left_eyebrow_inner_end_x 2270 non-null float64
left_eyebrow_inner_end_y 2270 non-null float64
left_eyebrow_outer_end_x 2225 non-null float64
left_eyebrow_outer_end_y 2225 non-null float64
right_eyebrow_inner_end_x 2270 non-null float64
right_eyebrow_inner_end_y 2270 non-null float64
right_eyebrow_outer_end_x 2236 non-null float64
right_eyebrow_outer_end_y 2236 non-null float64
nose_tip_x 7049 non-null float64
nose_tip_y 7049 non-null float64
mouth_left_corner_x 2269 non-null float64
mouth_left_corner_y 2269 non-null float64
mouth_right_corner_x 2270 non-null float64
mouth_right_corner_y 2270 non-null float64
mouth_center_top_lip_x 2275 non-null float64
mouth_center_top_lip_y 2275 non-null float64
mouth_center_bottom_lip_x 7016 non-null float64
mouth_center_bottom_lip_y 7016 non-null float64
Image 7049 non-null object

最佳答案

What is the best way to handle missing values in data set?

没有最好的方法,每个解决方案/算法都有自己的优点和缺点(您甚至可以将其中一些混合在一起以创建您自己的策略并调整相关参数以得出最能满足您数据的方法,有许多关于这个主题的研究/论文)。

例如,Mean Imputation 快速简单,但会低估方差,用平均值代替 NaN 会扭曲分布形状,而 KNN Imputation就时间复杂度而言,在大型数据集中可能并不理想,因为它遍历所有数据点并对每个 NaN 值执行计算,并且假设 NaN 属性与其他属性相关。

How to handle missing values in datasets before applying machine learning algorithm??

除了您提到的均值插补之外,您还可以查看K-最近邻插补回归插补,并引用给强大的Imputerscikit-learn 中上课检查要使用的现有 API。

KNN 插补

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

回归插补

回归模型被估计为基于其他变量预测变量的观察值,然后该模型用于在该变量缺失的情况下估算值。

Here链接到 scikit 的“缺失值的插补” 部分。我也听说过Orange插补库,但还没有机会使用它。

关于python - 如何在 python 中处理缺失的 NaN 以进行机器学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27824954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com