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)
You could get the rmse for each parameter in your grid using:
alsModel.getEstimatorParamMaps.zip(alsModel.avgMetrics)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With