KMean clustering ML.Net vs scikit-learn (Python)
System information
ML.NET version is 1.4.0 PresentationMatrix.xlsx
Issue
We try to do KMean clustering for the attached data (PresentationMatrix.csv) while doing so seeing a difference in behavior between ML.Net and scikit-learn (Python). With ML.net i am keep getting error "Failed to initialize clusters: too few examples", when i try number of clusters as 60 or above, sometimes even with lesser number of clusters, where as with Scikit-learn able to proceed with out any error for more than 60 Clusters.
Source code / logs
Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.
Hi @Vijay27anand
Perhaps your problem would be solved if you used the KMeans++ algorithm for the KMeansTrainer:
// Define trainer options.
var options = new KMeansTrainer.Options
{
InitializationAlgorithm = KMeansTrainer.InitializationAlgorithm.KMeansPlusPlus
};
// Define the trainer.
var pipeline = mlContext.Clustering.Trainers.KMeans(options);
By default, ML.NET uses KMeansYinYang (link to code), but Scikit learn uses KMeans++ by default. I made a small test, and changing the algorithm solved the problem.
So I will close this issue. If you still have problems, please feel free to reopen this. Thanks!
Can we get more information on why this is happening?
I can not find any hints on the Paper about the YinYang algorithm that indicates why this is happening. From the paper:
Overall, this study shows that Yinyang K-means is consistently faster than prior algorithms, regardless of the dimension and size of the data sets, the number of clusters, and the machine configurations.
So while for the comparison with scikit learn it is perfectly fine to use the same algorithm, I do think there is another issue that causes the root of this. A number of clusters working with another algorithm should work here as well, shouldn't it?
If you want me to open a new issue, i will do so.