code: def fit(self, X, y):
        
        X, y = self._prepare_inputs(X, y, y_numeric=True,
                                    ensure_min_samples=2)
        n, d = X.shape
        if y.shape[0] != n:
            raise ValueError('Data and label lengths mismatch: %d != %d'
                             % (n, y.shape[0]))
  
        A = self.A0
        m = self.num_dims
        if m is None:
            m = d
        if A is None:
            # initialize to PCA transformation matrix
            # note: not the same as n_components=m !
            A = PCA().fit(X).components_.T[:m]
        elif A.shape != (m, d):
            raise ValueError('A0 needs shape (%d,%d) but got %s' % (
                m, d, A.shape))
  
        # Measure the total training time
        train_time = time.time()
  
        self.n_iter_ = 0
        res = minimize(self._loss, A.ravel(), (X, y), method='L-BFGS-B',
                       jac=True, tol=self.tol,
                       options=dict(maxiter=self.max_iter))
        self.transformer_ = res.x.reshape(A.shape)
  
        # Stop timer
        train_time = time.time() - train_time
        if self.verbose:
            cls_name = self.__class__.__name__
            # Warn the user if the algorithm did not converge
            if not res.success:
                warnings.warn('[{}] MLKR did not converge: {}'
                              .format(cls_name, res.message), ConvergenceWarning)
            print('[{}] Training took {:8.2f}s.'.format(cls_name, train_time))
  
        return self
docs: Fit MLKR model
  
        Parameters
        ----------
        X : (n x d) array of samples
        y : (n) data labels