ageron/handson-ml3

[IDEA] Chapter 2, Reduce multiple FutureWarning(s) when using KMeans with sklearn 1.3.1

eranr opened this issue · 0 comments

eranr commented

Notebook name: 02_end_to_end_machine_learning_project
Section 3.4: “Custom Transformers”
cell 109

The definition of the ClusterSimilarity transformer yields quite a few “FutureWarning” warnings with sklearn 1.3.1. The warning comes from the “fit” method which initiates the KMeans class without an n_init parameter. To resolve replace:

self.kmeans_ = KMeans(self.n_clusters, random_state=self.random_state)

with:

self.kmeans_ = KMeans(self.n_clusters, random_state=self.random_state, n_init='auto')