问题
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)
回答1:
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.
来源:https://stackoverflow.com/questions/45698160/python-svm-function-with-huber-loss