Skip to main content
Version: 0.5.x

BaseClusterer

Abstract base class for clustering algorithms.

Module: aisp.base
Import: from aisp.base import BaseClusterer


Overview

This class defines the core interface for clustering models. It enforces the implementation of the fit and predict methods in all derived classes, and provides a default implementation for fit_predict and get_params.

Use cases:

  • Abstract base class for extending clustering algorithm classes.

Attributes

NameTypeDefaultDescription
labelsOptional[npt.NDArray]NoneLabels for the clusters generated during model fitting.

Abstract Methods

fit

@abstractmethod
def fit(self, X: Union[npt.NDArray, list], verbose: bool = True) -> BaseClusterer:
...

Train the model using the input data X.
This abstract method is implemented by the class that inherits it.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Training input samples. Each row corresponds to a samples and column to feature.
verboseboolTrueIf True, prints training progress information.

Returns

TypeDescription
SelfReturns the instance of the class that implements this method.

predict

@abstractmethod
def predict(self, X: Union[npt.NDArray, list]) -> npt.NDArray:
...

Generate predictions based on the input data X.
This abstract method is implemented by the class that inherits it.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Input samples. Must have the same number of features used during training.

Returns

TypeDescription
npt.NDArrayPredicted cluster labels for each input sample.

Public Methods

fit_predict

def fit_predict(self, X: Union[npt.NDArray, list], verbose: bool = True) -> npt.NDArray:
...

Fit the clustering model to the data and return cluster labels.

This is a convenience method that combines fit and predict into a single call.

Parameters

NameTypeDefaultDescription
XUnion[npt.NDArray, list]-Training input samples. Each row corresponds to a samples and column to feature.
verboseboolTrueIf True, prints training progress information.

Returns

TypeDescription
npt.NDArrayPredicted cluster labels for each input sample.