-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-22883][ML][TEST] Streaming tests for spark.ml.feature, from A to H #20111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jkbradley
wants to merge
2
commits into
apache:master
from
jkbradley:SPARK-22883-streaming-featureAM
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,16 +17,15 @@ | |
|
|
||
| package org.apache.spark.ml.feature | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.ml.linalg.{Vector, Vectors} | ||
| import org.apache.spark.ml.param.ParamsSuite | ||
| import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTestingUtils} | ||
| import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTest, MLTestingUtils} | ||
| import org.apache.spark.ml.util.TestingUtils._ | ||
| import org.apache.spark.mllib.util.MLlibTestSparkContext | ||
| import org.apache.spark.sql.{Dataset, Row} | ||
|
|
||
| class ChiSqSelectorSuite extends SparkFunSuite with MLlibTestSparkContext | ||
| with DefaultReadWriteTest { | ||
| class ChiSqSelectorSuite extends MLTest with DefaultReadWriteTest { | ||
|
|
||
| import testImplicits._ | ||
|
|
||
| @transient var dataset: Dataset[_] = _ | ||
|
|
||
|
|
@@ -119,32 +118,32 @@ class ChiSqSelectorSuite extends SparkFunSuite with MLlibTestSparkContext | |
| test("Test Chi-Square selector: numTopFeatures") { | ||
| val selector = new ChiSqSelector() | ||
| .setOutputCol("filtered").setSelectorType("numTopFeatures").setNumTopFeatures(1) | ||
| val model = ChiSqSelectorSuite.testSelector(selector, dataset) | ||
| val model = testSelector(selector, dataset) | ||
| MLTestingUtils.checkCopyAndUids(selector, model) | ||
| } | ||
|
|
||
| test("Test Chi-Square selector: percentile") { | ||
| val selector = new ChiSqSelector() | ||
| .setOutputCol("filtered").setSelectorType("percentile").setPercentile(0.17) | ||
| ChiSqSelectorSuite.testSelector(selector, dataset) | ||
| testSelector(selector, dataset) | ||
| } | ||
|
|
||
| test("Test Chi-Square selector: fpr") { | ||
| val selector = new ChiSqSelector() | ||
| .setOutputCol("filtered").setSelectorType("fpr").setFpr(0.02) | ||
| ChiSqSelectorSuite.testSelector(selector, dataset) | ||
| testSelector(selector, dataset) | ||
| } | ||
|
|
||
| test("Test Chi-Square selector: fdr") { | ||
| val selector = new ChiSqSelector() | ||
| .setOutputCol("filtered").setSelectorType("fdr").setFdr(0.12) | ||
| ChiSqSelectorSuite.testSelector(selector, dataset) | ||
| testSelector(selector, dataset) | ||
| } | ||
|
|
||
| test("Test Chi-Square selector: fwe") { | ||
| val selector = new ChiSqSelector() | ||
| .setOutputCol("filtered").setSelectorType("fwe").setFwe(0.12) | ||
| ChiSqSelectorSuite.testSelector(selector, dataset) | ||
| testSelector(selector, dataset) | ||
| } | ||
|
|
||
| test("read/write") { | ||
|
|
@@ -163,18 +162,19 @@ class ChiSqSelectorSuite extends SparkFunSuite with MLlibTestSparkContext | |
| assert(expected.selectedFeatures === actual.selectedFeatures) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object ChiSqSelectorSuite { | ||
|
|
||
| private def testSelector(selector: ChiSqSelector, dataset: Dataset[_]): ChiSqSelectorModel = { | ||
| val selectorModel = selector.fit(dataset) | ||
| selectorModel.transform(dataset).select("filtered", "topFeature").collect() | ||
| .foreach { case Row(vec1: Vector, vec2: Vector) => | ||
| private def testSelector(selector: ChiSqSelector, data: Dataset[_]): ChiSqSelectorModel = { | ||
|
||
| val selectorModel = selector.fit(data) | ||
| testTransformer[(Double, Vector, Vector)](data.toDF(), selectorModel, | ||
| "filtered", "topFeature") { | ||
| case Row(vec1: Vector, vec2: Vector) => | ||
| assert(vec1 ~== vec2 absTol 1e-1) | ||
| } | ||
| } | ||
| selectorModel | ||
| } | ||
| } | ||
|
|
||
| object ChiSqSelectorSuite { | ||
|
|
||
| /** | ||
| * Mapping from all Params to valid settings which differ from the defaults. | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,13 +17,31 @@ | |
|
|
||
| package org.apache.spark.ml.feature | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.ml.linalg.Vectors | ||
| import org.apache.spark.ml.util.DefaultReadWriteTest | ||
| import org.apache.spark.mllib.util.MLlibTestSparkContext | ||
| import org.apache.spark.ml.linalg.{Vector, Vectors} | ||
| import org.apache.spark.ml.util.{DefaultReadWriteTest, MLTest} | ||
| import org.apache.spark.ml.util.TestingUtils._ | ||
| import org.apache.spark.sql.Row | ||
|
|
||
| class ElementwiseProductSuite | ||
| extends SparkFunSuite with MLlibTestSparkContext with DefaultReadWriteTest { | ||
| class ElementwiseProductSuite extends MLTest with DefaultReadWriteTest { | ||
|
|
||
| import testImplicits._ | ||
|
|
||
| test("streaming transform") { | ||
|
||
| val scalingVec = Vectors.dense(0.1, 10.0) | ||
| val data = Seq( | ||
| (Vectors.dense(0.1, 1.0), Vectors.dense(0.01, 10.0)), | ||
| (Vectors.dense(0.0, -1.1), Vectors.dense(0.0, -11.0)) | ||
| ) | ||
| val df = spark.createDataFrame(data).toDF("features", "expected") | ||
| val ep = new ElementwiseProduct() | ||
| .setInputCol("features") | ||
| .setOutputCol("actual") | ||
| .setScalingVec(scalingVec) | ||
| testTransformer[(Vector, Vector)](df, ep, "actual", "expected") { | ||
| case Row(actual: Vector, expected: Vector) => | ||
| assert(actual ~== expected relTol 1e-14) | ||
| } | ||
| } | ||
|
|
||
| test("read/write") { | ||
| val ep = new ElementwiseProduct() | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No existing test to use