Ask Your Question
0

Stochastic Gradient Descent SVM and RAW_OUTPUT

asked 2018-05-10 06:22:14 -0600

I'm trying to implement the Stochastic Gradient Descent SVM in order to get an incremental version of the SVM. The problem is that I noted that the function related to this is not configured in order to output the score information of the prediction of the SVM, it just show the class label. I am using the Python API in Windows 7.

svm = cv2.ml.SVMSGD_create()
svm.setOptimalParameters()
svm.setTermCriteria((cv2.TERM_CRITERIA_COUNT, 100, 1.e-06))

DATA = cv2.ml.TrainData_create(trainData, cv2.ml.ROW_SAMPLE,  labels)
svm.train( DATA, cv2.ml.STAT_MODEL_UPDATE_MODEL)
svm.predict(candidate, flags = cv2.ml.STAT_MODEL_RAW_OUTPUT)[1][0,0]

The result is always the same with or without the flag:

cv2.ml.STAT_MODEL_RAW_OUTPUT

Looking into the core code of OpenCV library I think that in the definition of the predict function of SGDSVM there is no reference to this flag.

float SVMSGDImpl::predict( InputArray _samples, OutputArray _results, int ) const

Comparing to the normal SVM.

float predict( InputArray _samples, OutputArray _results, int flags ) const CV_OVERRIDE

Am I doing something wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-10 06:35:20 -0600

berak gravatar image

updated 2018-05-10 06:57:42 -0600

  • " to get an incremental version of the SVM. " -- sorry, won't work. first thing it does in train() is call clear().

    the only classes, that can make use of cv2.ml.STAT_MODEL_UPDATE_MODEL are ANN_MLP and LogisticRegression. (also, you would have to make an initial run without that flag)

  • cv2.ml.STAT_MODEL_RAW_OUTPUT -- that too, goes entirely unused. if you need the distance to the margin, you have to retrieve the support vector(s) and the shift val using getWeights(), getShift(), and do your own dot product, then add the shift.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-10 06:22:14 -0600

Seen: 337 times

Last updated: May 10 '18