(self, X)
Dispatch to the right submethod depending on the chosen solver.
Dispatch to the right submethod depending on the chosen solver.
Dispatch to the right submethod depending on the chosen solver .
def _fit(self, X):
        """Dispatch to the right submethod depending on the chosen solver."""
        X = check_array(
            X,
            accept_sparse=["csr", "csc"],
            dtype=[np.float64, np.float32],
            ensure_2d=True,
            copy=self.copy,
        )

        # Handle n_components==None
        if self.n_components is None:
            if self.svd_solver != "arpack":
                n_components = min(X.shape)
            else:
                n_components = min(X.shape) - 1
        else:
            n_components = self.n_components

        # Handle svd_solver
        self._fit_svd_solver = self.svd_solver
        if self._fit_svd_solver == "auto":
            # Sparse data can only be handled with the randomized solver
            if sp.issparse(X):
                self._fit_svd_solver = "randomized"
            # Small problem or n_components == 'mle', just call full PCA
            elif max(X.shape) <= 500 or n_components == "mle":
                self._fit_svd_solver = "full"
            elif 1 <= n_components < .8 * min(X.shape):
                self._fit_svd_solver = "randomized"
            # This is also the case of n_components in (0,1)
            else:
                self._fit_svd_solver = "full"

        # Ensure we don't try call arpack or full on a sparse matrix
        if sp.issparse(X) and self._fit_svd_solver != "randomized":
            raise ValueError("only the randomized solver supports sparse matrices")

        # Call different fits for either full or truncated SVD
        if self._fit_svd_solver == "full":
            return self._fit_full(X, n_components)
        elif self._fit_svd_solver in ["arpack", "randomized"]:
            return self._fit_truncated(X, n_components, self._fit_svd_solver)
        else:
            raise ValueError(
                "Unrecognized svd_solver='{0}'".format(self._fit_svd_solver)
            )
def _fit ( self , X ) : X = check_array ( X , accept_sparse = [ "csr" , "csc" ] , dtype = [ np . float64 , np . float32 ] , ensure_2d = True , copy = self . copy , ) # Handle n_components==None if self . n_components is None : if self . svd_solver != "arpack" : n_components = min ( X . shape ) else : n_components = min ( X . shape ) - 1 else : n_components = self . n_components # Handle svd_solver self . _fit_svd_solver = self . svd_solver if self . _fit_svd_solver == "auto" : # Sparse data can only be handled with the randomized solver if sp . issparse ( X ) : self . _fit_svd_solver = "randomized" # Small problem or n_components == 'mle', just call full PCA elif max ( X . shape ) <= 500 or n_components == "mle" : self . _fit_svd_solver = "full" elif 1 <= n_components < .8 * min ( X . shape ) : self . _fit_svd_solver = "randomized" # This is also the case of n_components in (0,1) else : self . _fit_svd_solver = "full" # Ensure we don't try call arpack or full on a sparse matrix if sp . issparse ( X ) and self . _fit_svd_solver != "randomized" : raise ValueError ( "only the randomized solver supports sparse matrices" ) # Call different fits for either full or truncated SVD if self . _fit_svd_solver == "full" : return self . _fit_full ( X , n_components ) elif self . _fit_svd_solver in [ "arpack" , "randomized" ] : return self . _fit_truncated ( X , n_components , self . _fit_svd_solver ) else : raise ValueError ( "Unrecognized svd_solver='{0}'" . format ( self . _fit_svd_solver ) )