shnitsel.core.postprocess.pca

pca(da, dim, n_components=2, return_pca_object=False)

xarray-oriented wrapper around scikit-learn’s PCA

Parameters:
  • da (DataArray) – A DataArray with at least a dimension with a name matching dim

  • dim (str) – The name of the dimension to reduce

  • n_components (int) – The number of principle components to return, by default 2

  • optional – The number of principle components to return, by default 2

  • return_pca_object (bool) – Whether to return the scikit-learn PCA object as well as the transformed data, by default False

  • optional – Whether to return the scikit-learn PCA object as well as the transformed data, by default False

Returns:

  • pca_res – A DataArray with the same dimensions as da, except for the dimension indicated by dim, which is replaced by a dimension PC of size n_components

  • [pca_object] – The trained PCA object produced by scikit-learn, if return_pca_object=True

Return type:

tuple[DataArray, PCA] | DataArray