0

I need a svm classifier of python with huber loss function. But its default loss function is hinge loss. Do you know how can I assign loss function to python svm?

svc = svm.SVC(kernel='linear', C=1, gamma=1).fit(data, label)
user3104352
  • 1,100
  • 1
  • 16
  • 34
  • What library is this from? scikit learn? It is hard to figure out what the issue is without knowing what software you are actually using. – Dylan Aug 15 '17 at 20:26
  • it is from from sklearn. – user3104352 Aug 15 '17 at 20:33
  • Well, one issue is that svm.SVC() has no loss parameter at all. svm.LinearSVC does, but the docs specify that only hinge and squared hinge are available. So the loss function you want is not available in the software you are using. if you must have that loss function specifically, you would have to write it yourself. – Dylan Aug 15 '17 at 21:10
  • In sklearn, svm functionality is delegated to liblinear and libsvm libraries C libraries, so I dont think you can do this without significanlty implementing yourself. Look for other alternatives. Maybe [`SGDClassifier()`](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier.predict_proba) is of use. – Vivek Kumar Aug 16 '17 at 12:12

1 Answers1

0

There is really no such thing as "SVM with huber loss", as SVM is literally a linear (or kernelized) model trained with hinge loss. If you change the loss - it stops being SVM. Consequently libraries do not have a loss parameter, as changing it does not apply to the SVM concept.

If you want to train a model with huber loss you can use SGDClassiifier from sklearn, which will train a linear model with this (and many other) loss.

If you want to do something more complex, like non-linear model with this kind of penalty - then sklearn is not the good choice and you should look at more "low-level" libraries such us TF, Keras and so on.

lejlot
  • 64,777
  • 8
  • 131
  • 164