在spark中使用分类特征信息和decisiontreeclassifier方法

pokxtpni  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(366)

我必须使用这个代码:

val dt = new DecisionTreeClassifier().setLabelCol("indexedLabel").setFeaturesCol("indexedFeatures").setImpurity(impurity).setMaxBins(maxBins).setMaxDepth(maxDepth);

我需要添加分类特征信息,这样决策树就不会处理 indexedCategoricalFeatures 作为数字。我有这张Map:

val categoricalFeaturesInfo = Map(143 -> 126, 144 -> 5, 145 -> 216, 146 -> 100, 147 -> 14, 148 -> 8, 149 -> 19, 150 -> 7);

但是它只适用于 DecisionTree.trainClassifier 方法。我不能使用这个方法,因为它接受的参数与我的不同。。。我真的很想使用 DecisionTreeClassifie 正确处理分类特征。
谢谢你的帮助!

70gysomp

70gysomp1#

您混合了两种不同的API,它们采用不同的方法处理分类数据: RDD 基于 o.a.s.mllib 它通过传递 categoricalFeaturesInfo Map。 Dataset ( DataFrame ) o.a.s.ml 它使用列元数据来确定变量类型。如果你正确使用 ML 创建特性的转换器应该为您自动处理,否则您必须手动提供元数据。

相关问题