def __init__(self, arg1, arg2=None): if arg2 == None: # create model from file filename = arg1 self.model = svmc.svm_load_model(filename) else: # create model from problem and parameter prob, param = arg1, arg2 self.prob = prob if param.gamma == 0: param.gamma = 1.0 / prob.maxlen msg = svmc.svm_check_parameter(prob.prob, param.param) if msg: raise ValueError(msg) self.model = svmc.svm_train(prob.prob, param.param) #setup some classwide variables self.nr_class = svmc.svm_get_nr_class(self.model) self.svm_type = svmc.svm_get_svm_type(self.model) #create labels(classes) intarr = svmc.new_int(self.nr_class) svmc.svm_get_labels(self.model, intarr) self.labels = int_array_to_list(intarr, self.nr_class) svmc.delete_int(intarr) #check if valid probability model self.probability = svmc.svm_check_probability_model(self.model)
def __init__(self, arg1, arg2=None): if arg2 == None: # create model from file filename = arg1 self.model = svmc.svm_load_model(filename) else: # create model from problem and parameter prob, param = arg1, arg2 self.prob = prob if param.gamma == 0: param.gamma = 1.0/prob.maxlen msg = svmc.svm_check_parameter(prob.prob, param.param) if msg: raise ValueError, msg self.model = svmc.svm_train(prob.prob, param.param) #setup some classwide variables self.nr_class = svmc.svm_get_nr_class(self.model) self.svm_type = svmc.svm_get_svm_type(self.model) #create labels(classes) intarr = svmc.new_int(self.nr_class) svmc.svm_get_labels(self.model, intarr) self.labels = int_array_to_list(intarr, self.nr_class) svmc.delete_int(intarr) #check if valid probability model self.probability = svmc.svm_check_probability_model(self.model)
def free_int_array(x): if x != 'NULL' and x != None: svmc.delete_int(x)