n-iter for the kmedoids in the pyclustering library in PyPI?

Viewed 86

How can I access the attribute of the number of iterations performed until convergence for the kmedoids as implemented in the pyclustering library in PyPI?

In the Scikit Learn implementation of KMeans, it provides access to 4 attributes:

cluster_centers_

labels_

inertia_

n_iter_

Where n_iter_ is the number of iterations required to converge on the solution as required by the parameters supplied to the algorithm.

In the very useful set of algorithms in the Pyclustering Library, the series of clustering algorithms similar to KMeans are useful. I am interested in one in particular kmedoids, but an answer for the other KMeans-similar algorithms I think would be generally useful.

For kmediods, there is no access to an attribute like n_iter_. Thus the question.

1 Answers

You can do this with itermax argument.

Have a look at the pyclustering docs: https://pyclustering.github.io/docs/0.9.3/html/d0/dd3/classpyclustering_1_1cluster_1_1kmedoids_1_1kmedoids.html#a698b7a2df2358221e705012973df44a6

[in] **kwargs
Arbitrary keyword arguments (available arguments: 'metric', 'data_type', 'itermax').

Example:

kmedoids_instance = kmedoids(dm, initial_medoids,
    tolerance = 0.001,
    ccore = True,
    metric = distance_metric(type_metric.MINKOWSKI, degree=2),
    data_type = 'distance_matrix',
    itermax = 1000    
)

Or you pass an unpacked dictionary as arguments:

metric = distance_metric(type_metric.MINKOWSKI, degree=2)
kwargs = {'metric': metric, 'data_type': 'distance_matrix', 'itermax': 1000}
kmedoids_instance = kmedoids(dm, initial_medoids,
    tolerance = 0.001,
    ccore = True,
    **kwargs
)
Related