Github user NarineK commented on a diff in the pull request:
https://github.com/apache/spark/pull/9366#discussion_r44926444
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/stat/StatFunctions.scala
---
@@ -33,6 +34,31 @@ private[sql] object StatFunctions extends Logging {
counts.Ck / math.sqrt(counts.MkX * counts.MkY)
}
+ /** Calculate the Pearson Correlation matrix for given DataFrame */
+ private[sql] def pearsonCorrelation(df: DataFrame): DataFrame = {
+ val fieldNames = df.schema.fieldNames
+ val dfStructAttrs = ArrayBuffer[AttributeReference](
+ AttributeReference("FieldName", StringType, true)())
+ val rows = fieldNames.map{fname => val countsRow = new
GenericMutableRow(fieldNames.length + 1)
+ countsRow.update(0, UTF8String.fromString(fname))
+ countsRow
+ }.toSeq
+ // generates field types of the output DataFrame
+ for(field <- fieldNames) dfStructAttrs += AttributeReference(field,
DoubleType, true)()
+
+ // fills the correlation matrix by computing column-by-column
correlations
+ for (i <- 0 to fieldNames.length - 1){
+ for (j <- 0 to i){
+ val corr = pearsonCorrelation(df, Seq(fieldNames(i),
fieldNames(j)))
--- End diff --
I'm not sure if showing null is valid. If not numeric then not showing
anything, I think so ....
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]