Github user WeichenXu123 commented on a diff in the pull request:
https://github.com/apache/spark/pull/18313#discussion_r128684617
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/tuning/CrossValidator.scala ---
@@ -113,15 +122,28 @@ class CrossValidator @Since("1.2.0") (@Since("1.4.0")
override val uid: String)
// multi-model training
logDebug(s"Train split $splitIndex with multiple sets of
parameters.")
val models = est.fit(trainingDataset,
epm).asInstanceOf[Seq[Model[_]]]
- trainingDataset.unpersist()
+
var i = 0
while (i < numModels) {
// TODO: duplicate evaluator to take extra params from input
val metric = eval.evaluate(models(i).transform(validationDataset,
epm(i)))
logDebug(s"Got metric $metric for model trained with ${epm(i)}.")
+ if (isDefined(modelPreservePath)) {
+ models(i) match {
+ case w: MLWritable =>
+ // e.g. maxIter-5-regParam-0.001-split0-0.859
+ val fileName = epm(i).toSeq.map(p => p.param.name + "-" +
p.value).sorted
+ .mkString("-") + s"-split$splitIndex-${math.rint(metric *
1000) / 1000}"
+ w.save(new Path($(modelPreservePath), fileName).toString)
+ case _ =>
+ // for third-party algorithms
+ logWarning(models(i).uid + " did not implement MLWritable.
Serialization omitted.")
+ }
+ }
metrics(i) += metric
--- End diff --
ping @hhbyyh @jkbradley
I am sorry but I want to say that this code is incorrect. Inside `fit`
method save the list of fitted models help nothing.
What we need is to let CrossValidatorModel/TrainValidationSplitModel
preserve the full list of fitted models, when save
CrossValidatorModel/TrainValidationSplitModel we can save the list of models,
also we can choose not to save, controlled by a parameter.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]