我正在使用Spark 1.6.1:
目前,我正在使用CrossValidator来训练具有各种参数的ML管道。在训练过程之后,我可以使用CrossValidatorModel的bestModel属性来获得在交叉验证期间表现最佳的模型。
交叉验证的其他模型是否会自动丢弃,或者我是否可以选择性能比bestModel差的模型?
我问是因为我正在使用F1分数度量标准进行交叉验证,但是我也对所有模型的weightedRecall感兴趣,而不仅仅是在交叉验证过程中表现最佳的模型
val folds = 6
val cv = new CrossValidator()
.setEstimator(pipeline)
.setEvaluator(new MulticlassClassificationEvaluator)
.setEstimatorParamMaps(paramGrid)
.setNumFolds(folds)
val avgF1Scores = cvModel.avgMetrics
val predictedDf = cvModel.bestModel.transform(testDf)
// Here I would like to predict as well with the other models of the cross validation
最佳答案
Spark> = 2.4.0 (> = 2.3.0 in Scala)
SPARK-21088 CrossValidator,TrainValidationSplit在拟合时应收集所有模型-添加了对收集子模型的支持。
cv = CrossValidator(..., collectSubModels=True)
model = cv.fit(...)
model.subModels
Spark <2.4
如果要访问所有中间模型,则必须从头开始创建自定义交叉验证器。
o.a.s.ml.tuning.CrossValidator
丢弃其他模型,并且仅将最佳模型和指标复制到CrossValidatorModel
。另请参阅Pyspark - Get all parameters of models created with ParamGridBuilder
关于apache-spark - Spark CrossValidatorModel是否可以访问除bestModel以外的其他模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38874546/