-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21108] [ML] convert LinearSVC to aggregator framework #18315
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 1 commit
071ce88
87c7279
c8228fb
94e0250
bc33cf9
3d7bfce
b19ca41
30e8646
4173084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext { | |
| val interceptArray = Array(2.0) | ||
|
Contributor
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. ditto |
||
| val agg = getNewAggregator(instances, Vectors.dense(coefArray ++ interceptArray), | ||
| fitIntercept = true) | ||
| withClue("LogisticAggregator does not support negative instance weights") { | ||
| withClue("HingeAggregator does not support negative instance weights") { | ||
| intercept[IllegalArgumentException] { | ||
| agg.add(Instance(1.0, -1.0, Vectors.dense(2.0, 1.0))) | ||
| } | ||
|
|
@@ -133,4 +133,18 @@ class HingeAggregatorSuite extends SparkFunSuite with MLlibTestSparkContext { | |
| assert(gradient ~== agg.gradient relTol 0.01) | ||
| } | ||
|
|
||
|
Contributor
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. The other aggregator tests have one for "zero standard deviation". We should add one here too.
Contributor
Author
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. Sure. Added. |
||
| test("check with zero standard deviation") { | ||
|
Contributor
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. As we found out in #18896, this test is not thorough enough. We should check all elements of the gradient for correctness. |
||
| val instancesConstantFeature = Array( | ||
|
||
| Instance(0.0, 0.1, Vectors.dense(1.0, 2.0)), | ||
| Instance(1.0, 0.5, Vectors.dense(1.0, 1.0)), | ||
| Instance(1.0, 0.3, Vectors.dense(1.0, 0.5))) | ||
| val binaryCoefArray = Array(1.0, 2.0) | ||
| val intercept = 1.0 | ||
| val aggConstantFeatureBinary = getNewAggregator(instancesConstantFeature, | ||
| Vectors.dense(binaryCoefArray ++ Array(intercept)), fitIntercept = true) | ||
| instances.foreach(aggConstantFeatureBinary.add) | ||
| // constant features should not affect gradient | ||
| assert(aggConstantFeatureBinary.gradient(0) === 0.0) | ||
| } | ||
|
|
||
| } | ||
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.
It seems this only support hinge loss currently. BTW, if we support squared hinge in the future, what is the best way? Add a param loss function for
HingeAggregatoror just add a newSquaredHingeAggregator? The later way should be more clear, but with more code.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.
I would prefer to use SquaredHingeAggregator. API-wise, it looks more intuitive and consistent to me. We can continue the review in the other LinearSVC PR.
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.
Yeah, I agree you for separate
SquaredHingeAggregator. Then we should removesquared_hingefrom here?BTW, you missed right parenthesis here.