def train(self, kernel_width, c, epsilon): self._svm_new(kernel_width, c, epsilon) x = RealFeatures(self.x) self.svm.io.enable_progress() self.svm.train(x) self.svm.io.disable_progress()
def classify(self, matrix): cl = self.svm.classify( RealFeatures( np.reshape(matrix, newshape=(com.FEATURE_DIM, 1), order='F'))).get_label(0) return int(cl + 1.0) % 10
def _svm_new(self, kernel_width, c, epsilon): if self.x == None or self.y == None: raise Exception("No training data loaded.") x = RealFeatures(self.x) y = Labels(self.y) self.svm = GMNPSVM(c, GaussianKernel(x, x, kernel_width), y) self.svm.set_epsilon(epsilon)
def get_test_error(self): self.svm.io.enable_progress() l = self.svm.apply(RealFeatures(self.x_test)).get_labels() self.svm.io.disable_progress() return 1.0 - np.mean(l == self.y_test)