Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13937#discussion_r68697383
--- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala ---
@@ -206,24 +206,21 @@ object PCAModel extends MLReadable[PCAModel] {
override def load(path: String): PCAModel = {
val metadata = DefaultParamsReader.loadMetadata(path, sc, className)
- // explainedVariance field is not present in Spark <= 1.6
- val versionRegex = "([0-9]+)\\.([0-9]+).*".r
- val hasExplainedVariance = metadata.sparkVersion match {
- case versionRegex(major, minor) =>
- major.toInt >= 2 || (major.toInt == 1 && minor.toInt > 6)
- case _ => false
- }
+ val versionRegex = "([0-9]+)\\.(.+)".r
+ val versionRegex(major, _) = metadata.sparkVersion
val dataPath = new Path(path, "data").toString
- val model = if (hasExplainedVariance) {
+ val model = if (major.toInt >= 2) {
val Row(pc: DenseMatrix, explainedVariance: DenseVector) =
sparkSession.read.parquet(dataPath)
.select("pc", "explainedVariance")
.head()
new PCAModel(metadata.uid, pc, explainedVariance)
} else {
- val Row(pc: DenseMatrix) =
sparkSession.read.parquet(dataPath).select("pc").head()
- new PCAModel(metadata.uid, pc,
Vectors.dense(Array.empty[Double]).asInstanceOf[DenseVector])
+ // explainedVariance field is not present and we use the old
matrix in Spark <= 2.0
+ val Row(pc: OldDenseMatrix) =
sparkSession.read.parquet(dataPath).select("pc").head()
+ new PCAModel(metadata.uid, pc.asML,
+ Vectors.dense(Array.empty[Double]).asInstanceOf[DenseVector])
--- End diff --
Here we combine the ```explainedVariance``` field issue and the old matrix
issue together to handle backward compatibility.
---
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]