Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix a MemoryError when executing scikit-learns silhouette score?

I run a clustering algorithm and want to evaluate the result by using silhouette score in scikit-learn. But in the scikit-learn, it needs to calculate the distance matrix: distances = pairwise_distances(X, metric=metric, **kwds)

Due to the fact that my data is order of 300K, and my memory is 2GB, and the result is out of memory. And I can not evaluate the clustering result.

Does anyone know how to overcome this problem?

like image 462
Thien Bao Avatar asked May 07 '13 17:05

Thien Bao


1 Answers

Set the sample_size parameter in the call to silhouette_score to some value smaller than 300K. Using this parameter will sample datapoints from X and calculate the silhouette_score on those instead of the entire array.

like image 142
mwv Avatar answered Oct 28 '22 02:10

mwv