DocumentationClassesMiniBatchKMeans

Class: MiniBatchKMeans

Mini-Batch K-Means clustering.

Read more in the User Guide.

Python Reference

Constructors

new MiniBatchKMeans()

new MiniBatchKMeans(opts?): MiniBatchKMeans

Parameters

ParameterTypeDescription
opts?object-
opts.batch_size?numberSize of the mini batches. For faster computations, you can set the batch_size greater than 256 * number of cores to enable parallelism on all cores.
opts.compute_labels?booleanCompute label assignment and inertia for the complete dataset once the minibatch optimization has converged in fit.
opts.init?ArrayLike[] | "k-means++" | "random"Method for initialization: ‘k-means++’ : selects initial cluster centroids using sampling based on an empirical probability distribution of the points’ contribution to the overall inertia. This technique speeds up convergence. The algorithm implemented is “greedy k-means++”. It differs from the vanilla k-means++ by making several trials at each sampling step and choosing the best centroid among them. ‘random’: choose n_clusters observations (rows) at random from data for the initial centroids. If an array is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. If a callable is passed, it should take arguments X, n_clusters and a random state and return an initialization.
opts.init_size?numberNumber of samples to randomly sample for speeding up the initialization (sometimes at the expense of accuracy): the only algorithm is initialized by running a batch KMeans on a random subset of the data. This needs to be larger than n_clusters. If undefined, the heuristic is init_size \= 3 \* batch_size if 3 \* batch_size < n_clusters, else init_size \= 3 \* n_clusters.
opts.max_iter?numberMaximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.
opts.max_no_improvement?numberControl early stopping based on the consecutive number of mini batches that does not yield an improvement on the smoothed inertia. To disable convergence detection based on inertia, set max_no_improvement to undefined.
opts.n_clusters?numberThe number of clusters to form as well as the number of centroids to generate.
opts.n_init?number | "auto"Number of random initializations that are tried. In contrast to KMeans, the algorithm is only run once, using the best of the n_init initializations as measured by inertia. Several runs are recommended for sparse high-dimensional problems (see Clustering sparse data with k-means). When n_init='auto', the number of runs depends on the value of init: 3 if using init='random' or init is a callable; 1 if using init='k-means++' or init is an array-like.
opts.random_state?numberDetermines random number generation for centroid initialization and random reassignment. Use an int to make the randomness deterministic. See Glossary.
opts.reassignment_ratio?numberControl the fraction of the maximum number of counts for a center to be reassigned. A higher value means that low count centers are more easily reassigned, which means that the model will take longer to converge, but should converge in a better clustering. However, too high a value may cause convergence issues, especially with a small batch size.
opts.tol?numberControl early stopping based on the relative center changes as measured by a smoothed, variance-normalized of the mean center squared position changes. This early stopping heuristics is closer to the one used for the batch variant of the algorithms but induces a slight computational and memory overhead over the inertia heuristic. To disable convergence detection based on normalized center change, set tol to 0.0 (default).
opts.verbose?numberVerbosity mode.

Returns MiniBatchKMeans

Defined in generated/cluster/MiniBatchKMeans.ts:23

Properties

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

Accessors

cluster_centers_

Get Signature

get cluster_centers_(): Promise<ArrayLike[]>

Coordinates of cluster centers.

Returns Promise<ArrayLike[]>

Defined in generated/cluster/MiniBatchKMeans.ts:695


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/MiniBatchKMeans.ts:845


inertia_

Get Signature

get inertia_(): Promise<number>

The value of the inertia criterion associated with the chosen partition if compute_labels is set to true. If compute_labels is set to false, it’s an approximation of the inertia based on an exponentially weighted average of the batch inertiae. The inertia is defined as the sum of square distances of samples to their cluster center, weighted by the sample weights if provided.

Returns Promise<number>

Defined in generated/cluster/MiniBatchKMeans.ts:745


labels_

Get Signature

get labels_(): Promise<ArrayLike>

Labels of each point (if compute_labels is set to true).

Returns Promise<ArrayLike>

Defined in generated/cluster/MiniBatchKMeans.ts:720


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/cluster/MiniBatchKMeans.ts:820


n_iter_

Get Signature

get n_iter_(): Promise<number>

Number of iterations over the full dataset.

Returns Promise<number>

Defined in generated/cluster/MiniBatchKMeans.ts:770


n_steps_

Get Signature

get n_steps_(): Promise<number>

Number of minibatches processed.

Returns Promise<number>

Defined in generated/cluster/MiniBatchKMeans.ts:795


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/cluster/MiniBatchKMeans.ts:124

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/MiniBatchKMeans.ts:176


fit()

fit(opts): Promise<any>

Compute the centroids on X by chunking it into mini-batches.

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 or a user provided array.
opts.X?ArrayLikeTraining instances to cluster. It must be noted that the data will be converted to C ordering, which will cause a memory copy if the given data is not C-contiguous. If a sparse matrix is passed, a copy will be made if it’s not in CSR format.
opts.y?anyNot used, present here for API consistency by convention.

Returns Promise<any>

Defined in generated/cluster/MiniBatchKMeans.ts:193


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/MiniBatchKMeans.ts:237


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/MiniBatchKMeans.ts:281


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/MiniBatchKMeans.ts:325


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/MiniBatchKMeans.ts:361


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/MiniBatchKMeans.ts:137


partial_fit()

partial_fit(opts): Promise<any>

Update k means estimate on a single mini-batch X.

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 or a user provided array.
opts.X?ArrayLikeTraining instances to cluster. It must be noted that the data will be converted to C ordering, which will cause a memory copy if the given data is not C-contiguous. If a sparse matrix is passed, a copy will be made if it’s not in CSR format.
opts.y?anyNot used, present here for API consistency by convention.

Returns Promise<any>

Defined in generated/cluster/MiniBatchKMeans.ts:395


predict()

predict(opts): Promise<ArrayLike>

Predict the closest cluster each sample in X belongs to.

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/MiniBatchKMeans.ts:439


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/MiniBatchKMeans.ts:471


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/MiniBatchKMeans.ts:517


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/MiniBatchKMeans.ts:553


set_partial_fit_request()

set_partial_fit_request(opts): Promise<any>

Request metadata passed to the partial_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 partial_fit.

Returns Promise<any>

Defined in generated/cluster/MiniBatchKMeans.ts:589


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/MiniBatchKMeans.ts:627


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/MiniBatchKMeans.ts:663