def load_svm(self, filename=None):
     if not filename:
         svm_file = config.get_classifier_filename(self, self.cls, self.train_dataset)
     else:
         svm_file = filename
     if not os.path.exists(svm_file):
         print ("Svm %s is not trained" % svm_file)
         return None
     else:
         model = load_svm(svm_file)
         return model
Пример #2
0
 def load_svm(self, filename=None):
     if not filename:
         svm_file = config.get_classifier_filename(self, self.cls,
                                                   self.train_dataset)
     else:
         svm_file = filename
     if not os.path.exists(svm_file):
         print("Svm %s is not trained" % svm_file)
         return None
     else:
         model = load_svm(svm_file)
         return model
 def train(self, pos, neg, kernel, C):
     y = [1] * pos.shape[0] + [-1] * neg.shape[0]
     x = np.concatenate((pos, neg))
     model = train_svm(x, y, kernel, C)
     self.svm = model
     print "model.score(C=%d): %f" % (C, model.score(x, y))
     table_t = svm_proba(x, model)
     y2 = np.array(y)
     y2 = (y2 + 1) / 2  # switch to 0/1
     ap, _, _ = Evaluation.compute_cls_pr(table_t[:, 1], y2)
     print "ap on train set: %f" % ap
     filename = config.get_classifier_filename(self, self.cls, self.train_dataset)
     self.svm = model
     self.save_svm(model, filename)
     return model
Пример #4
0
 def train(self, pos, neg, kernel, C):
     y = [1] * pos.shape[0] + [-1] * neg.shape[0]
     x = np.concatenate((pos, neg))
     model = train_svm(x, y, kernel, C)
     self.svm = model
     print 'model.score(C=%d): %f' % (C, model.score(x, y))
     table_t = svm_proba(x, model)
     y2 = np.array(y)
     y2 = (y2 + 1) / 2  # switch to 0/1
     ap, _, _ = Evaluation.compute_cls_pr(table_t[:, 1], y2)
     print 'ap on train set: %f' % ap
     filename = config.get_classifier_filename(self, self.cls,
                                               self.train_dataset)
     self.svm = model
     self.save_svm(model, filename)
     return model