如何在CrossValidatorModel中访问每个折页的计算指标 [英] How can I access computed metrics for each fold in a CrossValidatorModel
本文介绍了如何在CrossValidatorModel中访问每个折页的计算指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 spark.ml
中的 CrossValidatorModel
获取每个折叠的计算指标?我知道我可以使用 model.avgMetrics
来获取平均指标,但是是否有可能获得每折的原始结果,例如.结果的差异?
How can I get the computed metrics for each fold from a CrossValidatorModel
in spark.ml
? I know I can get the average metrics using model.avgMetrics
but is it possible to get the raw results on each fold to look at eg. the variance of the results?
我正在使用Spark 2.0.0.
I am using Spark 2.0.0.
推荐答案
For the folds, you can do the iteration yourself like this:
val splits = MLUtils.kFold(dataset.toDF.rdd, $(numFolds), $(seed))
//K-folding operation starting
//for each fold you have multiple models created cfm. the paramgrid
splits.zipWithIndex.foreach { case ((training, validation), splitIndex) =>
val trainingDataset = sparkSession.createDataFrame(training, schema).cache()
val validationDataset = sparkSession.createDataFrame(validation, schema).cache()
val models = est.fit(trainingDataset, epm).asInstanceOf[Seq[Model[_]]]
trainingDataset.unpersist()
var i = 0
while (i < numModels) {
val metric = eval.evaluate(models(i).transform(validationDataset, epm(i)))
logDebug(s"Got metric $metric for model trained with ${epm(i)}.")
metrics(i) += metric
i += 1
}
这是在scala中,但是思路很清晰.
This is in scala, but the ideas are very clearly outlined.
看看此答案,它概述了结果每折.希望这会有所帮助.
Take a look at this answer that outlines results per fold. Hope this helps.
这篇关于如何在CrossValidatorModel中访问每个折页的计算指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文