kazuto1011 / svm-pytorch

Linear SVM with PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong loss function

osainz59 opened this issue · comments

The C parameter of the LinearSVC should be multiplying the hinge loss and not the regularization method. Also, the l2 regularization method is defined as w.t·w/2, which is not equal to torch.mean(w ** 2).

svm-pytorch/main.py

Lines 51 to 52 in 970eec1

loss = torch.mean(torch.clamp(1 - output.t() * y, min=0)) # hinge loss
loss += args.c * torch.mean(model.fc.weight ** 2) # l2 penalty

Source: https://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf

Thank you for reporting. The definition of the L2 penalty has been fixed. The C parameter still follows the sklearn.svm.SVC format.