1

We can calculate the log loss for a classification problem with two classes as follows:

enter image description here

where y is the label of the actual class and p the probability of the class being positive (e.g. P(y=1)).

However, this assumes that y has the classes 0 and 1. What can I do when my class labels are actually -1 and +1? How do you calculate the log loss in that case?

JohnAndrews
  • 537
  • 1
  • 5
  • 15
  • See https://stats.stackexchange.com/questions/229645/why-there-are-two-different-logistic-loss-formulation-notations?noredirect=1&lq=1 – Tim May 29 '18 at 08:54
  • 3
    recode your classes? convert -1 to 0 – ReneBt May 29 '18 at 08:56
  • @ReneBt Yes but are there any dangers in doing so? Because from the link of Tim I see that there is a second notation, specifically designed for -1 and +1 – JohnAndrews May 29 '18 at 08:57
  • 1
    Compose $\frac{z+1}{2} \mapsto y$ with your function $L: y \mapsto \ell$. – Neil G May 29 '18 at 09:01
  • If there is a way to do something without interfering, go with that as it reduces risk of bugs in your code. So use the function for your case rather than mess with the coding. In most cases it won't matter, unless it matters that one is the inverse of the other, or the interval between the two is important (so in the case of log loss you would need the appropriate function since the actual value is used in the formula). – ReneBt May 29 '18 at 09:04
  • I am not sure if I am getting it. So I cannot convert the -1 to 0? @NeilG what exactly is is the z in your approximation? – JohnAndrews May 29 '18 at 11:33
  • 2
    Think of an outcome $y=a, b$ and write the log likelihood function (don't call this log loss) by replacing $y$ with $y=b$ and $1-y$ with $y=a$ and you'll see the general issue. This is only a labeling issue and no math is required. – Frank Harrell May 29 '18 at 12:04
  • 1
    @FrankHarrell No I agree, there is clearly an issue when you apply the classes {-1,+1}. But since the interval between the two is not important, it might as well be A or B (in my case, stock price Up or stock price Down), then I guess I can just replace -1 with 0. – JohnAndrews May 29 '18 at 16:40

0 Answers0