我看到Apache Spark的MLLIB实现的随机森林分类器不支持用于培训和度量评估的错误分类成本矩阵。
问题:有没有办法在不更改MLLIB代码的情况下实现这一点?怎么样?
每棵树上的每个拆分都应考虑成本矩阵(例如C5.0 cost matrix related question)。
以下是使用MLLIB提供的[new] Random Forest分类器进行训练和预测的SCALA代码的一部分。
[...]
// Train a RandomForest model.
// Here, I would like to insert a misclassification cost matrix
val rf = new RandomForestClassifier()
.setLabelCol("indexedLabel")
.setFeaturesCol("rawFeatures")
.setNumTrees(500)
.setImpurity("gini")
.setMaxBins(500)
.setMaxDepth(30)
.setFeatureSubsetStrategy("50")
// Chain indexers and forest in a Pipeline
val pipeline = new Pipeline()
.setStages(Array(assembler,rf))
// Train model. This also runs the indexers.
val model = pipeline.fit(trainingData)
// Make predictions.
val predictions = model.transform(testData)
[...]
// I could use predictions and the cost matrix to evaluate
// some metrics directly.
[...]
提前谢谢。
的问候,
Paulo Angelo