【发布时间】:2016-04-07 17:21:50
【问题描述】:
像这样训练了一个 RandomForest (Spark 1.6.0)
val numClasses = 4 // 0-2
val categoricalFeaturesInfo = Map[Int, Int]()
val numTrees = 9
val featureSubsetStrategy = "auto" // Let the algorithm choose.
val impurity = "gini"
val maxDepth = 6
val maxBins = 32
val model = RandomForest.trainClassifier(trainRDD, numClasses,
categoricalFeaturesInfo, numTrees,
featureSubsetStrategy, impurity,
maxDepth, maxBins)
输入标签:
labels = labeledRDD.map(lambda lp: lp.label).distinct().collect()
for label in sorted(labels):
print label
0.0
1.0
2.0
但输出只包含两个类:
metrics = MulticlassMetrics(labelsAndPredictions)
df_confusion = metrics.confusionMatrix()
display_cm(df_confusion)
输出:
83017.0 81.0 0.0
8703.0 2609.0 0.0
10232.0 255.0 0.0
当我在 pyspark 中加载相同模型并针对其他数据运行它时的输出(以上部分)
DenseMatrix([[ 1.75280000e+04, 3.26000000e+02],
[ 3.00000000e+00, 1.27400000e+03]])
【问题讨论】:
-
我无法重现这一点,或者至少我得到的混淆矩阵没有任何问题。而你实际上有 3 个类 :)
-
@zero323 我保存了它并在中间加载了它。可能是这样。你能发布你的复制品
-
我基本上复制了文档中的示例,用
data.map{case LabeledPoint(i, v) => if (i == 0.0) LabeledPoint(2.0, v) else LabeledPoint(3.0, v) } ++ data替换数据 -
从 scala 我可以确定 2.0 类始终为 0,使用 pyspark 我得到了上面的密集矩阵(没有第三列)@zero323
-
能否为 Python 和 Scala 提供一些 minimal reproducible examples?
标签: apache-spark