mlpy.cluster.vq.kmeans

mlpy.cluster.vq.kmeans(x, k, n_iter=None, thresh=None, mean=None, fn_plot=None, return_assignment=False, return_err_hist=False, verbose=False)[source]

Hard cluster data using kmeans.

Parameters:

x : array_like, shape (n, dim)

List of dim-dimensional data points. Each row corresponds to a single data point.

k : int

The number of clusters to fit.

n_iter : int, optional

Number of iterations to perform. Default is 100.

thresh : float, optional

Convergence threshold. Default is 1e-3.

mean : array_like, shape (ncomponents,), optional

Initial guess for the cluster centers.

fn_plot : callable, optional

A plotting callback function.

return_assignment : bool, optional

Whether to return the assignments or not. Default is False.

return_err_hist : bool, optional

Whether to return the error history. Default is False.

verbose : bool, optional

Controls if debug information is printed to the console. Default is False.

Returns:

ndarray or tuple :

The cluster centers and optionally the assignments and error history.

Examples

>>> from mlpy.cluster.vq import kmeans

Note

Ported from Matlab:

Copyright (2010) Kevin Murphy and Matt Dunham
License: MIT