Skip to content

Commit

Permalink
[SPARK-12905][ML][PYSPARK] PCAModel return eigenvalues for PySpark
Browse files Browse the repository at this point in the history
```PCAModel```  can output ```explainedVariance``` at Python side.

cc mengxr srowen

Author: Yanbo Liang <[email protected]>

Closes apache#10830 from yanboliang/spark-12905.
  • Loading branch information
yanboliang authored and mengxr committed Jan 25, 2016
1 parent 9348431 commit dcae355
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] (
Expand Down
11 changes: 11 additions & 0 deletions python/pyspark/ml/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -2052,6 +2054,15 @@ def pc(self):
"""
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):
Expand Down

0 comments on commit dcae355

Please sign in to comment.