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)
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)
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)
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)
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)