Skip to content

Commit dcae355

Browse files
yanboliangmengxr
authored andcommitted
[SPARK-12905][ML][PYSPARK] PCAModel return eigenvalues for PySpark
```PCAModel``` can output ```explainedVariance``` at Python side. cc mengxr srowen Author: Yanbo Liang <[email protected]> Closes #10830 from yanboliang/spark-12905.
1 parent 9348431 commit dcae355

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ object PCA extends DefaultParamsReadable[PCA] {
102102
* Model fitted by [[PCA]].
103103
*
104104
* @param pc A principal components Matrix. Each column is one principal component.
105+
* @param explainedVariance A vector of proportions of variance explained by
106+
* each principal component.
105107
*/
106108
@Experimental
107109
class PCAModel private[ml] (

python/pyspark/ml/feature.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,8 @@ class PCA(JavaEstimator, HasInputCol, HasOutputCol):
19871987
>>> model = pca.fit(df)
19881988
>>> model.transform(df).collect()[0].pca_features
19891989
DenseVector([1.648..., -4.013...])
1990+
>>> model.explainedVariance
1991+
DenseVector([0.794..., 0.205...])
19901992
19911993
.. versionadded:: 1.5.0
19921994
"""
@@ -2052,6 +2054,15 @@ def pc(self):
20522054
"""
20532055
return self._call_java("pc")
20542056

2057+
@property
2058+
@since("2.0.0")
2059+
def explainedVariance(self):
2060+
"""
2061+
Returns a vector of proportions of variance
2062+
explained by each principal component.
2063+
"""
2064+
return self._call_java("explainedVariance")
2065+
20552066

20562067
@inherit_doc
20572068
class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol):

0 commit comments

Comments
 (0)