(self, X, y, description="ExperimentName")
Performs a k-fold cross validation
        
        Args:

            X [dim x num_data] input data to validate on
            y [1 x num_data] classes
Performs a k-fold cross validation
        
        Args:
Performs a k - fold cross validation Args :
def validate(self, X, y, description="ExperimentName"):
        """ Performs a k-fold cross validation
        
        Args:

            X [dim x num_data] input data to validate on
            y [1 x num_data] classes
        """
        X,y = shuffle(X,y)
        c = len(np.unique(y))
        foldIndices = []
        n = np.iinfo(np.int).max
        for i in range(0,c):
            idx = np.where(y==i)[0]
            n = min(n, idx.shape[0])
            foldIndices.append(idx.tolist()); 

        # I assume all folds to be of equal length, so the minimum
        # number of samples in a class is responsible for the number
        # of folds. This is probably not desired. Please adjust for
        # your use case.
        if n < self.k:
            self.k = n

        foldSize = int(math.floor(n/self.k))
        
        true_positives, false_positives, true_negatives, false_negatives = (0,0,0,0)
        for i in range(0,self.k):
        
            self.logger.info("Processing fold %d/%d." % (i+1, self.k))
                
            # calculate indices
            l = int(i*foldSize)
            h = int((i+1)*foldSize)
            testIdx = slice_2d(foldIndices, cols=range(l,h), rows=range(0, c))
            trainIdx = slice_2d(foldIndices,cols=range(0,l), rows=range(0,c))
            trainIdx.extend(slice_2d(foldIndices,cols=range(h,n),rows=range(0,c)))
            
            # build training data subset
            Xtrain = [X[t] for t in trainIdx]
            ytrain = y[trainIdx]
                        
            self.model.compute(Xtrain, ytrain)
            
            # TODO I have to add the true_negatives and false_negatives. Models also need to support it,
            # so we should use a PredictionResult, instead of trying to do this by simply comparing
            # the predicted and actual class.
            #
            # This is inteneded of the next version! Feel free to contribute.
            for j in testIdx:
                prediction = self.model.predict(X[j])[0]
                if prediction == y[j]:
                    true_positives = true_positives + 1
                else:
                    false_positives = false_positives + 1
                    
        self.add(ValidationResult(true_positives, true_negatives, false_positives, false_negatives, description))
def validate ( self , X , y , description = "ExperimentName" ) : X , y = shuffle ( X , y ) c = len ( np . unique ( y ) ) foldIndices = [ ] n = np . iinfo ( np . int ) . max for i in range ( 0 , c ) : idx = np . where ( y == i ) [ 0 ] n = min ( n , idx . shape [ 0 ] ) foldIndices . append ( idx . tolist ( ) ) # I assume all folds to be of equal length, so the minimum # number of samples in a class is responsible for the number # of folds. This is probably not desired. Please adjust for # your use case. if n < self . k : self . k = n foldSize = int ( math . floor ( n / self . k ) ) true_positives , false_positives , true_negatives , false_negatives = ( 0 , 0 , 0 , 0 ) for i in range ( 0 , self . k ) : self . logger . info ( "Processing fold %d/%d." % ( i + 1 , self . k ) ) # calculate indices l = int ( i * foldSize ) h = int ( ( i + 1 ) * foldSize ) testIdx = slice_2d ( foldIndices , cols = range ( l , h ) , rows = range ( 0 , c ) ) trainIdx = slice_2d ( foldIndices , cols = range ( 0 , l ) , rows = range ( 0 , c ) ) trainIdx . extend ( slice_2d ( foldIndices , cols = range ( h , n ) , rows = range ( 0 , c ) ) ) # build training data subset Xtrain = [ X [ t ] for t in trainIdx ] ytrain = y [ trainIdx ] self . model . compute ( Xtrain , ytrain ) # TODO I have to add the true_negatives and false_negatives. Models also need to support it, # so we should use a PredictionResult, instead of trying to do this by simply comparing # the predicted and actual class. # # This is inteneded of the next version! Feel free to contribute. for j in testIdx : prediction = self . model . predict ( X [ j ] ) [ 0 ] if prediction == y [ j ] : true_positives = true_positives + 1 else : false_positives = false_positives + 1 self . add ( ValidationResult ( true_positives , true_negatives , false_positives , false_negatives , description ) )