Birch
Implements the BIRCH clustering algorithm.
It is a memory-efficient, online-learning algorithm provided as an alternative to 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 AgglomerativeClustering
.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new Birch(opts?: object): Birch;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.branching_factor? | number | 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. Default Value 50 |
opts.compute_labels? | boolean | Whether or not to compute labels for each fit. Default Value true |
opts.copy? | boolean | Whether or not to make a copy of the given data. If set to false , the initial data will be overwritten. Default Value true |
opts.n_clusters? | number | Number of clusters after the final clustering step, which treats the subclusters from the leaves as new samples. Default Value 3 |
opts.threshold? | number | 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. Default Value 0.5 |
Returns
Defined in: generated/cluster/Birch.ts:25 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/cluster/Birch.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/cluster/Birch.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/cluster/Birch.ts:21 (opens in a new tab)
id
string
Defined in: generated/cluster/Birch.ts:18 (opens in a new tab)
opts
any
Defined in: generated/cluster/Birch.ts:19 (opens in a new tab)
Accessors
dummy_leaf_
Start pointer to all the leaves.
Signature
dummy_leaf_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:465 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:583 (opens in a new tab)
labels_
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.
Signature
labels_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:538 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/cluster/Birch.ts:560 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/cluster/Birch.ts:65 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/cluster/Birch.ts:69 (opens in a new tab)
root_
Root of the CFTree.
Signature
root_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:443 (opens in a new tab)
subcluster_centers_
Centroids of all subclusters read directly from the leaves.
Signature
subcluster_centers_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:488 (opens in a new tab)
subcluster_labels_
Labels assigned to the centroids of the subclusters after they are clustered globally.
Signature
subcluster_labels_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:513 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/cluster/Birch.ts:123 (opens in a new tab)
fit()
Build a CF Tree for the input data.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. |
opts.y? | any | Not used, present here for API consistency by convention. |
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:140 (opens in a new tab)
fit_predict()
Perform clustering on X
and returns cluster labels.
Signature
fit_predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input data. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:178 (opens in a new tab)
fit_transform()
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit\_params
and returns a transformed version of X
.
Signature
fit_transform(opts: object): Promise<any[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input samples. |
opts.fit_params? | any | Additional fit parameters. |
opts.y? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns
Promise
<any
[]>
Defined in: generated/cluster/Birch.ts:218 (opens in a new tab)
get_feature_names_out()
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"\]
.
Signature
get_feature_names_out(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.input_features? | any | Only used to validate feature names with the names seen in fit . |
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:267 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/cluster/Birch.ts:78 (opens in a new tab)
partial_fit()
Online learning. Prevents rebuilding of CFTree from scratch.
Signature
partial_fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. If X is not provided, only the global clustering step is done. |
opts.y? | any | Not used, present here for API consistency by convention. |
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:300 (opens in a new tab)
predict()
Predict data using the centroids\_
of subclusters.
Avoid computation of the row norms of X.
Signature
predict(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. |
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:340 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/cluster/Birch.ts:375 (opens in a new tab)
transform()
Transform X into subcluster centroids dimension.
Each dimension represents the distance from the sample point to each cluster centroid.
Signature
transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. |
Returns
Promise
<ArrayLike
>
Defined in: generated/cluster/Birch.ts:410 (opens in a new tab)