Documentation
Classes
Birch

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

NameTypeDescription
opts?object-
opts.branching_factor?numberMaximum 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?booleanWhether or not to compute labels for each fit. Default Value true
opts.copy?booleanWhether 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?numberNumber of clusters after the final clustering step, which treats the subclusters from the leaves as new samples. Default Value 3
opts.threshold?numberThe 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

Birch

Defined in: generated/cluster/Birch.ts:25 (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

NameTypeDescription
optsobject-
opts.X?ArrayLikeInput data.
opts.y?anyNot 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

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Input data.
opts.y?anyNot 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

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Input samples.
opts.fit_params?anyAdditional fit parameters.
opts.y?ArrayLikeTarget 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

NameTypeDescription
optsobject-
opts.input_features?anyOnly 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)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

get_metadata_routing(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns

Promise<any>

Defined in: generated/cluster/Birch.ts:302 (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

NameType
pyPythonBridge

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

NameTypeDescription
optsobject-
opts.X?ArrayLikeInput data. If X is not provided, only the global clustering step is done.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/cluster/Birch.ts:335 (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

NameTypeDescription
optsobject-
opts.X?ArrayLikeInput data.

Returns

Promise<any>

Defined in: generated/cluster/Birch.ts:375 (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

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/cluster/Birch.ts:410 (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

NameTypeDescription
optsobject-
opts.X?ArrayLikeInput data.

Returns

Promise<ArrayLike>

Defined in: generated/cluster/Birch.ts:445 (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:500 (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:618 (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:573 (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:595 (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

NameType
pythonBridgePythonBridge

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:478 (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:523 (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:548 (opens in a new tab)