I want to find the parameters of ParamGridBuilder
that make the best model in CrossValidator in Spark 1.4.x,
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)
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()
Any help?
Thanks in advance,
this java code should work:
cvModel.bestModel().parent().extractParamMap()
.you can translate it to scala codeparent()
method will return an estimator, you can get the best params then.One method to get a proper
ParamMap
object is to useCrossValidatorModel.avgMetrics: Array[Double]
to find the argmaxParamMap
:When run on the
CrossValidatorModel
trained in the Pipeline Example you cited gives:To print everything in
paramMap
, you actually don't have to call parent:To answer OP's question, to get a single best parameter, for example
regParam
:This is how you get the chosen parameters
If java,see this debug show;
Building in the solution of @macfeliga, a single liner that works for pipelines: