-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11852] [ML] StandardScaler minor refactor #9839
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,23 +116,19 @@ class StandardScalerSuite extends SparkFunSuite with MLlibTestSparkContext | |
| assertResult(standardScaler3.transform(df3)) | ||
| } | ||
|
|
||
| test("StandardScaler read/write") { | ||
| val t = new StandardScaler() | ||
| .setInputCol("myInputCol") | ||
| .setOutputCol("myOutputCol") | ||
| .setWithStd(false) | ||
| .setWithMean(true) | ||
| testDefaultReadWrite(t) | ||
| } | ||
|
|
||
| test("StandardScalerModel read/write") { | ||
| val oldModel = new feature.StandardScalerModel( | ||
| Vectors.dense(1.0, 2.0), Vectors.dense(3.0, 4.0), false, true) | ||
| val instance = new StandardScalerModel("myStandardScalerModel", oldModel) | ||
| val newInstance = testDefaultReadWrite(instance) | ||
| assert(newInstance.std === instance.std) | ||
| assert(newInstance.mean === instance.mean) | ||
| assert(newInstance.getWithStd === instance.getWithStd) | ||
| assert(newInstance.getWithMean === instance.getWithMean) | ||
| test("read/write") { | ||
| def checkModelData(model1: StandardScalerModel, model2: StandardScalerModel): Unit = { | ||
| assert(model1.mean === model2.mean) | ||
| assert(model1.std === model2.std) | ||
| } | ||
| val allParams: Map[String, Any] = Map( | ||
| "inputCol" -> "features", | ||
| "outputCol" -> "standardized_features", | ||
| "withMean" -> true, | ||
| "withStd" -> true | ||
| ) | ||
| val df = sqlContext.createDataFrame(data.zip(resWithBoth)).toDF("features", "expected") | ||
| val standardScaler = new StandardScaler() | ||
| testEstimatorAndModelReadWrite(standardScaler, df, allParams, checkModelData) | ||
| } | ||
|
||
| } | ||
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.
We only need to check
meanandstdwhich are parts of the model,withStdandwithStdare params.