Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get best parameters for TrainValidationSplit scala

I am using the Spark Scala ML API and I am trying to pass a pipeline ALS model to the TrainValidationSplit. The code executes but I am unable to retrieve the best parameters...thoughts?

val alsPipeline = new Pipeline().setStages(Array(idIndexer , modelIndexer, als))

val paramGrid = new ParamGridBuilder().
    addGrid(als.maxIter, Array(5, 10)).
    addGrid(als.regParam, Array(0.01, 0.05, 0.1)).
    addGrid(als.implicitPrefs).
    build()

val tvs = new TrainValidationSplit().
                setEstimator(alsPipeline).
                setEvaluator(new RegressionEvaluator().
                                    setMetricName("rmse").
                                    setLabelCol("purchases").
                                    setPredictionCol("prediction")).
                setEstimatorParamMaps(paramGrid).
                setTrainRatio(0.75)

val alsModel = tvs.fit(trainALS)
like image 373
mgcdanny Avatar asked Dec 04 '25 10:12

mgcdanny


1 Answers

You could get the rmse for each parameter in your grid using:

alsModel.getEstimatorParamMaps.zip(alsModel.avgMetrics)
like image 103
mtoto Avatar answered Dec 07 '25 07:12

mtoto