-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-5099][Mllib] Simplify logistic loss function #3899
Conversation
+1 looks like a small good improvement. |
Test build #25053 has finished for PR 3899 at commit
|
@viirya Thanks for the improvement! We could make this computation more accurate. We should branch based on Do you have time making this change? Or I can merge this PR and create a JIRA as a reminder. |
@mengxr Thanks for that. I will do it later. |
Hi @mengxr, Thanks for comment. I may be wrong, but I think that we should branch based on Because according to the definition of logistic loss function, When we branch on Besides, https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/mllib/tree/loss/LogLoss.scala#L67 and https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/mllib/tree/loss/LogLoss.scala#L69 are mathematically the same equation. I think it should be a bug. As the function note said, it is not used by the gradient boosting algorithm but only for debugging, so it is not found before. I add a commit to fix it. |
Test build #25093 has finished for PR 3899 at commit
|
@viirya They are the same analytically but not numerically, for example, scala> math.log1p(math.exp(1000))
res2: Double = Infinity
scala> 1000 + math.log1p(math.exp(-1000))
res3: Double = 1000.0 |
OK. I understood it. I am wrong for LogLoss. Will revert it back. |
@mengxr I noticed that you file a issue in #SPARK-5101. Do I need to extract the codes in this pr to the place you suggested |
Test build #25097 has finished for PR 3899 at commit
|
@mengxr I think I already know what you meant to branch based on |
Test build #25101 has finished for PR 3899 at commit
|
@@ -64,11 +64,17 @@ class LogisticGradient extends Gradient { | |||
val gradientMultiplier = (1.0 / (1.0 + math.exp(margin))) - label | |||
val gradient = data.copy | |||
scal(gradientMultiplier, gradient) | |||
val minusYP = label * margin |
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.
This looks like you expect labels to be -1, +1. They are actually 0, 1.
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.
Oh? I thought it is similar to LogLoss so it would be {+1, -1}. Fixed.
LGTM pending Jenkins. I'm going to merge this first. We might want to add more functions in #3915 . |
Test build #25127 has finished for PR 3899 at commit
|
Thanks. |
Merged into master. Thanks! |
This is a minor pr where I think that we can simply take minus of
margin
, instead of subtractingmargin
.Mathematically, they are equal. But the modified equation is the common form of logistic loss function and so more readable. It also computes more accurate value as some quick tests show.