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

    https://github.com/apache/spark/pull/19108#discussion_r174977495
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/stat/KolmogorovSmirnovTestSuite.scala 
---
    @@ -0,0 +1,133 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.stat
    +
    +import org.apache.commons.math3.distribution.{ExponentialDistribution, 
NormalDistribution}
    +import org.apache.commons.math3.stat.inference.{KolmogorovSmirnovTest => 
Math3KSTest}
    +
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.ml.util.DefaultReadWriteTest
    +import org.apache.spark.ml.util.TestingUtils._
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +import org.apache.spark.sql.Row
    +
    +class KolmogorovSmirnovTestSuite
    +  extends SparkFunSuite with MLlibTestSparkContext with 
DefaultReadWriteTest {
    +
    +  import testImplicits._
    +
    +  test("1 sample Kolmogorov-Smirnov test: apache commons math3 
implementation equivalence") {
    +    // Create theoretical distributions
    +    val stdNormalDist = new NormalDistribution(0, 1)
    +    val expDist = new ExponentialDistribution(0.6)
    +
    +    // set seeds
    +    val seed = 10L
    +    stdNormalDist.reseedRandomGenerator(seed)
    +    expDist.reseedRandomGenerator(seed)
    +
    +    // Sample data from the distributions and parallelize it
    +    val n = 100000
    +    val sampledNormArray = stdNormalDist.sample(n)
    +    val sampledNormDF = sc.parallelize(sampledNormArray, 10).toDF("sample")
    +    val sampledExpArray = expDist.sample(n)
    +    val sampledExpDF = sc.parallelize(sampledExpArray, 10).toDF("sample")
    +
    +    // Use a apache math commons local KS test to verify calculations
    +    val ksTest = new Math3KSTest()
    +    val pThreshold = 0.05
    +
    +    // Comparing a standard normal sample to a standard normal distribution
    --- End diff --
    
    Can this and the next set of code lines be combined into a single helper 
method?  That could help with adding in the test for the uniform distribution 
as well.


---

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

Reply via email to