-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
[SPARK-22881][ML][TEST] ML regression package testsuite add StructuredStreaming test #19979
Closed
Closed
Changes from all commits
Commits
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,16 +25,15 @@ import org.apache.spark.ml.feature.{Instance, OffsetInstance} | |
import org.apache.spark.ml.feature.{LabeledPoint, RFormula} | ||
import org.apache.spark.ml.linalg.{BLAS, DenseVector, Vector, Vectors} | ||
import org.apache.spark.ml.param.{ParamMap, 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.random._ | ||
import org.apache.spark.mllib.util.MLlibTestSparkContext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can remove unused imports |
||
import org.apache.spark.sql.{DataFrame, Row} | ||
import org.apache.spark.sql.functions._ | ||
import org.apache.spark.sql.types.FloatType | ||
|
||
class GeneralizedLinearRegressionSuite | ||
extends SparkFunSuite with MLlibTestSparkContext with DefaultReadWriteTest { | ||
class GeneralizedLinearRegressionSuite extends MLTest with DefaultReadWriteTest { | ||
|
||
import testImplicits._ | ||
|
||
|
@@ -268,8 +267,8 @@ class GeneralizedLinearRegressionSuite | |
s"$link link and fitIntercept = $fitIntercept.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(dataset).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Vector)](dataset, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -278,7 +277,7 @@ class GeneralizedLinearRegressionSuite | |
s"gaussian family, $link link and fitIntercept = $fitIntercept.") | ||
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with gaussian family, $link link and fitIntercept = $fitIntercept.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
|
@@ -384,8 +383,8 @@ class GeneralizedLinearRegressionSuite | |
s"$link link and fitIntercept = $fitIntercept.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(dataset).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Vector)](dataset, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -394,7 +393,7 @@ class GeneralizedLinearRegressionSuite | |
s"binomial family, $link link and fitIntercept = $fitIntercept.") | ||
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with binomial family, $link link and fitIntercept = $fitIntercept.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
|
@@ -456,8 +455,8 @@ class GeneralizedLinearRegressionSuite | |
s"$link link and fitIntercept = $fitIntercept.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(dataset).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Vector)](dataset, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -466,7 +465,7 @@ class GeneralizedLinearRegressionSuite | |
s"poisson family, $link link and fitIntercept = $fitIntercept.") | ||
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with poisson family, $link link and fitIntercept = $fitIntercept.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
|
@@ -562,8 +561,8 @@ class GeneralizedLinearRegressionSuite | |
s"$link link and fitIntercept = $fitIntercept.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(dataset).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Vector)](dataset, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -572,7 +571,7 @@ class GeneralizedLinearRegressionSuite | |
s"gamma family, $link link and fitIntercept = $fitIntercept.") | ||
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with gamma family, $link link and fitIntercept = $fitIntercept.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
|
@@ -649,8 +648,8 @@ class GeneralizedLinearRegressionSuite | |
s"and variancePower = $variancePower.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(datasetTweedie).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Double, Vector)](datasetTweedie, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -661,7 +660,8 @@ class GeneralizedLinearRegressionSuite | |
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with tweedie family, linkPower = $linkPower, fitIntercept = $fitIntercept " + | ||
s"and variancePower = $variancePower.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
} | ||
|
@@ -724,8 +724,8 @@ class GeneralizedLinearRegressionSuite | |
s"fitIntercept = $fitIntercept and variancePower = $variancePower.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(datasetTweedie).select("features", "prediction", "linkPrediction").collect() | ||
.foreach { | ||
testTransformer[(Double, Double, Vector)](datasetTweedie, model, | ||
"features", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, prediction1: Double, linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept | ||
val prediction2 = familyLink.fitted(eta) | ||
|
@@ -736,7 +736,8 @@ class GeneralizedLinearRegressionSuite | |
assert(linkPrediction1 ~= linkPrediction2 relTol 1E-5, "Link Prediction mismatch: " + | ||
s"GLM with tweedie family, fitIntercept = $fitIntercept " + | ||
s"and variancePower = $variancePower.") | ||
} | ||
} | ||
|
||
idx += 1 | ||
} | ||
} | ||
|
@@ -861,8 +862,8 @@ class GeneralizedLinearRegressionSuite | |
s" and fitIntercept = $fitIntercept.") | ||
|
||
val familyLink = FamilyAndLink(trainer) | ||
model.transform(dataset).select("features", "offset", "prediction", "linkPrediction") | ||
.collect().foreach { | ||
testTransformer[(Double, Double, Double, Vector)](dataset, model, | ||
"features", "offset", "prediction", "linkPrediction") { | ||
case Row(features: DenseVector, offset: Double, prediction1: Double, | ||
linkPrediction1: Double) => | ||
val eta = BLAS.dot(features, model.coefficients) + model.intercept + offset | ||
|
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.
The
varianceDF
generated byTreeTests.setMetadata
, how to add "expected value" column into the DF ? It seems to need some flaky code. @jkbradleyThere 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.
The expected values would have to be added to
def varianceData
.