diff options
author | Yanbo Liang <ybliang8@gmail.com> | 2016-01-25 13:54:21 -0800 |
---|---|---|
committer | Xiangrui Meng <meng@databricks.com> | 2016-01-25 13:54:21 -0800 |
commit | dcae355c64d7f6fdf61df2feefe464eb96c4cf5e (patch) | |
tree | 401df92f5b3239caf68c37ccc98925582aa7a9b6 | |
parent | 9348431da212ec3ab7be2b8e89a952a48b4e2a31 (diff) | |
download | spark-dcae355c64d7f6fdf61df2feefe464eb96c4cf5e.tar.gz spark-dcae355c64d7f6fdf61df2feefe464eb96c4cf5e.tar.bz2 spark-dcae355c64d7f6fdf61df2feefe464eb96c4cf5e.zip |
[SPARK-12905][ML][PYSPARK] PCAModel return eigenvalues for PySpark
```PCAModel``` can output ```explainedVariance``` at Python side.
cc mengxr srowen
Author: Yanbo Liang <ybliang8@gmail.com>
Closes #10830 from yanboliang/spark-12905.
-rw-r--r-- | mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala | 2 | ||||
-rw-r--r-- | python/pyspark/ml/feature.py | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala b/mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala index 7020397f3b..0e07dfabfe 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala @@ -102,6 +102,8 @@ object PCA extends DefaultParamsReadable[PCA] { * Model fitted by [[PCA]]. * * @param pc A principal components Matrix. Each column is one principal component. + * @param explainedVariance A vector of proportions of variance explained by + * each principal component. */ @Experimental class PCAModel private[ml] ( diff --git a/python/pyspark/ml/feature.py b/python/pyspark/ml/feature.py index 141ec3492a..1fa0eab384 100644 --- a/python/pyspark/ml/feature.py +++ b/python/pyspark/ml/feature.py @@ -1987,6 +1987,8 @@ class PCA(JavaEstimator, HasInputCol, HasOutputCol): >>> model = pca.fit(df) >>> model.transform(df).collect()[0].pca_features DenseVector([1.648..., -4.013...]) + >>> model.explainedVariance + DenseVector([0.794..., 0.205...]) .. versionadded:: 1.5.0 """ @@ -2052,6 +2054,15 @@ class PCAModel(JavaModel): """ return self._call_java("pc") + @property + @since("2.0.0") + def explainedVariance(self): + """ + Returns a vector of proportions of variance + explained by each principal component. + """ + return self._call_java("explainedVariance") + @inherit_doc class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): |