Could it be because  target  has  0 s and  1 s in it unlike what the documentation suggests, that it should contain  1 s and  -1 s. Is the behavior when you add this line  target[target == 0] = -1  along expected lines?