如何提取从CrossValidatorModel最佳参数 [英] How to extract best parameters from a CrossValidatorModel

查看:1981
本文介绍了如何提取从CrossValidatorModel最佳参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到的参数 ParamGridBuilder ,使最好的模型CrossValidator在星火1.4.x的,

I want to find the parameters of ParamGridBuilder that make the best model in CrossValidator in Spark 1.4.x,

在<一个href=\"http://spark.apache.org/docs/latest/ml-guide.html#example-model-selection-via-cross-validation\">Pipeline星火实例文档中的,他们通过使用<$ C $添加不同的参数( numFeatures regParam ) C> ParamGridBuilder 酝酿中。然后通过下面的行code,他们做最好的模型:

In Pipeline Example in Spark documentation, they add different parameters (numFeatures, regParam) by using ParamGridBuilder in the Pipeline. Then by the following line of code they make the best model:

val cvModel = crossval.fit(training.toDF)

现在,我想知道什么是参数( numFeatures regParam )从 ParamGridBuilder 产生的最佳模式。

Now, I want to know what are the parameters (numFeatures, regParam) from ParamGridBuilder that produces the best model.

我已经用下面的命令没有成功:

I already used the following commands without success:

cvModel.bestModel.extractParamMap().toString()
cvModel.params.toList.mkString("(", ",", ")")
cvModel.estimatorParamMaps.toString()
cvModel.explainParams()
cvModel.getEstimatorParamMaps.mkString("(", ",", ")")
cvModel.toString()

任何帮助吗?

由于提前,

推荐答案

一个方法来获得正确的 ParamMap 对象是使用 CrossValidatorModel.avgMetrics :数组[双] 找到argmax ParamMap

One method to get a proper ParamMap object is to use CrossValidatorModel.avgMetrics: Array[Double] to find the argmax ParamMap:

implicit class BestParamMapCrossValidatorModel(cvModel: CrossValidatorModel) {
  def bestEstimatorParamMap: ParamMap = {
    cvModel.getEstimatorParamMaps
           .zip(cvModel.avgMetrics)
           .maxBy(_._2)
           ._1
  }
}

在上运行 CrossValidatorModel 训练有素的管道比如你引用给出了:

When run on the CrossValidatorModel trained in the Pipeline Example you cited gives:

scala> println(cvModel.bestParamMap)
{
   hashingTF_2b0b8ccaeeec-numFeatures: 100,
   logreg_950a13184247-regParam: 0.1
}

这篇关于如何提取从CrossValidatorModel最佳参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆