def fit(self, X, y):
        np.random.seed(self.random_seed)
        self.cost_ = []
        self.gradient_ = np.array([])
        X_data, y_data = X.copy(), y.copy()

        if self.shuffle_init:
            X_data, y_data = self._shuffle([X_data, y_data])

        y_enc = self._encode_labels(y_data, self.n_output)

        delta_w1_prev = np.zeros(self.w1.shape)
        delta_w2_prev = np.zeros(self.w2.shape)

        self.init_time_ = time()
        for i in range(self.epochs):

            # adaptive learning rate
            self.eta /= (1 + self.decrease_const * i)

            if self.shuffle_epoch:
                idx = np.random.permutation(y_enc.shape[1])
                X_data, y_enc = X_data[idx], y_enc[:, idx]

            mini = np.array_split(range(y_data.shape[0]), self.minibatches)
            for idx in mini:

                # feedforward
                a1, z2, a2, z3, a3 = self._feedforward(X_data[idx],
                                                       self.w1,
                                                       self.w2)
                cost = self._get_cost(y_enc=y_enc[:, idx],
                                      output=a3,
                                      w1=self.w1,
                                      w2=self.w2)
                self.cost_.append(cost)

                # compute gradient via backpropagation
                grad1, grad2 = self._get_gradient(a1=a1, a2=a2,
                                                  a3=a3, z2=z2,
                                                  y_enc=y_enc[:, idx],
                                                  w1=self.w1,
                                                  w2=self.w2)

                # gradient_ attribute used for gradient checking
                self.gradient_ = np.hstack((grad1.flatten(), grad2.flatten()))

                # update weights; [alpha * delta_w_prev] for momentum learning
                delta_w1, delta_w2 = self.eta * grad1, self.eta * grad2
                self.w1 -= (delta_w1 + (self.alpha * delta_w1_prev))
                self.w2 -= (delta_w2 + (self.alpha * delta_w2_prev))
                delta_w1_prev, delta_w2_prev = delta_w1, delta_w2

                if self.print_progress:
                    self._print_progress(epoch=i + 1)

        return self
Learn weight coefficients from training data.
dataset/ETHPy150Open rasbt/mlxtend/mlxtend/classifier/neuralnet_mlp.py/NeuralNetMLP.fit