glance.clustering package

Submodules

humancompatible.explain.glance.clustering.kmeans module

class humancompatible.explain.glance.clustering.kmeans.KMeansMethod(num_clusters, random_seed)[source]

Bases: ClusteringMethod

Implementation of a clustering method using KMeans.

This class provides an interface to apply KMeans clustering to a dataset.

Initializes the KMeansMethod class.

Parameters:

num_clustersint

The number of clusters to form as well as the number of centroids to generate.

random_seedint

A seed for the random number generator to ensure reproducibility.

fit(data)[source]

Fits the KMeans model on the provided dataset.

Parameters:

dataarray-like or sparse matrix, shape (n_samples, n_features)

Training instances to cluster.

Returns:

None

predict(instances)[source]

Predicts the nearest cluster each sample in the provided data belongs to.

Parameters:

instancesarray-like or sparse matrix, shape (n_samples, n_features)

New data to predict.

Returns:

labelsarray, shape (n_samples,)

Index of the cluster each sample belongs to.

Module contents