在 spark mllib 分类器中处理 null/NaN 值 [英] Handle null/NaN values in spark mllib classifier

查看:31
本文介绍了在 spark mllib 分类器中处理 null/NaN 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组分类列(字符串),我正在解析它们并将其转换为特征向量以传递给 mllib 分类器(随机森林).

I have a set of categorical columns (strings), that I'm parsing and converting into Vectors of features to pass to a mllib classifier (random forest).

在我的输入数据中,某些列具有空值.说,在其中一列中,我有 p 值 + 一个空值:我应该如何构建我的特征向量和分类器的 categoricalFeaturesInfo 地图?

In my input data, some columns have null values. Say, in one of those columns, I have p values + a null value : How should I build my feature Vectors, and the categoricalFeaturesInfo map of the classifier ?

  • 选项 1:我在 categoricalFeaturesInfo 中告诉 p 值,并在我的输入 Vectors 中使用 Double.NaN ?
    • 附带问题:分类器如何处理 NaN?

    感谢您的帮助.

    (PS:我知道新的数据框+管道+向量索引器API,但由于某些原因它不适合我的需要,所以我需要自己做)

    (PS : I know the the new dataframe + pipeline + vectorindexer API, but for reasons it doesn't fit well my need, so I need to do that by myself)

    推荐答案

    看起来选项 2 是其中之一.如果您的 null 实际上是您的分类特征的另一个级别,只需将其映射到某个值即可.请注意,分类特征级别应映射到 0,1,2 .... 等,然后才能正确使用它们,请参见此处:

    Looks like option 2 is the one. If null for you is actually another level of your categorical feature, just map it into some value. Note that the categorical feature levels should be mapped into 0,1,2 .... etc before you can properly use them, see here:

    stackoverflow 中的响应

    因此空值将被映射到这些数字之一.

    So nulls will be mapped into one of these numbers.

    这篇关于在 spark mllib 分类器中处理 null/NaN 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆