Uh oh!
There was an error while loading. Please reload this page.
[SPARK-6227] [MLlib] [PySpark] Implement PySpark wrappers for SVD and PCA - #7963
[SPARK-6227] [MLlib] [PySpark] Implement PySpark wrappers for SVD and PCA#7963MechCoder wants to merge 7 commits into
Conversation
MechCoder
commented
Aug 5, 2015
Actually I'll add the PCA wrappers in this PR as well. |
SparkQA
commented
Aug 5, 2015
Test build #39888 has finished for PR 7963 at commit
|
SparkQA
commented
Aug 5, 2015
Test build #39895 has finished for PR 7963 at commit
|
56978ae to
f64a83fCompareSparkQA
commented
Aug 5, 2015
Test build #39901 has finished for PR 7963 at commit
|
SparkQA
commented
Aug 5, 2015
Test build #39904 has finished for PR 7963 at commit
|
MechCoder
commented
Aug 5, 2015
All right this PR is ready for review. |
SparkQA
commented
Aug 5, 2015
Test build #39916 has finished for PR 7963 at commit
|
There was a problem hiding this comment.
Minor: This import isn't needed.
dusenberrymw
commented
Aug 7, 2015
Great work, @MechCoder! I left some very small comments, and otherwise it looks good. |
MechCoder
commented
Aug 10, 2015
Thanks for the reviews, I have addressed your comments. Do you have anything else? |
SparkQA
commented
Aug 10, 2015
Test build #40286 has finished for PR 7963 at commit
|
There was a problem hiding this comment.
I'd check that matrix is a DenseMatrix here as well.
dusenberrymw
commented
Aug 12, 2015
@MechCoder I'd just add the |
…ted Linear Algebra Classes This PR adds the remaining group of methods to PySpark's distributed linear algebra classes as follows: * `RowMatrix` <sup>**[1]**</sup> 1. `computeGramianMatrix` 2. `computeCovariance` 3. `computeColumnSummaryStatistics` 4. `columnSimilarities` 5. `tallSkinnyQR` <sup>**[2]**</sup> * `IndexedRowMatrix` <sup>**[3]**</sup> 1. `computeGramianMatrix` * `CoordinateMatrix` 1. `transpose` * `BlockMatrix` 1. `validate` 2. `cache` 3. `persist` 4. `transpose` **[1]**: Note: `multiply`, `computeSVD`, and `computePrincipalComponents` are already part of PR apache#7963 for SPARK-6227. **[2]**: Implementing `tallSkinnyQR` uncovered a bug with our PySpark `RowMatrix` constructor. As discussed on the dev list [here](http://apache-spark-developers-list.1001551.n3.nabble.com/K-Means-And-Class-Tags-td10038.html), there appears to be an issue with type erasure with RDDs coming from Java, and by extension from PySpark. Although we are attempting to construct a `RowMatrix` from an `RDD[Vector]` in [PythonMLlibAPI](https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/mllib/api/python/PythonMLLibAPI.scala#L1115), the `Vector` type is erased, resulting in an `RDD[Object]`. Thus, when calling Scala's `tallSkinnyQR` from PySpark, we get a Java `ClassCastException` in which an `Object` cannot be cast to a Spark `Vector`. As noted in the aforementioned dev list thread, this issue was also encountered with `DecisionTrees`, and the fix involved an explicit `retag` of the RDD with a `Vector` type. Thus, this PR currently contains that fix applied to the `createRowMatrix` helper function in `PythonMLlibAPI`. `IndexedRowMatrix` and `CoordinateMatrix` do not appear to have this issue likely due to their related helper functions in `PythonMLlibAPI` creating the RDDs explicitly from DataFrames with pattern matching, thus preserving the types. However, this fix may be out of scope for this single PR, and it may be better suited in a separate JIRA/PR. Therefore, I have marked this PR as WIP and am open to discussion. **[3]**: Note: `multiply` and `computeSVD` are already part of PR apache#7963 for SPARK-6227. Author: Mike Dusenberry <mwdusenb@us.ibm.com> Closesapache#9441 from dusenberrymw/SPARK-9656_Add_Missing_Methods_to_PySpark_Distributed_Linear_Algebra.
cavaunpeu
commented
May 20, 2016
any progress on this @dusenberrymw@MechCoder? it would be really helpful if I could do matrix multiplication in pyspark. |
SparkQA
commented
May 27, 2016
Test build #59437 has finished for PR 7963 at commit
|
MechCoder
commented
May 27, 2016
@cavaunpeu Thanks for the ping! I think I've addressed the pending diff comment. It will take me some time to refresh the knowledge of the codebase. Can @MLnick or @holdenk give a final pass? |
SparkQA
commented
May 27, 2016
Test build #59445 has finished for PR 7963 at commit
|
MechCoder
commented
Jun 13, 2016
Bump? |
MLnick
commented
Jun 17, 2016
@MechCoder thanks for updating this - may need to wait until after 2.0 release for review. |
holdenk
commented
Oct 7, 2016
holdenk
left a comment
There was a problem hiding this comment.
Thanks for working on this and sorry this fell through the cracks post 2.0. I've left some initial comments - likely the same comments apply to the indexed one as well.
| </div> | ||
| <div data-lang="python" markdown="1"> | ||
| {% highlight python %} |
There was a problem hiding this comment.
Now days we tend write new examples separately and then use the include example syntax to bring them
| The following code demonstrates how to compute principal components on a `RowMatrix` | ||
| and use them to project the vectors into a low-dimensional space. | ||
| R = decomp.call("R") | ||
| return QRDecomposition(Q, R) | ||
| def computeSVD(self, k, computeU=False, rCond=1e-9): |
There was a problem hiding this comment.
Would be good to add a since annotation here
| For more specific details on implementation, please refer | ||
| the scala documentation. | ||
| :param k: Set the number of singular values to keep. |
There was a problem hiding this comment.
It might be good to copy the longer description from RowMatrix for the k param
| def computePrincipalComponents(self, k): | ||
| """ | ||
| Computes the k principal components of the given row matrix |
There was a problem hiding this comment.
It might be good to copy the warnings form RowMatrix here as well.
| class SingularValueDecomposition(JavaModelWrapper): | ||
| """Wrapper around the SingularValueDecomposition scala case class""" |
MechCoder
commented
Oct 11, 2016
Thanks for the reviews @holdenk . Unfortunately I will not be able to work on this anytime soon. Feel free to cherry-pick the commits, (if you wish) |
holdenk
commented
Oct 14, 2016
@MechCoder Thanks! I'll look around and see if anyone else is interested in taking this over and bringing it to the finish line otherwise I'll pick it up myself after OSCON :) |
HyukjinKwon
commented
Feb 9, 2017
Ping @MechCoder, are you able to proceed this PR and address the comments above? If not it might be good to close this for now. |
MLnick
commented
Apr 12, 2017
Note I revived this at #17621 based on @MechCoder's work. |
…CA (v2) Add PCA and SVD to PySpark's wrappers for `RowMatrix` and `IndexedRowMatrix` (SVD only). Based on apache#7963, updated. ## How was this patch tested? New doc tests and unit tests. Ran all examples locally. Author: MechCoder <manojkumarsivaraj334@gmail.com> Author: Nick Pentreath <nickp@za.ibm.com> Closesapache#17621 from MLnick/SPARK-6227-pyspark-svd-pca.
…CA (v2) Add PCA and SVD to PySpark's wrappers for `RowMatrix` and `IndexedRowMatrix` (SVD only). Based on #7963, updated. ## How was this patch tested? New doc tests and unit tests. Ran all examples locally. Author: MechCoder <manojkumarsivaraj334@gmail.com> Author: Nick Pentreath <nickp@za.ibm.com> Closes#17621 from MLnick/SPARK-6227-pyspark-svd-pca. (cherry picked from commit db2fb84) Signed-off-by: Nick Pentreath <nickp@za.ibm.com>
SixAlien3
commented
Jun 22, 2017
@MLnick Hi, I'm interesting in this PySpark wrapper for SVD. How many columns can this support? Cuz I see in the old document it can only support columns <1000. How about this wrapper? |
## What changes were proposed in this pull request? This PR proposes to close stale PRs. What I mean by "stale" here includes that there are some review comments by reviewers but the author looks inactive without any answer to them more than a month. I left some comments roughly a week ago to ping and the author looks still inactive in these PR below These below includes some PR suggested to be closed and a PR against another branch which seems obviously inappropriate. Given the comments in the last three PRs below, they are probably worth being taken over by anyone who is interested in it. Closesapache#7963Closesapache#8374Closesapache#11192Closesapache#11374Closesapache#11692Closesapache#12243Closesapache#12583Closesapache#12620Closesapache#12675Closesapache#12697Closesapache#12800Closesapache#13715Closesapache#14266Closesapache#15053Closesapache#15159Closesapache#15209Closesapache#15264Closesapache#15267Closesapache#15871Closesapache#15861Closesapache#16319Closesapache#16324Closesapache#16890Closesapache#12398Closesapache#12933Closesapache#14517 ## How was this patch tested? N/A Author: hyukjinkwon <gurwls223@gmail.com> Closesapache#16937 from HyukjinKwon/stale-prs-close.
Singular Value Decomposition wrappers are missing in PySpark. Since the base for a RowMatrix has been laid writing the wrappers becomes straightforward. Will follow up with the PCA Wrappers in another PR.