DocumentationClassesBisectingKMeans

Class: BisectingKMeans

Bisecting K-Means clustering.

Read more in the User Guide.

Python Reference

Constructors

new BisectingKMeans()

new BisectingKMeans(opts?): BisectingKMeans

Parameters

ParameterTypeDescription
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).
opts.bisecting_strategy?"biggest_inertia" | "largest_cluster"Defines how bisection should be performed:
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.
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.
opts.max_iter?numberMaximum number of iterations of the inner k-means algorithm at each bisection.
opts.n_clusters?numberThe number of clusters to form as well as the number of centroids to generate.
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.
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.
opts.verbose?numberVerbosity mode.

Returns BisectingKMeans

Defined in generated/cluster/BisectingKMeans.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/cluster/BisectingKMeans.ts:21
_isInitializedbooleanfalsegenerated/cluster/BisectingKMeans.ts:20
_pyPythonBridgeundefinedgenerated/cluster/BisectingKMeans.ts:19
idstringundefinedgenerated/cluster/BisectingKMeans.ts:16
optsanyundefinedgenerated/cluster/BisectingKMeans.ts:17

Accessors

cluster_centers_

Get Signature

get cluster_centers_(): Promise<ArrayLike[]>

Coordinates of cluster centers. If the algorithm stops before fully converging (see tol and max_iter), these will not be consistent with labels_.

Returns Promise<ArrayLike[]>

Defined in generated/cluster/BisectingKMeans.ts:595


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/cluster/BisectingKMeans.ts:695


inertia_

Get Signature

get inertia_(): Promise<number>

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

Returns Promise<number>

Defined in generated/cluster/BisectingKMeans.ts:645


labels_

Get Signature

get labels_(): Promise<ArrayLike>

Labels of each point.

Returns Promise<ArrayLike>

Defined in generated/cluster/BisectingKMeans.ts:620


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/cluster/BisectingKMeans.ts:670


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/cluster/BisectingKMeans.ts:102

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/cluster/BisectingKMeans.ts:154


fit()

fit(opts): Promise<any>

Compute bisecting k-means clustering.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight. sample_weight is not used during initialization if init is a callable.
opts.X?ArrayLikeTraining instances to cluster.
opts.y?anyNot used, present here for API consistency by convention.

Returns Promise<any>

Defined in generated/cluster/BisectingKMeans.ts:171


fit_predict()

fit_predict(opts): Promise<ArrayLike>

Compute cluster centers and predict cluster index for each sample.

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

Parameters

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

Returns Promise<ArrayLike>

Defined in generated/cluster/BisectingKMeans.ts:215


fit_transform()

fit_transform(opts): Promise<ArrayLike[]>

Compute clustering and transform X to cluster-distance space.

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

Parameters

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

Returns Promise<ArrayLike[]>

Defined in generated/cluster/BisectingKMeans.ts:259


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

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

ParameterTypeDescription
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:303


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

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

Returns Promise<any>

Defined in generated/cluster/BisectingKMeans.ts:339


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/cluster/BisectingKMeans.ts:115


predict()

predict(opts): Promise<ArrayLike>

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.

Parameters

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

Returns Promise<ArrayLike>

Defined in generated/cluster/BisectingKMeans.ts:377


score()

score(opts): Promise<number>

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

Parameters

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

Returns Promise<number>

Defined in generated/cluster/BisectingKMeans.ts:409


set_fit_request()

set_fit_request(opts): Promise<any>

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/cluster/BisectingKMeans.ts:455


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/cluster/BisectingKMeans.ts:491


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/cluster/BisectingKMeans.ts:527


transform()

transform(opts): Promise<ArrayLike[]>

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.

Parameters

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

Returns Promise<ArrayLike[]>

Defined in generated/cluster/BisectingKMeans.ts:563

Last updated on