gemseo.mlearning.transformers.dimension_reduction.pca module#

The Principal Component Analysis (PCA) to reduce the dimension of a variable.

The PCA class wraps the PCA from Scikit-learn.

Dependence#

This dimension reduction algorithm relies on the PCA class of the scikit-learn library.

class PCA(name='', n_components=None, scale=False, **parameters)[source]#

Bases: BaseDimensionReduction

Principal component dimension reduction algorithm.

Parameters:
  • name (str) --

    A name for this transformer.

    By default it is set to "".

  • n_components (int | None) -- The number of components of the latent space. If None, use the maximum number allowed by the technique, typically min(n_samples, n_features).

  • scale (bool) --

    Whether to scale the data before applying the PCA.

    By default it is set to False.

  • **parameters (float | str | bool | None) -- The optional parameters for sklearn PCA constructor.

compute_jacobian(data, *args, **kwargs)#

Force a NumPy array to be at least 2D and evaluate the function f.

f expects a 2D array shaped as (n_points, input_dimension) and returns a nD arrays shaped as (..., n_points, output_dimension) or (..., n_points, output_dimension, input_dimension).

If the original data is a 1D array shaped as (input_dimension,), then this wrapper returns a (n-1)D array shaped as (..., output_dimension) or (..., output_dimension, intput_dimension).

Parameters:
  • data (ndarray) -- A NumPy array.

  • *args (Any) -- The positional arguments.

  • **kwargs (Any) -- The optional arguments.

Returns:

Any kind of output; if a NumPy array, its dimension is made consistent with the shape of data.

Return type:

Any

compute_jacobian_inverse(data, *args, **kwargs)#

Force a NumPy array to be at least 2D and evaluate the function f.

f expects a 2D array shaped as (n_points, input_dimension) and returns a nD arrays shaped as (..., n_points, output_dimension) or (..., n_points, output_dimension, input_dimension).

If the original data is a 1D array shaped as (input_dimension,), then this wrapper returns a (n-1)D array shaped as (..., output_dimension) or (..., output_dimension, intput_dimension).

Parameters:
  • data (ndarray) -- A NumPy array.

  • *args (Any) -- The positional arguments.

  • **kwargs (Any) -- The optional arguments.

Returns:

Any kind of output; if a NumPy array, its dimension is made consistent with the shape of data.

Return type:

Any

inverse_transform(data, *args, **kwargs)#

Force a NumPy array to be at least 2D and evaluate the function f.

f expects a 2D array shaped as (n_points, input_dimension) and returns a nD arrays shaped as (..., n_points, output_dimension) or (..., n_points, output_dimension, input_dimension).

If the original data is a 1D array shaped as (input_dimension,), then this wrapper returns a (n-1)D array shaped as (..., output_dimension) or (..., output_dimension, intput_dimension).

Parameters:
  • data (ndarray) -- A NumPy array.

  • *args (Any) -- The positional arguments.

  • **kwargs (Any) -- The optional arguments.

Returns:

Any kind of output; if a NumPy array, its dimension is made consistent with the shape of data.

Return type:

Any

transform(data, *args, **kwargs)#

Force a NumPy array to be at least 2D and evaluate the function f.

f expects a 2D array shaped as (n_points, input_dimension) and returns a nD arrays shaped as (..., n_points, output_dimension) or (..., n_points, output_dimension, input_dimension).

If the original data is a 1D array shaped as (input_dimension,), then this wrapper returns a (n-1)D array shaped as (..., output_dimension) or (..., output_dimension, intput_dimension).

Parameters:
  • data (ndarray) -- A NumPy array.

  • *args (Any) -- The positional arguments.

  • **kwargs (Any) -- The optional arguments.

Returns:

Any kind of output; if a NumPy array, its dimension is made consistent with the shape of data.

Return type:

Any

property components: RealArray#

The principal components.

property data_is_scaled: bool#

Whether the transformer scales the data before reducing its dimension.