Documentation
Classes
BisectingKMeans

BisectingKMeans

Bisecting K-Means clustering.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new BisectingKMeans(opts?: object): BisectingKMeans;

Parameters

NameTypeDescription
opts?object-
opts.algorithm?"lloyd" | "elkan"Inner K-means algorithm used in bisection. The classical EM-style algorithm is "lloyd". The "elkan" variation can be more efficient on some datasets with well-defined clusters, by using the triangle inequality. However it’s more memory intensive due to the allocation of an extra array of shape (n\_samples, n\_clusters). Default Value 'lloyd'
opts.bisecting_strategy?"biggest_inertia" | "largest_cluster"Defines how bisection should be performed: Default Value 'biggest_inertia'
opts.copy_x?booleanWhen pre-computing distances it is more numerically accurate to center the data first. If copy_x is true (default), then the original data is not modified. If false, the original data is modified, and put back before the function returns, but small numerical differences may be introduced by subtracting and then adding the data mean. Note that if the original data is not C-contiguous, a copy will be made even if copy_x is false. If the original data is sparse, but not in CSR format, a copy will be made even if copy_x is false. Default Value true
opts.init?"k-means++" | "random"Method for initialization: ‘k-means++’ : selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. See section Notes in k_init for more details. ‘random’: choose n\_clusters observations (rows) at random from data for the initial centroids. If a callable is passed, it should take arguments X, n_clusters and a random state and return an initialization. Default Value 'random'
opts.max_iter?numberMaximum number of iterations of the inner k-means algorithm at each bisection. Default Value 300
opts.n_clusters?numberThe number of clusters to form as well as the number of centroids to generate. Default Value 8
opts.n_init?numberNumber of time the inner k-means algorithm will be run with different centroid seeds in each bisection. That will result producing for each bisection best output of n_init consecutive runs in terms of inertia. Default Value 1
opts.random_state?numberDetermines random number generation for centroid initialization in inner K-Means. Use an int to make the randomness deterministic. See Glossary.
opts.tol?numberRelative tolerance with regards to Frobenius norm of the difference in the cluster centers of two consecutive iterations to declare convergence. Used in inner k-means algorithm at each bisection to pick best possible clusters. Default Value 0.0001
opts.verbose?numberVerbosity mode. Default Value 0

Returns

BisectingKMeans

Defined in: generated/cluster/BisectingKMeans.ts:23 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/cluster/BisectingKMeans.ts:21 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/cluster/BisectingKMeans.ts:20 (opens in a new tab)

_py

PythonBridge

Defined in: generated/cluster/BisectingKMeans.ts:19 (opens in a new tab)

id

string

Defined in: generated/cluster/BisectingKMeans.ts:16 (opens in a new tab)

opts

any

Defined in: generated/cluster/BisectingKMeans.ts:17 (opens in a new tab)

Accessors

cluster_centers_

Coordinates of cluster centers. If the algorithm stops before fully converging (see tol and max\_iter), these will not be consistent with labels\_.

Signature

cluster_centers_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/cluster/BisectingKMeans.ts:517 (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/BisectingKMeans.ts:617 (opens in a new tab)

inertia_

Sum of squared distances of samples to their closest cluster center, weighted by the sample weights if provided.

Signature

inertia_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/BisectingKMeans.ts:567 (opens in a new tab)

labels_

Labels of each point.

Signature

labels_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/cluster/BisectingKMeans.ts:542 (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/BisectingKMeans.ts:592 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/cluster/BisectingKMeans.ts:102 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/cluster/BisectingKMeans.ts:106 (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/BisectingKMeans.ts:163 (opens in a new tab)

fit()

Compute bisecting k-means clustering.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining instances to cluster.
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/cluster/BisectingKMeans.ts:180 (opens in a new tab)

fit_predict()

Compute cluster centers and predict cluster index for each sample.

Convenience method; equivalent to calling fit(X) followed by predict(X).

Signature

fit_predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data to transform.
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<ArrayLike>

Defined in: generated/cluster/BisectingKMeans.ts:229 (opens in a new tab)

fit_transform()

Compute clustering and transform X to cluster-distance space.

Equivalent to fit(X).transform(X), but more efficiently implemented.

Signature

fit_transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data to transform.
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<ArrayLike[]>

Defined in: generated/cluster/BisectingKMeans.ts:278 (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/BisectingKMeans.ts:327 (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/BisectingKMeans.ts:115 (opens in a new tab)

predict()

Predict which cluster each sample in X belongs to.

Prediction is made by going down the hierarchical tree in searching of closest leaf cluster.

In the vector quantization literature, cluster\_centers\_ is called the code book and each value returned by predict is the index of the closest code in the code book.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data to predict.

Returns

Promise<ArrayLike>

Defined in: generated/cluster/BisectingKMeans.ts:367 (opens in a new tab)

score()

Opposite of the value of X on the K-means objective.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data.
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight.
opts.y?anyNot used, present here for API consistency by convention.

Returns

Promise<number>

Defined in: generated/cluster/BisectingKMeans.ts:400 (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/BisectingKMeans.ts:449 (opens in a new tab)

transform()

Transform X to a cluster-distance space.

In the new space, each dimension is the distance to the cluster centers. Note that even if X is sparse, the array returned by transform will typically be dense.

Signature

transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data to transform.

Returns

Promise<ArrayLike[]>

Defined in: generated/cluster/BisectingKMeans.ts:484 (opens in a new tab)