pyriemann.clustering.KmeansPerClassTransform

class pyriemann.clustering.KmeansPerClassTransform(**params)[source]

Clustering by k-means for each class with SPD/HPD matrices as inputs.

Parameters:
**paramsdict

The keyword arguments passed to pyriemann.clustering.Kmeans. They default to the defaults of pyriemann.clustering.Kmeans, and are exposed by get_params() and set_params() so that the estimator can be cloned and used in a scikit-learn search.

Attributes:
classes_ndarray, shape (n_classes,)

Labels for each class.

covmeans_ndarray, shape (n_centroids, n_channels, n_channels)

Centroids of each cluster of each class, with n_centroids <= n_clusters x n_classes.

See also

Kmeans

Notes

Added in version 0.2.

Changed in version 0.8: Add support for HPD matrices.

Changed in version 0.13: Store the parameters so that get_params(), set_params() and clone() work.

__init__(**params)[source]

Init.

fit(X, y)[source]

Fit the clusters for each class.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_channels)

Set of SPD/HPD matrices.

yndarray, shape (n_matrices,)

Labels corresponding to each matrix.

Returns:
selfKmeansPerClassTransform instance

The KmeansPerClassTransform instance.

fit_transform(X, y=None, sample_weight=None)

Fit and transform in a single function.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_channels)

Set of SPD matrices.

yNone | ndarray, shape (n_matrices,), default=None

Labels for each matrix.

sample_weightNone | ndarray, shape (n_matrices,), default=None

Weights for each matrix. If None, it uses equal weights.

Returns:
distndarray, shape (n_matrices, n_centroids)

Distance to each centroid.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]

Get the parameters passed to pyriemann.clustering.Kmeans.

Parameters:
deepbool, default=True

Unused, kept for scikit-learn compatibility.

Returns:
paramsdict

Parameter names mapped to their values.

set_output(*, transform=None)

Set output container.

Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]

Set the parameters passed to pyriemann.clustering.Kmeans.

Parameters:
**paramsdict

Parameters to set.

Returns:
selfKmeansPerClassTransform instance

The KmeansPerClassTransform instance.

transform(X)[source]

Get the distance to each centroid.

Parameters:
Xndarray, shape (n_matrices, n_channels, n_channels)

Set of SPD/HPD matrices.

Returns:
distndarray, shape (n_matrices, n_centroids)

Distance to each centroid according to the metric.