package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `Birch
]
type t = [ `BaseEstimator | `Birch | `ClusterMixin | `Object | `TransformerMixin ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_transformer : t -> [ `TransformerMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val as_cluster : t -> [ `ClusterMixin ] Obj.t
val create : ?threshold:float -> ?branching_factor:int -> ?n_clusters: [ `None | `I of int | `ClusterMixin of [> `ClusterMixin ] Np.Obj.t ] -> ?compute_labels:bool -> ?copy:bool -> unit -> t

Implements the Birch clustering algorithm.

It is a memory-efficient, online-learning algorithm provided as an alternative to :class:`MiniBatchKMeans`. 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 :class:`AgglomerativeClustering`.

Read more in the :ref:`User Guide <birch>`.

.. versionadded:: 0.16

Parameters ---------- threshold : float, default=0.5 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, 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.
  • :mod:`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.
  • `int` : the model fit is :class:`AgglomerativeClustering` with `n_clusters` set to be equal to the int.

compute_labels : bool, default=True Whether or not to compute labels for each fit.

copy : bool, default=True Whether or not to make a copy of the given data. If set to False, the initial data will be overwritten.

Attributes ---------- root_ : _CFNode Root of the CFTree.

dummy_leaf_ : _CFNode Start pointer to all the leaves.

subcluster_centers_ : ndarray Centroids of all subclusters read directly from the leaves.

subcluster_labels_ : ndarray Labels assigned to the centroids of the subclusters after they are clustered globally.

labels_ : ndarray of shape (n_samples,) Array of labels assigned to the input data. if partial_fit is used instead of fit, they are assigned to the last batch of data.

See Also --------

MiniBatchKMeans Alternative implementation that does incremental updates of the centers' positions using mini-batches.

Notes ----- 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.

References ---------- * Tian Zhang, Raghu Ramakrishnan, Maron Livny BIRCH: An efficient data clustering method for large databases. https://www.cs.sfu.ca/CourseCentral/459/han/papers/zhang96.pdf

* Roberto Perdisci JBirch - Java implementation of BIRCH clustering algorithm https://code.google.com/archive/p/jbirch

Examples -------- >>> from sklearn.cluster import Birch >>> X = [0, 1], [0.3, 1], [-0.3, 1], [0, -1], [0.3, -1], [-0.3, -1] >>> brc = Birch(n_clusters=None) >>> brc.fit(X) Birch(n_clusters=None) >>> brc.predict(X) array(0, 0, 0, 1, 1, 1)

val fit : ?y:Py.Object.t -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> t

Build a CF Tree for the input data.

Parameters ---------- 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.

val fit_predict : ?y:Py.Object.t -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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.

Returns ------- labels : ndarray of shape (n_samples,) Cluster labels.

val fit_transform : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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, sparse matrix, dataframe of shape (n_samples, n_features)

y : ndarray of shape (n_samples,), default=None Target values.

**fit_params : dict Additional fit parameters.

Returns ------- X_new : ndarray array of shape (n_samples, n_features_new) Transformed array.

val get_params : ?deep:bool -> [> tag ] Obj.t -> Dict.t

Get parameters for this estimator.

Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns ------- params : mapping of string to any Parameter names mapped to their values.

val partial_fit : ?x:[> `ArrayLike ] Np.Obj.t -> ?y:Py.Object.t -> [> tag ] Obj.t -> t

Online learning. Prevents rebuilding of CFTree from scratch.

Parameters ---------- X : array-like, sparse matrix of shape (n_samples, n_features), default=None Input data. If X is not provided, only the global clustering step is done.

y : Ignored Not used, present here for API consistency by convention.

Returns ------- self Fitted estimator.

val predict : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Predict data using the ``centroids_`` of subclusters.

Avoid computation of the row norms of X.

Parameters ---------- X : array-like, sparse matrix of shape (n_samples, n_features) Input data.

Returns ------- labels : ndarray of shape(n_samples,) Labelled data.

val set_params : ?params:(string * Py.Object.t) list -> [> tag ] Obj.t -> t

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). 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 : object Estimator instance.

val transform : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

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) Transformed data.

val root_ : t -> Py.Object.t

Attribute root_: get value or raise Not_found if None.

val root_opt : t -> Py.Object.t option

Attribute root_: get value as an option.

val dummy_leaf_ : t -> Py.Object.t

Attribute dummy_leaf_: get value or raise Not_found if None.

val dummy_leaf_opt : t -> Py.Object.t option

Attribute dummy_leaf_: get value as an option.

val subcluster_centers_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute subcluster_centers_: get value or raise Not_found if None.

val subcluster_centers_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute subcluster_centers_: get value as an option.

val subcluster_labels_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute subcluster_labels_: get value or raise Not_found if None.

val subcluster_labels_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute subcluster_labels_: get value as an option.

val labels_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute labels_: get value or raise Not_found if None.

val labels_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute labels_: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.