def predict_proba(self, X): loader = _build_data_loader(self.batch_size, X) for idx, x in enumerate(loader): if idx == 0: y_hat = self(x.float()).data.numpy() else: y_hat = np.vstack([y_hat, self(x.float()).data.numpy()]) return y_hat
def fit(self, X, y, epochs=10, loss='mse', learning_rate=1e-3, batch_size=10, solver='adam', verbose=False): self.batch_size = batch_size loader = _build_data_loader(self.batch_size, X, y) opt = OPTIMIZERS[solver](self.parameters(), lr=learning_rate) crit = LOSS_FUNCS[loss] for _ in range(epochs): for x, y in loader: opt.zero_grad() y_hat = self(x.float()) loss = crit(y_hat, y.float()) loss.backward() opt.step()
def fit(self, X, y, epochs=10, loss='crossentropy', learning_rate=1e-3, batch_size=10, optim='adam', verbose=False): self.batch_size = batch_size loader = _build_data_loader(self.batch_size, X, y) opt = OPTIMIZERS[optim](self.parameters(), lr=learning_rate) crit = LOSS_FUNCS[loss] for e in range(epochs): if verbose: print('\rEpoch {}'.format(e + 1), end='') for x, y in loader: opt.zero_grad() y_hat = self(x.float()) loss = crit(y_hat, y.float()) loss.backward() opt.step()