Exemple #1
0
 def __setstate__(self,state):
     if libsvm is None:
         raise RuntimeError('LibSVM Library not found. Cannot use this classifier.')
     S,self.output_probability,self.names = state
     N = NamedTemporaryFile()
     N.write(S)
     N.flush()
     self.model = libsvm.svm_model(N.name)
Exemple #2
0
def demo1():
    """
    Set of exercises to better understand workings of SVM
    """
    pdb.set_trace()
    prob = svm.svm_problem([1, -1], [[1, 0, 1], [-1, 0, -1]])
    param = svm.svm_parameter()
    mod = svm.svm_model(prob, param)
Exemple #3
0
 def __setstate__(self, state):
     if libsvm is None:
         raise RuntimeError(
             'LibSVM Library not found. Cannot use this classifier.')
     S, self.output_probability, self.names = state
     N = NamedTemporaryFile()
     N.write(S)
     N.flush()
     self.model = libsvm.svm_model(N.name)
Exemple #4
0
 def train(self, features, labels):
     labels,names = normaliselabels(labels)
     if self.auto_weighting:
         nlabels = labels.max() + 1
         self.param.nr_weight = int(nlabels)
         self.param.weight_label = range(nlabels)
         self.param.weight = [(labels != i).mean() for i in xrange(nlabels)]
     problem = libsvm.svm_problem(labels.astype(float), features)
     model = libsvm.svm_model(problem, self.param)
     return libsvmModel(model, names, self.output_probability)
Exemple #5
0
 def train(self, features, labels):
     labels, names = normaliselabels(labels)
     if self.auto_weighting:
         nlabels = labels.max() + 1
         self.param.nr_weight = int(nlabels)
         self.param.weight_label = list(range(nlabels))
         self.param.weight = [(labels != i).mean() for i in range(nlabels)]
     problem = libsvm.svm_problem(labels.astype(float), features)
     model = libsvm.svm_model(problem, self.param)
     return libsvmModel(model, names, self.output_probability)