Uh oh!
There was an error while loading. Please reload this page.
[SPARK-11057] [SQL] Add correlation and covariance matrices - #9366
[SPARK-11057] [SQL] Add correlation and covariance matrices#9366NarineK wants to merge 1 commit into
Conversation
NarineK
commented
Oct 30, 2015
shivaram
commented
Oct 30, 2015
cc @mengxr |
SparkQA
commented
Oct 30, 2015
Test build #44651 has finished for PR 9366 at commit
|
NarineK
commented
Nov 5, 2015
Hi guys, would you share your thoughts about this ? |
NarineK
commented
Nov 9, 2015
In general I think that currently there are some issues in the StatFunctions.scala: It seems that all computations both for covariance and correlation are being accomplished in one place which makes it a little confusing and harder to extend for the future. collectStatisticalData method is called for both correlation and covariance and even if I call something like this: Here is an example: I think we can actually separate the computations. Is there a reason why these computations are being accomplished in one place ? @rxin, @mengxr |
There was a problem hiding this comment.
You can't assume all columns are of numeric type. Catch exception here and use null as value if exception happens?
NarineK
commented
Nov 16, 2015
Hi @sun-rui, |
NarineK
commented
Nov 16, 2015
what do you think ? |
sun-rui
commented
Nov 17, 2015
Yes, since R throws error message in this case, we can leave exception un-handled. No need to verify all column types. User will get exception message at https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/stat/StatFunctions.scala#L81 |
NarineK
commented
Nov 17, 2015
yes, there is even a test case which covers that case. |
NarineK
commented
Nov 17, 2015
can someone from Spark SQL committers or experts also look at this ? |
SparkQA
commented
Mar 16, 2016
Test build #53308 has finished for PR 9366 at commit
|
SparkQA
commented
Apr 18, 2016
Test build #56142 has finished for PR 9366 at commit
|
shivaram
commented
Apr 19, 2016
cc @mengxr |
I have been trying to use correlation on a matrix with many columns. @NarineK menthioned R like correlation. I wish we had something like what pandas offers. It handles missing data automatically. Take a look here. Even the corr() function from MLlib can not handle missing data. These features are really missing from SparkSQL:
|
gatorsmile
commented
Jun 13, 2017
@NarineK Are you still working on this? cc @yanboliang |
gatorsmile
commented
Jun 27, 2017
We are closing it due to inactivity. please do reopen if you want to push it forward. Thanks! |
## What changes were proposed in this pull request? This PR proposes to close stale PRs, mostly the same instances with apache#18017 I believe the author in apache#14807 removed his account. Closesapache#7075Closesapache#8927Closesapache#9202Closesapache#9366Closesapache#10861Closesapache#11420Closesapache#12356Closesapache#13028Closesapache#13506Closesapache#14191Closesapache#14198Closesapache#14330Closesapache#14807Closesapache#15839Closesapache#16225Closesapache#16685Closesapache#16692Closesapache#16995Closesapache#17181Closesapache#17211Closesapache#17235Closesapache#17237Closesapache#17248Closesapache#17341Closesapache#17708Closesapache#17716Closesapache#17721Closesapache#17937 Added: Closesapache#14739Closesapache#17139Closesapache#17445Closesapache#18042Closesapache#18359 Added: Closesapache#16450Closesapache#16525Closesapache#17738 Added: Closesapache#16458Closesapache#16508Closesapache#17714 Added: Closesapache#17830Closesapache#14742 ## How was this patch tested? N/A Author: hyukjinkwon <gurwls223@gmail.com> Closesapache#18417 from HyukjinKwon/close-stale-pr.
Hi there,
As we know R has the option to calculate the correlation and covariance for all columns of a dataframe or between columns of two dataframes.
If we look at apache math package we can see that, they have that too.
http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/correlation/PearsonsCorrelation.html#computeCorrelationMatrix%28org.apache.commons.math3.linear.RealMatrix%29
In case we have as input only one DataFrame:
for correlation:
cor[i,j] = cor[j,i]
and for the main diagonal we can have 1s.
for covariance:
cov[i,j] = cov[j,i]
and for main diagonal: we can compute the variance for that specific column:
See:
http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/correlation/Covariance.html#computeCovarianceMatrix%28org.apache.commons.math3.linear.RealMatrix%29
Thanks,
Narine