# Getting parameters of the best model with crossvalidation in with SparkMLLib

I am having trouble accessing the parameters of estimators of model in SparkMLlib. More precisely my problem is: I have a logistic regression model for which I want to find the best regularization parameters (regParam and elasticNetParam). To do that, I use the CrossValidator which works and finds me a model better than all the other one I tried. The issue is that I do not know how to access the actual value of the parameters that were found by the cross validator. Below is the code I use to fit my cross validator:

from pyspark.ml.evaluation import BinaryClassificationEvaluator
from pyspark.ml.tuning import CrossValidator, ParamGridBuilder
from pyspark.ml.classification import LogisticRegression

lr_predictor = LogisticRegression(featuresCol='polyFeatures', labelCol='label', maxIter=10)
paramGrid = ParamGridBuilder() \
.build()
crossval = CrossValidator(estimator=LogRegPipeline,
estimatorParamMaps=paramGrid,
evaluator=BinaryClassificationEvaluator(),
numFolds=2)
cvModel = crossval.fit(train_set)
bestModel = cvModel.bestModel

• Did you try bestModel.extractParamMap()? – Biggus Sep 6 '19 at 16:48
zip(cvModel.avgMetrics, paramGrid)