Skip to content Skip to sidebar Skip to footer

Sklearn Kmeans Convergence Warning

I am using SKLearn's KMeans clustering on a 1D dataset. The bug I am getting is that when I run the code, I am getting a ConvergenceWarning: ConvergenceWarning: Number of distinct

Solution 1:

Ideally, the specified number of clusters should not exceed the number of unique data points. If you can adjust your centroid count accordingly, that will cause the warning not to be raised.

Sklearn uses the warning module to raise warnings. We can suppress the warnings as shown below.

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    cluster_data(data_arr)

All warnings are suppressed within the with block so this functionality should be used with caution.

Post a Comment for "Sklearn Kmeans Convergence Warning"