lale.lib.sklearn.k_means module

class lale.lib.sklearn.k_means.KMeans(*, n_clusters=8, init='k-means++', n_init=10, max_iter=300, tol=0.0001, verbose=0, random_state=None, copy_x=True, algorithm='lloyd')

Bases: PlannedIndividualOp

KMeans from scikit-learn.

This documentation is auto-generated from JSON schemas.

Parameters
  • n_clusters (integer, >=2 for optimizer, <=8 for optimizer, uniform distribution, default 8) – The number of clusters to form as well as the number of centroids to generate.

  • init (union type, default 'k-means++') –

    Method for initialization, defaults to k-means++. 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 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.

    • ’k-means++’ or ‘random’

    • or callable, not for optimizer

    • or array, not for optimizer of items : array of items : float

  • n_init (union type, default 10) –

    Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia. When n_init=’auto’, the number of runs will be 10 if using init=’random’, and 1 if using init=’kmeans++’.

    • integer, >=3 for optimizer, <=10 for optimizer, uniform distribution

    • or ‘auto’

  • max_iter (integer, >=10 for optimizer, <=1000 for optimizer, uniform distribution, default 300) – Maximum number of iterations of the k-means algorithm for a single run.

  • tol (float, >=1e-08 for optimizer, <=0.01 for optimizer, default 0.0001) – Relative tolerance with regards to Frobenius norm of the difference in the cluster centers of two consecutive iterations to declare convergence.

  • verbose (integer, not for optimizer, default 0) – Verbosity mode.

  • random_state (union type, not for optimizer, default None) –

    Determines random number generation for centroid initialization

    • integer

    • or numpy.random.RandomState

    • or None

  • copy_x (boolean, 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’ or ‘elkan’, default ‘lloyd’) – K-means algorithm to use. The classical EM-style algorithm is “lloyd”. The “elkan” variation is more efficient on data 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).

fit(X, y=None, **fit_params)

Train the operator.

Note: The fit method is not available until this operator is trainable.

Once this method is available, it will have the following signature:

Parameters
  • X (array of items : array of items : float) – Training instances to cluster. Array-like or sparse matrix, shape=(n_samples, n_features)

  • y (any type, optional) – not used, present here for API consistency by convention.

  • sample_weight (union type, optional, default 'deprecated') –

    The parameter sample_weight is deprecated in version 1.3 and will be removed in 1.5.

    • array of items : float

    • or None or ‘deprecated’

predict(X, **predict_params)

Make predictions.

Note: The predict method is not available until this operator is trained.

Once this method is available, it will have the following signature:

Parameters
  • X (array of items : array of items : float) – New data to predict.

  • sample_weight (union type, optional, default None) –

    The weights for each observation in X

    • array of items : float

    • or None

Returns

result – Index of the cluster each sample belongs to.

Return type

array of items : float

transform(X, y=None)

Transform the data.

Note: The transform method is not available until this operator is trained.

Once this method is available, it will have the following signature:

Parameters

X (array of items : array of items : float) – New data to transform.

Returns

result – X transformed in the new space.

Return type

array of items : array of items : float