Flayn Flayn - 8 months ago 49
Python Question

Choosing the best SVM kernel type and parameters using OpenCV on Python

I'm trying to find the SVM kernel type and parameters that fits better my data. I'm using OpenCV on Python and I found the function cv2.SVM.train_auto to achieve this, but I didn't found a clear example of how to use it.

Could someone guide me to find the best kernel or give me an explanation of how to use cv2.SVM.train_auto?

Answer Source

I'm also looking for that information but you can have a look at the digits_adjust.py example, it uses train() instead of train_auto() and shows how to iterate on C and gamma parameters to try to find a best combination.

Interesting functions are:

def cross_validate(model_class, params, samples, labels, kfold = 3, pool = None):
    def adjust_SVM(self):
        Cs = np.logspace(0, 10, 15, base=2)
        gammas = np.logspace(-7, 4, 15, base=2)
            params = dict(C = Cs[i], gamma=gammas[j])
            score = cross_validate(SVM, params, samples, labels)