You are viewing documentation about an older version (1.0.9). View latest version

snowflake.ml.modeling.cluster.BisectingKMeansΒΆ

class snowflake.ml.modeling.cluster.BisectingKMeans(*, n_clusters=8, init='random', n_init=1, random_state=None, max_iter=300, verbose=0, tol=0.0001, copy_x=True, algorithm='lloyd', bisecting_strategy='biggest_inertia', 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

Bisecting K-Means clustering For more details on this class, see sklearn.cluster.BisectingKMeans

n_clusters: int, default=8

The number of clusters to form as well as the number of centroids to generate.

init: {β€˜k-means++’, β€˜random’} or callable, default=’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.

n_init: int, default=1

Number 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.

random_state: int, RandomState instance or None, default=None

Determines random number generation for centroid initialization in inner K-Means. Use an int to make the randomness deterministic. See Glossary.

max_iter: int, default=300

Maximum number of iterations of the inner k-means algorithm at each bisection.

verbose: int, default=0

Verbosity mode.

tol: float, default=1e-4

Relative 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.

copy_x: bool, default=True

When 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.

algorithm: {β€œlloyd”, β€œelkan”}, default=”lloyd”

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).

bisecting_strategy: {β€œbiggest_inertia”, β€œlargest_cluster”}, default=”biggest_inertia”

Defines how bisection should be performed:

  • β€œbiggest_inertia” means that BisectingKMeans will always check

    all calculated cluster for cluster with biggest SSE (Sum of squared errors) and bisect it. This approach concentrates on precision, but may be costly in terms of execution time (especially for larger amount of data points).

  • β€œlargest_cluster” - BisectingKMeans will always split cluster with

    largest amount of points assigned to it from all clusters previously calculated. That should work faster than picking by SSE (β€˜biggest_inertia’) and may produce similar results in most cases.

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 bisecting k-means clustering For more details on this function, see sklearn.cluster.BisectingKMeans.fit

predict(dataset)

Predict which cluster each sample in X belongs to For more details on this function, see sklearn.cluster.BisectingKMeans.predict

score(dataset)

Opposite of the value of X on the K-means objective For more details on this function, see sklearn.cluster.BisectingKMeans.score

set_input_cols(input_cols)

Input columns setter.

to_sklearn()

Get sklearn.cluster.BisectingKMeans object.

transform(dataset)

Transform X to a cluster-distance space For more details on this function, see sklearn.cluster.BisectingKMeans.transform

Attributes

model_signatures

Returns model signature of current class.