def fit(self,X,y,Xtest=None,ytest=None):
        """Fit."""
        input_dim = X.shape[1]
        # set different data preparation schemes basing on what kind of NN is it
        layers = [i.keys()[0] for i in self.architecture]
        self.isCNN = 'Conv' in layers
        self.isRecurrent = 'GRU' in layers or 'LSTM' in layers        
        if self.isCNN:
            self.addDelay = delay_preds
            self.training_params['num_strides'] = self.delay//self.skip
        elif self.isRecurrent:
            self.addDelay = delay_preds_2d
        else:
            input_dim *= self.delay/self.skip
            input_dim = int( input_dim )
            self.addDelay = delay_preds
        
        # create the model
        self.model = buildNN(self.architecture, self.training_params, input_dim)
            
        widgets = ['Training : ', Percentage(), ' ', Bar(marker=RotatingMarker()),
           ' ', ETA(), ' ']
        pbar = ProgressBar(widgets=widgets, maxval=self.majorEpochs)
        pbar.start()
            
        # train the model on a portion of training data; that portion is changed each majorEpoch
        for majorEpoch in range(self.majorEpochs):
            startingPoint = majorEpoch%self.partsTrain or self.mdlNr%self.partsTrain
            if self.jump is not None:
                trainData = self.addDelay(X, delay=self.delay, skip=self.skip,
                                          subsample=self.partsTrain,start=startingPoint, jump=self.jump)
            else:
                trainData = self.addDelay(X, delay=self.delay, skip=self.skip,
                                          subsample=self.partsTrain,start=startingPoint)
                                         
            if self.isCNN:
                trainData = trainData.reshape((trainData.shape[0],1,trainData.shape[1],1))
            targets = y[startingPoint::self.partsTrain]
            
            trainData = trainData[::self.subsample]
            targets = targets[::self.subsample]
            
            self.model.fit(trainData, targets, nb_epoch=self.smallEpochs, 
                           batch_size=512,verbose=0,show_accuracy=True)
            
            trainData=None
            
            pbar.update(majorEpoch)
            
            if self.verbose and majorEpoch%self.checkEveryEpochs == 0:
                print("Total epochs: %d" % (self.smallEpochs*(majorEpoch+1)))
                if Xtest is not None and ytest is not None:
                    pred = self._predict_proba_train(Xtest)
                    score = np.mean(roc_auc_score(ytest[0::self.partsTest],pred))
                    print("Test AUC : %.5f" % (score))
                    pred = None
        
        if self.verbose:
            print('Training finished after %d epochs'% (self.smallEpochs*(majorEpoch+1)))
dataset/ETHPy150Open alexandrebarachant/Grasp-and-lift-EEG-challenge/ensembling/NeuralNet.py/NeuralNet.fit/original