Kmedoids

class PAsampling.wrappers.Kmedoids(b_samples, init='k-medoids++', metric='euclidean', random_state=None, max_iter=300)[source]

Implements the KMedoids function from the sklearn_extra library (https://scikit-learn-extra.readthedocs.io/en/stable/generated/sklearn_extra.cluster.KMedoids.html).

This class provides a wrapper around the KMedoids function, allowing for the selection of a subset of samples from a dataset based on the k-medoids clustering strategy. The selection can be performed using different initialization methods and distance metrics.

Attributes:

b_samplesint

The number of samples to select (i.e., the number of clusters).

initstr, optional (default=’k-medoids++’)

The method for initialization. Options are are ‘random’, ‘heuristic’, ‘k-medoids++’, and ‘build’.

metricstr, optional (default=’euclidean’)

What distance metric to use. See sklearn.metrics.pairwise_distances metrics. Metric can be ‘precomputed’, the user must then feed the fit method with a precomputed kernel matrix and not the design matrix X.

random_stateint, optional (default=None)

The seed used by the random number generator.

fit(X)[source]

Fits the kmedoids function to the data matrix X and returns the indices of the selected samples (medoids).

Parameters:

Xnumpy.ndarray

Input data matrix, representing a set of data points with shape (n_samples, n_features). If metric is precomputed, X is expected to be the matrix of precomputed pairwise distances.

Returns:

sampleslist

List of indices representing the selected points using the kmedoids algorithm