snowflake.ml.modeling.cluster.MiniBatchKMeansΒΆ
- class snowflake.ml.modeling.cluster.MiniBatchKMeans(*, n_clusters=8, init='k-means++', max_iter=100, batch_size=1024, verbose=0, compute_labels=True, random_state=None, tol=0.0, max_no_improvement=10, init_size=None, n_init='warn', reassignment_ratio=0.01, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)ΒΆ
Bases:
BaseTransformer
Mini-Batch K-Means clustering For more details on this class, see sklearn.cluster.MiniBatchKMeans
- n_clusters: int, default=8
The number of clusters to form as well as the number of centroids to generate.
- init: {βk-means++β, βrandomβ}, callable or array-like of shape (n_clusters, n_features), default=βk-means++β
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.
- max_iter: int, default=100
Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.
- batch_size: int, default=1024
Size 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.- verbose: int, default=0
Verbosity mode.
- compute_labels: bool, default=True
Compute label assignment and inertia for the complete dataset once the minibatch optimization has converged in fit.
- random_state: int, RandomState instance or None, default=None
Determines random number generation for centroid initialization and random reassignment. Use an int to make the randomness deterministic. See Glossary.
- tol: float, default=0.0
Control 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).
- max_no_improvement: int, default=10
Control 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 None.
- init_size: int, default=None
Number 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 None, the heuristic is init_size = 3 * batch_size if 3 * batch_size < n_clusters, else init_size = 3 * n_clusters.
- n_init: βautoβ or int, default=3
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 kmeans_sparse_high_dim).
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.
- reassignment_ratio: float, default=0.01
Control 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.
- input_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols and sample-weight_col parameters are considered input columns.
- label_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain labels. This is a required param for estimators, as there is no way to infer these columns. If this parameter is not specified, then object is fitted without labels(Like a transformer).
- output_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols mus match the expected number of output columns from the specific estimator or transformer class used. If this parameter is not specified, output column names are derived by adding an OUTPUT_ prefix to the label column names. These inferred output column names work for estimatorβs predict() method, but output_cols must be set explicitly for transformers.
- sample_weight_col: Optional[str]
A string representing the column name containing the examplesβ weights. This argument is only required when working with weighted datasets.
- drop_input_cols: Optional[bool], default=False
If set, the response of predict(), transform() methods will not contain input columns.
Methods
fit
(dataset)Compute the centroids on X by chunking it into mini-batches For more details on this function, see sklearn.cluster.MiniBatchKMeans.fit
predict
(dataset)Predict the closest cluster each sample in X belongs to For more details on this function, see sklearn.cluster.MiniBatchKMeans.predict
score
(dataset)Opposite of the value of X on the K-means objective For more details on this function, see sklearn.cluster.MiniBatchKMeans.score
set_input_cols
(input_cols)Input columns setter.
to_sklearn
()Get sklearn.cluster.MiniBatchKMeans object.
transform
(dataset)Transform X to a cluster-distance space For more details on this function, see sklearn.cluster.MiniBatchKMeans.transform
Attributes
model_signatures
Returns model signature of current class.