Documentation
Classes
MiniBatchKMeans

MiniBatchKMeans

Mini-Batch K-Means clustering.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new MiniBatchKMeans(opts?: object): MiniBatchKMeans;

Parameters

NameTypeDescription
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. Default Value 1024
opts.compute_labels?booleanCompute label assignment and inertia for the complete dataset once the minibatch optimization has converged in fit. Default Value true
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. Default Value 'k-means++'
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. Default Value 100
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. Default Value 10
opts.n_clusters?numberThe number of clusters to form as well as the number of centroids to generate. Default Value 8
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. Default Value 3
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. Default Value 0.01
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). Default Value 0
opts.verbose?numberVerbosity mode. Default Value 0

Returns

MiniBatchKMeans

Defined in: generated/cluster/MiniBatchKMeans.ts:23 (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/MiniBatchKMeans.ts:191 (opens in a new tab)

fit()

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

Signature

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

Parameters

NameTypeDescription
optsobject-
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.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.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:208 (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/MiniBatchKMeans.ts:257 (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/MiniBatchKMeans.ts:306 (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/MiniBatchKMeans.ts:355 (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/MiniBatchKMeans.ts:393 (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/MiniBatchKMeans.ts:137 (opens in a new tab)

partial_fit()

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

Signature

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

Parameters

NameTypeDescription
optsobject-
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.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.y?anyNot used, present here for API consistency by convention.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:428 (opens in a new tab)

predict()

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.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeNew data to predict.
opts.sample_weight?ArrayLikeThe weights for each observation in X. If undefined, all observations are assigned equal weight.

Returns

Promise<ArrayLike>

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

set_fit_request()

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:

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in fit.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:568 (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/MiniBatchKMeans.ts:605 (opens in a new tab)

set_partial_fit_request()

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:

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in partial\_fit.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:642 (opens in a new tab)

set_predict_request()

Request metadata passed to the predict 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:

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in predict.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:682 (opens in a new tab)

set_score_request()

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:

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in score.

Returns

Promise<any>

Defined in: generated/cluster/MiniBatchKMeans.ts:722 (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/MiniBatchKMeans.ts:760 (opens in a new tab)

Properties

_isDisposed

boolean = false

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

_isInitialized

boolean = false

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

_py

PythonBridge

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

id

string

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

opts

any

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

Accessors

cluster_centers_

Coordinates of cluster centers.

Signature

cluster_centers_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/cluster/MiniBatchKMeans.ts:793 (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/MiniBatchKMeans.ts:943 (opens in a new tab)

inertia_

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.

Signature

inertia_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/MiniBatchKMeans.ts:843 (opens in a new tab)

labels_

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

Signature

labels_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/cluster/MiniBatchKMeans.ts:818 (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/MiniBatchKMeans.ts:918 (opens in a new tab)

n_iter_

Number of iterations over the full dataset.

Signature

n_iter_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/MiniBatchKMeans.ts:868 (opens in a new tab)

n_steps_

Number of minibatches processed.

Signature

n_steps_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/cluster/MiniBatchKMeans.ts:893 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/cluster/MiniBatchKMeans.ts:124 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/cluster/MiniBatchKMeans.ts:128 (opens in a new tab)