def fit(self, X, y=None):
        """Fit detector. y is ignored in unsupervised methods.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples.

        y : Ignored
            Not used, present for API consistency by convention.

        Returns
        -------
        self : object
            Fitted estimator.
        """

        # validate inputs X and y (optional)
        X = check_array(X, copy=self.copy_X)
        self._set_n_classes(y)

        # perform subsampling to reduce time complexity
        if self.sampling is True:
            subset_size = self._check_subset_size(X)
            random_indices = self.random_state.choice(
                X.shape[0],
                size=subset_size,
                replace=False,
            )
            X = X[random_indices, :]

        # copy the attributes from the sklearn Kernel PCA object
        if self.n_components is None:
            n_components = X.shape[0]  # use all dimensions
        else:
            if self.n_components < 1:
                raise ValueError(
                    f"`n_components` should be >= 1, got: {self.n_components}"
                )
            n_components = min(X.shape[0], self.n_components)

        # validate the number of components to be used for outlier detection
        if self.n_selected_components is None:
            self.n_selected_components_ = n_components
        else:
            self.n_selected_components_ = self.n_selected_components
        check_parameter(
            self.n_selected_components_,
            1,
            n_components,
            include_left=True,
            include_right=True,
            param_name="n_selected_components",
        )

        self.kpca = PyODKernelPCA(
            n_components=self.n_components,
            kernel=self.kernel,
            gamma=self.gamma,
            degree=self.degree,
            coef0=self.coef0,
            kernel_params=self.kernel_params,
            alpha=self.alpha,
            fit_inverse_transform=False,
            eigen_solver=self.eigen_solver,
            tol=self.tol,
            max_iter=self.max_iter,
            remove_zero_eig=self.remove_zero_eig,
            copy_X=self.copy_X,
            n_jobs=self.n_jobs,
            random_state=self.random_state,
        )
        x_transformed = self.kpca.fit_transform(X)
        x_transformed = x_transformed[:, : self.n_selected_components_]

        centerer = self.kpca.get_centerer
        kernel = self.kpca.get_kernel

        potential = []
        for i in range(X.shape[0]):
            sample = X[i, :].reshape(1, -1)
            potential.append(kernel(sample))
        potential = np.array(potential).squeeze()
        potential = potential - 2 * centerer.K_fit_rows_ + centerer.K_fit_all_

        # reconstruction error
        self.decision_scores_ = potential - np.sum(np.square(x_transformed),
                                                   axis=1)
        self._process_decision_scores()

        return self
Fit detector. y is ignored in unsupervised methods.

        Parameters
        ----------
        X : numpy array of shape (n_samples, n_features)
            The input samples.

        y : Ignored
            Not used, present for API consistency by convention.

        Returns
        -------
        self : object
            Fitted estimator.
        
pyod/models/kpca.py