It is a memory-efficient, online-learning algorithm provided as an
alternative to . It constructs a tree
data structure with the cluster centroids being read off the leaf.
These can be either the final cluster centroids or can be provided as input
to another clustering algorithm such as .
The radius of the subcluster obtained by merging a new sample and the
closest subcluster should be lesser than the threshold. Otherwise a new
subcluster is started. Setting this value to be very low promotes
splitting and vice-versa.
branching_factor : int, default=50
Maximum number of CF subclusters in each node. If a new samples enters
such that the number of subclusters exceed the branching_factor then
that node is split into two nodes with the subclusters redistributed
in each. The parent subcluster of that node is removed and two new
subclusters are added as parents of the 2 split nodes.
n_clusters : int, instance of sklearn.cluster model or None, default=3
Number of clusters after the final clustering step, which treats the
subclusters from the leaves as new samples.
None : the final clustering step is not performed and the
subclusters are returned as they are.
sklearn.cluster Estimator : If a model is provided, the model
is fit treating the subclusters as new samples and the initial data
is mapped to the label of the closest subcluster.
The tree data structure consists of nodes with each node consisting of
a number of subclusters. The maximum number of subclusters in a node
is determined by the branching factor. Each subcluster maintains a
linear sum, squared sum and the number of samples in that subcluster.
In addition, each subcluster can also have a node as its child, if the
subcluster is not a member of a leaf node.
For a new point entering the root, it is merged with the subcluster closest
to it and the linear sum, squared sum and the number of samples of that
subcluster are updated. This is done recursively till the properties of
the leaf node are updated.
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data.
y : Ignored
Not used, present here for API consistency by convention.
Returns:
self
Fitted estimator.
fit_predict(X, y=None, **kwargs)
Perform clustering on X and returns cluster labels.
Parameters:
X : array-like of shape (n_samples, n_features)
Input data.
y : Ignored
Not used, present for API consistency by convention.
**kwargs : dict
Arguments to be passed to fit.
Returns:
labels : ndarray of shape (n_samples,), dtype=np.int64
Cluster labels.
fit_transform(X, y=None, **fit_params)
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.
Parameters:
X : array-like of shape (n_samples, n_features)
Input samples.
y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
**fit_params : dict
Additional fit parameters.
Pass only if the estimator accepts additional params in its fit method.
Returns:
X_new : ndarray array of shape (n_samples, n_features_new)
Transformed array.
get_feature_names_out(input_features=None)
Get output feature names for transformation.
The feature names out will prefixed by the lowercased class name. For
example, if the transformer outputs 3 features, then the feature names
out are: ["class_name0","class_name1","class_name2"].
Parameters:
input_features : array-like of str or None, default=None
Only used to validate feature names with the names seen in fit.
Returns:
feature_names_out : ndarray of str objects
Transformed feature names.
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing
mechanism works.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Parameters:
**params : dict
Estimator parameters.
Returns:
self : estimator instance
Estimator instance.
transform(X)
Transform X into subcluster centroids dimension.
Each dimension represents the distance from the sample point to each
cluster centroid.
Parameters:
X : {array-like, sparse matrix} of shape (n_samples, n_features)
Input data.
Returns:
X_trans : {array-like, sparse matrix} of shape (n_samples, n_clusters)