srendle / libfm

Library for factorization machines
GNU General Public License v3.0
1.49k stars 414 forks source link

Bad loss function for classification? #17

Closed benmccann closed 7 years ago

benmccann commented 8 years ago

According to the docs:

For binary classification, cases with y > 0 are regarded as the positive class and with y ≤ 0 as the negative class.

But if you have a target of 0 in the loss function for negative cases then you don't learn anything because your loss is always 0:

        } else if (task == 1) {
            grad_loss = target * ( (1.0/(1.0+exp(-target*p))) -  1.0);

It seems like target needs to be normalized in the classification case, but I don't see anywhere in the code where that'd be happening. (Note that I haven't actually run the code to prove it's misbehaving, but am just reading it and this didn't make sense to me. Did I miss something?)

srendle commented 7 years ago

For classification, the target is normalized to -1,1 in libfm.cpp line 295.