You are viewing documentation about an older version (1.0.9). View latest version

snowflake.ml.modeling.decomposition.PCAΒΆ

class snowflake.ml.modeling.decomposition.PCA(*, n_components=None, copy=True, whiten=False, svd_solver='auto', tol=0.0, iterated_power='auto', n_oversamples=10, power_iteration_normalizer='auto', random_state=None, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)ΒΆ

Bases: BaseTransformer

Principal component analysis (PCA) For more details on this class, see sklearn.decomposition.PCA

n_components: int, float or β€˜mle’, default=None

Number of components to keep. if n_components is not set all components are kept:

n_components == min(n_samples, n_features)
Copy

If n_components == 'mle' and svd_solver == 'full', Minka’s MLE is used to guess the dimension. Use of n_components == 'mle' will interpret svd_solver == 'auto' as svd_solver == 'full'.

If 0 < n_components < 1 and svd_solver == 'full', select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components.

If svd_solver == 'arpack', the number of components must be strictly less than the minimum of n_features and n_samples.

Hence, the None case results in:

n_components == min(n_samples, n_features) - 1
Copy
copy: bool, default=True

If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.

whiten: bool, default=False

When True (False by default) the components_ vectors are multiplied by the square root of n_samples and then divided by the singular values to ensure uncorrelated outputs with unit component-wise variances.

Whitening will remove some information from the transformed signal (the relative variance scales of the components) but can sometime improve the predictive accuracy of the downstream estimators by making their data respect some hard-wired assumptions.

svd_solver: {β€˜auto’, β€˜full’, β€˜arpack’, β€˜randomized’}, default=’auto’
If auto :

The solver is selected by a default policy based on X.shape and n_components: if the input data is larger than 500x500 and the number of components to extract is lower than 80% of the smallest dimension of the data, then the more efficient β€˜randomized’ method is enabled. Otherwise the exact full SVD is computed and optionally truncated afterwards.

If full :

run exact full SVD calling the standard LAPACK solver via scipy.linalg.svd and select the components by postprocessing

If arpack :

run SVD truncated to n_components calling ARPACK solver via scipy.sparse.linalg.svds. It requires strictly 0 < n_components < min(X.shape)

If randomized :

run randomized SVD by the method of Halko et al.

tol: float, default=0.0

Tolerance for singular values computed by svd_solver == β€˜arpack’. Must be of range [0.0, infinity).

iterated_power: int or β€˜auto’, default=’auto’

Number of iterations for the power method computed by svd_solver == β€˜randomized’. Must be of range [0, infinity).

n_oversamples: int, default=10

This parameter is only relevant when svd_solver=”randomized”. It corresponds to the additional number of random vectors to sample the range of X so as to ensure proper conditioning. See randomized_svd() for more details.

power_iteration_normalizer: {β€˜auto’, β€˜QR’, β€˜LU’, β€˜none’}, default=’auto’

Power iteration normalizer for randomized SVD solver. Not used by ARPACK. See randomized_svd() for more details.

random_state: int, RandomState instance or None, default=None

Used when the β€˜arpack’ or β€˜randomized’ solvers are used. Pass an int for reproducible results across multiple function calls. See Glossary.

input_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols and sample-weight_col parameters are considered input columns.

label_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that contain labels. This is a required param for estimators, as there is no way to infer these columns. If this parameter is not specified, then object is fitted without labels(Like a transformer).

output_cols: Optional[Union[str, List[str]]]

A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols mus match the expected number of output columns from the specific estimator or transformer class used. If this parameter is not specified, output column names are derived by adding an OUTPUT_ prefix to the label column names. These inferred output column names work for estimator’s predict() method, but output_cols must be set explicitly for transformers.

sample_weight_col: Optional[str]

A string representing the column name containing the examples’ weights. This argument is only required when working with weighted datasets.

drop_input_cols: Optional[bool], default=False

If set, the response of predict(), transform() methods will not contain input columns.

Methods

fit(dataset)

Fit the model with X For more details on this function, see sklearn.decomposition.PCA.fit

score(dataset)

Return the average log-likelihood of all samples For more details on this function, see sklearn.decomposition.PCA.score

set_input_cols(input_cols)

Input columns setter.

to_sklearn()

Get sklearn.decomposition.PCA object.

transform(dataset)

Apply dimensionality reduction to X For more details on this function, see sklearn.decomposition.PCA.transform

Attributes

model_signatures

Returns model signature of current class.