Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5858#discussion_r29565880
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameStatSuite.scala ---
    @@ -43,19 +43,40 @@ class DataFrameStatSuite extends FunSuite  {
         val singleColResults = df.stat.freqItems(Array("negDoubles"), 0.1)
         val items2 = singleColResults.collect().head
         items2.getSeq[Double](0) should contain (-1.0)
    +  }
     
    +  test("pearson correlation") {
    +    val df = Seq.tabulate(10)(i => (i, 2 * i, i * -1.0)).toDF("a", "b", 
"c")
    +    val corr1 = df.stat.corr("a", "b", "pearson")
    +    assert(math.abs(corr1 - 1.0) < 1e-12)
    +    val corr2 = df.stat.corr("a", "c", "pearson")
    +    assert(math.abs(corr2 + 1.0) < 1e-12)
    +    // non-trivial example. To reproduce in python, use:
    +    // >>> from scipy.stats import pearsonr
    +    // >>> import numpy as np
    +    // >>> a = np.array(range(20))
    +    // >>> b = np.array([x * x - 2 * x + 3.5 for x in range(20)])
    +    // >>> pearsonr(a, b)
    +    // (0.95723391394758572, 3.8902121417802199e-11)
    +    // In R, use:
    +    // > a <- 0:19
    +    // > b <- mapply(function(x) x * x - 2 * x + 3.5, a)
    +    // > cor(a, b)
    +    // [1] 0.957233913947585835
    --- End diff --
    
    Thanks for adding this test!


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to