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)
Пример #3
0
 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)
Пример #4
0
	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)
Пример #5
0
	def __init__(self, prob, param):
		if param is None:
			raise NotImplementedError, "svm_varma can't load a svm_model from a file (yet)"

		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 = 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 = labels = _int_array_to_list(intarr, self.nr_class)
		svmc.delete_int(intarr)
		if len(labels) != 2:
			raise NotImplementedError, "svm_varma doesn't handle problems with more than 2 labels (yet)"
		#check if valid probability model
		self.probability = svmc.svm_check_probability_model(self.model)

		model = self.model
		self.obj = svmc.svm_varma_get_obj(model, 0)
		self.rho = svmc.svm_varma_get_rho(model, 0)
		self.nSV = svmc.svm_varma_get_nSV(model, 0)
		self.total_sv = svmc.svm_varma_get_total_sv(model)

		# XXX: this only work for 2-class problems
		size = self.total_sv
		doublearr = svmc.new_double(size)
		svmc.svm_varma_get_sv_coef(model, 0, doublearr)
		self.sv_coef = _double_array_to_list(doublearr, size)
		svmc.delete_double(doublearr)
		
		# XXX: only works with PRECOMPUTED kernels
		size = self.total_sv
		doublearr = svmc.new_double(size)
		svmc.svm_varma_get_SV(model, doublearr)
		self.SV = _double_array_to_list(doublearr, size)
		svmc.delete_double(doublearr)