def decision_function(self, X): if self.is_fitted == False: raise NotFittedError( "This EasyMKL instance is not fitted yet. Call 'fit' with appropriate arguments before using this method." ) if self.kernel == 'precomputed': K = check_KL_Y(X, self.Y) else: X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C") if X.shape[1] != self.n_f: raise ValueError("The number of feature in X not correspond") #K = self.K.set_test(X) K = kernel_list(self.X, X, self.K) if self.multiclass_ == True: return self.cls.decision_function(X) YY = matrix(np.diag(list(matrix(self.Y)))) ker_matrix = matrix(summation(K, self.weights)) z = ker_matrix * YY * self.gamma z = z - self.bias return np.array(list(z))
def _check_test(self,X): if self.is_fitted == False: raise NotFittedError("This EasyMKL instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.") if self.kernel == 'precomputed': KL = check_KL_Y(X,self.Y) else: X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C") if X.shape[1] != self.X.shape[1]:#self.n_f: raise ValueError("The number of feature in X not correspond") KL = self.gen(self.X,X).make_a_list(self.n_kernels).to_array() return KL
def _prepare(self,X,Y): '''preprocess data before training''' check_classification_targets(Y) self.classes_ = np.unique(Y) if len(self.classes_) < 2: raise ValueError("The number of classes has to be almost 2; got ", len(self.classes_)) self.multiclass_ = len(self.classes_) > 2 KL = process_list(X,self.generator) # X can be a samples matrix or Kernels List self.KL, self.Y = check_KL_Y(KL,Y) self.n_kernels = len(self.KL) return
def _prepare(self,X,Y): '''preprocess data before training''' check_classification_targets(Y) self.classes_ = np.unique(Y) if len(self.classes_) < 2: raise ValueError("The number of classes has to be almost 2; got ", len(self.classes_)) self.multiclass_ = len(self.classes_) > 2 KL = process_list(X,self.generator) # X can be a samples matrix or Kernels List self.KL, self.Y = check_KL_Y(KL,Y) self.n_kernels = len(self.KL) return
def _input_checks(self, X, Y): '''valida l'input dell'algoritmo e fa un po di preprocessing''' if self.kernel == 'precomputed': self.KL = check_KL_Y(X,Y) else: X,Y = validation.check_X_y(X, Y, dtype=np.float64, order='C', accept_sparse='csr') self.KL = self.gen(X).make_a_list(self.n_kernels) check_classification_targets(Y) self.Y = Y self.X = X self.classes_ = np.unique(Y) if len(self.classes_) < 2: raise ValueError("The number of classes has to be almost 2; got ", len(self.classes_)) if self.tracenorm: for k in self.KL: self.traces.append(traceN(k))
def _input_checks(self, X, Y): '''valida l'input dell'algoritmo e fa un po di preprocessing''' if self.kernel == 'precomputed': self.K = check_KL_Y(X, Y) elif self.gen != None: X, Y = validation.check_X_y(X, Y, dtype=np.float64, order='C', accept_sparse='csr') self.K = self.gen.make_a_list(self.n_kernels) else: random.seed(1) X, Y = validation.check_X_y(X, Y, dtype=np.float64, order='C', accept_sparse='csr') self.K = random_generator(X).make_a_list( self.n_kernels) #.to_array() #da sistemare i parametri #self.K = poly_generator(X).make_a_list(20)#.to_array() check_classification_targets(Y) self.Y = Y self.X = X self.classes_ = np.unique(Y) if len(self.classes_) < 2: raise ValueError("The number of classes has to be almost 2; got ", len(self.classes_)) self.traces = [] #for k in self.K: # self.traces.append(traceN(k)) if self.tracenorm and False: for k in self.K: self.traces.append(traceN(k)) from MKL.utils import kernel_list if not type(self.K).__name__ == 'ndarray': #== kernel_list: #print 'k_list' self.K /= self.traces else: #print 'array' c = [[[i for j in range(len(Y))] for k in range(len(Y))] for i in self.traces] self.K /= np.array(c) del c self.n_f = X.shape[1]