forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-17315][SPARKR] Kolmogorov-Smirnov test SparkR wrapper
## What changes were proposed in this pull request? This PR tries to add Kolmogorov-Smirnov Test wrapper to SparkR. This wrapper implementation only supports one sample test against normal distribution. ## How was this patch tested? R unit test. Author: Junyang Qian <junyangq@databricks.com> Closes apache#14881 from junyangq/SPARK-17315.
- Loading branch information
Showing
5 changed files
with
205 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
mllib/src/main/scala/org/apache/spark/ml/r/KSTestWrapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.r | ||
|
||
import org.apache.spark.mllib.stat.Statistics.kolmogorovSmirnovTest | ||
import org.apache.spark.mllib.stat.test.KolmogorovSmirnovTestResult | ||
import org.apache.spark.sql.{DataFrame, Row} | ||
|
||
private[r] class KSTestWrapper private ( | ||
val testResult: KolmogorovSmirnovTestResult, | ||
val distName: String, | ||
val distParams: Array[Double]) { | ||
|
||
lazy val pValue = testResult.pValue | ||
|
||
lazy val statistic = testResult.statistic | ||
|
||
lazy val nullHypothesis = testResult.nullHypothesis | ||
|
||
lazy val degreesOfFreedom = testResult.degreesOfFreedom | ||
|
||
def summary: String = testResult.toString | ||
} | ||
|
||
private[r] object KSTestWrapper { | ||
|
||
def test( | ||
data: DataFrame, | ||
featureName: String, | ||
distName: String, | ||
distParams: Array[Double]): KSTestWrapper = { | ||
|
||
val rddData = data.select(featureName).rdd.map { | ||
case Row(feature: Double) => feature | ||
} | ||
|
||
val ksTestResult = kolmogorovSmirnovTest(rddData, distName, distParams : _*) | ||
|
||
new KSTestWrapper(ksTestResult, distName, distParams) | ||
} | ||
} | ||
|