Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21681][ML] fix bug of MLOR do not work correctly when featureStd contains zero - #18896
[SPARK-21681][ML] fix bug of MLOR do not work correctly when featureStd contains zero #18896WeichenXu123 wants to merge 5 commits into
Conversation
SparkQA
commented
Aug 9, 2017
Test build #80462 has finished for PR 18896 at commit
|
SparkQA
commented
Aug 15, 2017
Test build #80680 has finished for PR 18896 at commit
|
MrBago
left a comment
There was a problem hiding this comment.
The only thing I would change is the name of the new test you added. I would add "multinomial logistic regression with zero var" or something similar to the test name.
There was a problem hiding this comment.
I would include a description of the test in addition to the ticket #.
MrBago
commented
Aug 15, 2017
@jkbradley please take a look when you get a chance. |
jkbradley
commented
Aug 16, 2017
LGTM except for making the test's title more descriptive. Thanks! |
SparkQA
commented
Aug 16, 2017
Test build #80708 has finished for PR 18896 at commit
|
MLnick
commented
Aug 16, 2017
Fix seems ok - but just wondering why the test for zero std dev in |
MLnick
commented
Aug 16, 2017
The model is always trained in the scaled space regardless of the e.g. in the test case doing: valmodel= mlr.fit(multinomialDatasetWithZeroVar)
println(model.interceptVector)
println(model.coefficientMatrix)
valmodel2= mlr.setStandardization(false).fit(multinomialDatasetWithZeroVar)
println(model2.interceptVector)
println(model2.coefficientMatrix)Gives you |
@MLnick Yes it is always trained in scaled space. |
WeichenXu123
commented
Aug 16, 2017
@MLnick I debug the testcase your mentioned. |
jkbradley
commented
Aug 18, 2017
How about updating the LogisticAggregatorSuite so it catches this error: |
WeichenXu123
commented
Aug 18, 2017
@jkkbradley OK. So I can remove the test I added ? |
SparkQA
commented
Aug 18, 2017
Test build #80820 has finished for PR 18896 at commit
|
There was a problem hiding this comment.
The problem with this test was that it checked that part of the gradient was zero, but didn't check that the rest of the gradient was correct. Here, you're checking that the rest of the gradient isn't nan or infinite, but not that it's actually correct. A more appropriate test, IMO, is to also run an aggregator over the same instances with the constant feature filtered out, then check that the portion of the gradients they share are the same. e.g.
valaggConstantFeature= getNewAggregator(instancesConstantFeature,
Vectors.dense(coefArray ++ interceptArray), fitIntercept =true, isMultinomial =true)
valfilteredInstances= instancesConstantFeature.map { caseInstance(l, w, f) =>Instance(l, w, Vectors.dense(f.toArray.tail))
}
valaggMultinomial= getNewAggregator(filteredInstances,
Vectors.dense(coefArray.slice(3, 6) ++ interceptArray), fitIntercept =true,
isMultinomial =true)
filteredInstances.foreach(aggMultinomial.add)
instancesConstantFeature.foreach(aggConstantFeature.add)
// constant features should not affect gradient
assert(aggConstantFeature.gradient.toArray.take(numClasses) ===Array.fill(numClasses)(0.0))
assert(aggMultinomial.gradient.toArray === aggConstantFeature.gradient.toArray.slice(3, 9))Just to note, this code is just for an example, not meant to be copy and pasted.
sethah
commented
Aug 19, 2017
Thanks for catching this @WeichenXu123! I just added a note about the intent of test. |
5e73f63 to
1f4ba14CompareSparkQA
commented
Aug 21, 2017
Test build #80927 has finished for PR 18896 at commit
|
jkbradley
commented
Aug 21, 2017
Thanks @WeichenXu123 and @sethah ! @WeichenXu123 I'd leave the MLOR test since it's cheap and has a clear purpose, even if it overlaps a little. LGTM |
Merging with master |
jkbradley
commented
Aug 22, 2017
@WeichenXu123 would you mind sending a backport PR for 2.2? |
WeichenXu123
commented
Aug 22, 2017
@jkbradley OK. (Can this directly merged to 2.2 ?) |
…td contains zero (backport PR for 2.2) ## What changes were proposed in this pull request? This is backport PR of #18896 fix bug of MLOR do not work correctly when featureStd contains zero We can reproduce the bug through such dataset (features including zero variance), will generate wrong result (all coefficients becomes 0) ``` val multinomialDatasetWithZeroVar = { val nPoints = 100 val coefficients = Array( -0.57997, 0.912083, -0.371077, -0.16624, -0.84355, -0.048509) val xMean = Array(5.843, 3.0) val xVariance = Array(0.6856, 0.0) // including zero variance val testData = generateMultinomialLogisticInput( coefficients, xMean, xVariance, addIntercept = true, nPoints, seed) val df = sc.parallelize(testData, 4).toDF().withColumn("weight", lit(1.0)) df.cache() df } ``` ## How was this patch tested? testcase added. Author: WeichenXu <WeichenXu123@outlook.com> Closes#19026 from WeichenXu123/fix_mlor_zero_var_bug_2_2.
…td contains zero (backport PR for 2.2) ## What changes were proposed in this pull request? This is backport PR of apache#18896 fix bug of MLOR do not work correctly when featureStd contains zero We can reproduce the bug through such dataset (features including zero variance), will generate wrong result (all coefficients becomes 0) ``` val multinomialDatasetWithZeroVar = { val nPoints = 100 val coefficients = Array( -0.57997, 0.912083, -0.371077, -0.16624, -0.84355, -0.048509) val xMean = Array(5.843, 3.0) val xVariance = Array(0.6856, 0.0) // including zero variance val testData = generateMultinomialLogisticInput( coefficients, xMean, xVariance, addIntercept = true, nPoints, seed) val df = sc.parallelize(testData, 4).toDF().withColumn("weight", lit(1.0)) df.cache() df } ``` ## How was this patch tested? testcase added. Author: WeichenXu <WeichenXu123@outlook.com> Closesapache#19026 from WeichenXu123/fix_mlor_zero_var_bug_2_2.
What changes were proposed in this pull request?
fix bug of MLOR do not work correctly when featureStd contains zero
We can reproduce the bug through such dataset (features including zero variance), will generate wrong result (all coefficients becomes 0)
How was this patch tested?
testcase added.