def fit(self, X, y, instances):
    test_instances = instances['test']
    validation_instances = instances['validation']
    train_instances = instances['train']
    time_ = 0
    self.model_time = 0
    n_train = X.shape[0]
    if self.validation:
        validation_list = []
    indexes = np.arange(n_train)
    loss_fn = nn.MSELoss()
    for e in range(self.epochs):
        start_time = time.time()
        np.random.shuffle(indexes)
        num_batches = (len(indexes) // self.batchsize)
        bi = 0
        for b in range(num_batches):
            self.optimizer.zero_grad()
            X_np = X[indexes[bi:(bi + self.batchsize)]]
            y_np = y[indexes[bi:(bi + self.batchsize)]]
            bi += self.batchsize
            X_torch = torch.from_numpy(X_np).float()
            y_torch = torch.from_numpy(y_np).float()
            c_pred = self.net(X_torch).squeeze()
            loss = loss_fn(c_pred, y_torch)
            loss.backward()
            self.optimizer.step()
        end_time = time.time()
        time_ += (end_time - start_time)
        if self.validation:
            validation_list.append(validation_module(self.net, self.A, X, y, train_instances, validation_instances, test_instances, time_, e, b))
        print('Epoch {} Loss:{} Time: {:%Y-%m-%d %H:%M:%S}'.format((e + 1), loss.sum().item(), datetime.datetime.now()))
    if self.validation:
        dd = defaultdict(list)
        for d in validation_list:
            for (key, value) in d.items():
                dd[key].append(value)
        df = pd.DataFrame.from_dict(dd)
        logging.info(('Completion Time %s \n' % str(datetime.datetime.now())))
        return df
def fit(self, X, y, instances):
    test_instances = instances['test']
    validation_instances = instances['validation']
    train_instances = instances['train']
    time_ = 0
    self.model_time = 0
    n_train = X.shape[0]
    if self.validation:
        validation_list = []
    indexes = np.arange(n_train)
    loss_fn = nn.MSELoss()
    for e in range(self.epochs):
        start_time = time.time()
        np.random.shuffle(indexes)
        num_batches = (len(indexes) // self.batchsize)
        bi = 0
        for b in range(num_batches):
            self.optimizer.zero_grad()
            X_np = X[indexes[bi:(bi + self.batchsize)]]
            y_np = y[indexes[bi:(bi + self.batchsize)]]
            bi += self.batchsize
            X_torch = torch.from_numpy(X_np).float()
            y_torch = torch.from_numpy(y_np).float()
            c_pred = self.net(X_torch).squeeze()
            loss = loss_fn(c_pred, y_torch)
            loss.backward()
            self.optimizer.step()
        end_time = time.time()
        time_ += (end_time - start_time)
        if self.validation:
            validation_list.append(validation_module(self.net, self.A, X, y, train_instances, validation_instances, test_instances, time_, e, b))
        print('Epoch {} Loss:{} Time: {:%Y-%m-%d %H:%M:%S}'.format((e + 1), loss.sum().item(), datetime.datetime.now()))
    if self.validation:
        dd = defaultdict(list)
        for d in validation_list:
            for (key, value) in d.items():
                dd[key].append(value)
        df = pd.DataFrame.from_dict(dd)
        logging.info(('Completion Time %s \n' % str(datetime.datetime.now())))
        return df