(self, num_epochs=3, batch_size=32)
return batch_losses
Trains the LR model.

        :param num_epochs: (int) number of epochs.
Trains the LR model.
Trains the LR model .
def train(self, num_epochs=3, batch_size=32):
        """
        Trains the LR model.

        :param num_epochs: (int) number of epochs.
        """
        batch_losses = []
        # We train only on cells that do not have their initial value as NULL.
        X_train, Y_train = self._X.index_select(0, self._train_idx), self._Y.index_select(0, self._train_idx)
        torch_ds = TensorDataset(X_train, Y_train)

        # Main training loop.
        for epoch_idx in range(1, num_epochs+1):
            logging.debug("Logistic: epoch %d", epoch_idx)
            batch_cnt = 0
            for batch_X, batch_Y in tqdm(DataLoader(torch_ds, batch_size=batch_size)):
                batch_pred = self.forward(batch_X)
                batch_loss = self._loss(batch_pred, batch_Y.reshape(-1,1))
                batch_losses.append(float(batch_loss))
                self.zero_grad()
                batch_loss.backward()
                self._optimizer.step()
                batch_cnt += 1
            logging.debug('Logistic: average batch loss: %f', sum(batch_losses[-1 * batch_cnt:]) / batch_cnt)
        return batch_losses
def train ( self , num_epochs = 3 , batch_size = 32 ) : batch_losses = [ ] # We train only on cells that do not have their initial value as NULL. X_train , Y_train = self . _X . index_select ( 0 , self . _train_idx ) , self . _Y . index_select ( 0 , self . _train_idx ) torch_ds = TensorDataset ( X_train , Y_train ) # Main training loop. for epoch_idx in range ( 1 , num_epochs + 1 ) : logging . debug ( "Logistic: epoch %d" , epoch_idx ) batch_cnt = 0 for batch_X , batch_Y in tqdm ( DataLoader ( torch_ds , batch_size = batch_size ) ) : batch_pred = self . forward ( batch_X ) batch_loss = self . _loss ( batch_pred , batch_Y . reshape ( - 1 , 1 ) ) batch_losses . append ( float ( batch_loss ) ) self . zero_grad ( ) batch_loss . backward ( ) self . _optimizer . step ( ) batch_cnt += 1 logging . debug ( 'Logistic: average batch loss: %f' , sum ( batch_losses [ - 1 * batch_cnt : ] ) / batch_cnt ) return batch_losses