So I have a matrix with my sample images (all turned into vectors) which was run trough PCA/LDA, and a vector which denotes the class each images belongs to. Now I want to use t
Adapted from timgluz version, but uses "train_auto" instead of "train". cv2 will find parameters "C", "gamma", ... for us.
import cv2
import numpy as np
class Learn:
def __init__(self, X, y):
self.est = cv2.SVM()
params = dict(kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC)
self.est.train_auto(X, y, None, None, params, 3) #kfold=3 (default: 10)
def guess(self, X):
return np.float32( [self.est.predict(s) for s in X])
X = np.array(np.random.random((6,2)), dtype = np.float32)
y = np.array([1.,0.,0.,1.,0.,1.], dtype = np.float32)
g = Learn(X,y).guess(X)