You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Sean Owen (JIRA)" <ji...@apache.org> on 2017/09/03 09:18:00 UTC

[jira] [Updated] (SPARK-21900) Numerical Error in simple Skewness Computation

     [ https://issues.apache.org/jira/browse/SPARK-21900?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sean Owen updated SPARK-21900:
------------------------------
    Priority: Minor  (was: Major)
     Summary: Numerical Error in simple Skewness Computation  (was: Error in Skewness Computation)

Try {{.show(truncate=false)}}. I think you'll find that it's actually something like "5.95...e-17", which is nearly 0.

Still, I find it does return 0 if the input is 1,2,3,4, and return differently nearly-0 values for different orderings. That's not quite ideal for such a simple example where the result is obviously 0, even if it's 
It also, however, seems to return 0 on the original input in Spark 2.2.

On a different input like 1,2,3,10,20,30 it gives 0.7256411823021005, which matches scipy (with bias correction) and e1071 in R ("type 1" definition). I suspect the calculation is correct, but this is slightly unfortunate manifestation of numerical error.

[~mengxr] wrote a whole paper on this (!) https://arxiv.org/pdf/1510.04923.pdf

> Numerical Error in simple Skewness Computation
> ----------------------------------------------
>
>                 Key: SPARK-21900
>                 URL: https://issues.apache.org/jira/browse/SPARK-21900
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.2.0
>            Reporter: Jakob Bach
>            Priority: Minor
>
> The skewness() aggregate SQL function in the Scala implementation (org.apache.spark.sql.skewness) seems to be buggy .The following code
> {code:java}
> import org.apache.spark.sql.functions
> import org.apache.spark.sql.SparkSession
> object SkewTest {
>   def main(args: Array[String]): Unit = {
>     val spark = SparkSession.
>       builder().
>       appName("Skewness example").
>       master("local[1]").
>       getOrCreate()
>     spark.createDataFrame(Seq(4,1,2,3).map(Tuple1(_))).agg(functions.skewness("_1")).show()
>   }
> }
> {code}
> should output 0 (as it does for Seq(1,2,3,4)), but outputs
> {code:none}
> +--------------------+
> |        skewness(_1)|
> +--------------------+
> |5.958081967793454...|
> +--------------------+
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org