Spark Multi-class classification - 分类变量

Spark Multi-class classification -Categorical Variables

我有一个数据集作为 csv 文件。它有大约 50 列,其中大部分是分类的。我计划 运行 一个 RandomForest multi class classification with a new test data-set.

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

简而言之,我想实现与 link 中相同的效果,但使用的是 CSV 文件。

有什么建议吗?

编辑: 数据 -> 50 个特征,10 万行,其中大部分是字母数字分类 我是 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?

我建议看一下功能转换器 http://spark.apache.org/docs/ml-features.html,尤其是 StringIndexer 和 VectorAssembler。