【问题标题】:Spark Multi-class classification -Categorical VariablesSpark 多类分类 - 分类变量
【发布时间】:2016-03-03 16:07:32
【问题描述】:

我有一个数据集作为 csv 文件。它有大约 50 列,其中大部分是分类的。我计划使用新的测试数据集运行 RandomForest 多类分类。

这样做的痛点是处理分类变量。处理它们的最佳方法是什么?我在 Spark 网站http://spark.apache.org/docs/latest/ml-guide.html#example-pipeline 中阅读了 Pipeline 指南,该指南从硬编码序列创建了一个 DataFrame,还具有空格分隔的字符串。这看起来非常具体,我想在他们如何使用 HashingTF 使用我拥有的 CSV 文件的功能方面实现相同的目标。

简而言之,我想实现与链接中相同的功能,但使用 CSV 文件。

有什么建议吗?

编辑: 数据 -> 50 个特征,100k 行,其中大部分是字母数字分类 我对 MLlib 很陌生,因此很难从 CSV 中为我的数据找到合适的管道。我尝试从文件中创建一个 DataFrame,但对如何对分类列进行编码感到困惑。我的疑惑如下

1. The example in the link above tokenizes the data ans uses it but I have a dataframe.
2. Also even if I try using  a StringIndexer , should I write an indexer for every column? Shouldn't there be one method which accepts multiple columns?
3. How will I get back the label from the String Indexer for showing the prediction?
5. For new test data, how will I keep consistent encoding for every column?

【问题讨论】:

    标签: scala apache-spark apache-spark-mllib categorical-data multilabel-classification


    【解决方案1】:

    我建议查看特征转换器 http://spark.apache.org/docs/ml-features.html,尤其是 StringIndexer 和 VectorAssembler。

    【讨论】:

    • 如果我使用StringIndexer,我将如何取回输出的原始标签?
    • 您有相应的 IndexToString 来检索您的原始标签。
    • :谢谢!有什么办法可以将 StingIndex 多列放在一起?
    • 查看 VectorIndexer
    猜你喜欢
    • 2015-11-08
    • 2018-11-24
    • 2016-05-06
    • 1970-01-01
    • 2021-01-11
    • 2018-02-06
    • 1970-01-01
    • 2017-01-03
    • 2017-07-16
    相关资源
    最近更新 更多