TypeError: '<=' not supported between instances of 'str' and 'int' when using fit_predict

I am trying to utilize silhouette analysis on KMeans clustering in order to determine how to choose the optimal number of clusters in a given dataset.
I tried the example code provided on [scikit-learn](https://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html#) but it seems to produce an error whenever I try to run it.

Traceback:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [14], in <cell line: 24>()
     37 # Initialize the clusterer with n_clusters value and a random generator
     38 # seed of 10 for reproducibility.
     39 clusterer = KMeans(n_clusters=n_clusters, n_init="auto", random_state=10)
---> 40 cluster_labels = clusterer.fit_predict(X)
     42 # The silhouette_score gives the average value for all the samples.
     43 # This gives a perspective into the density and separation of the formed
     44 # clusters
     45 silhouette_avg = silhouette_score(X, cluster_labels)

File ~\Anaconda3\lib\site-packages\sklearn\cluster\_kmeans.py:1255, in KMeans.fit_predict(self, X, y, sample_weight)
   1232 def fit_predict(self, X, y=None, sample_weight=None):
   1233     """Compute cluster centers and predict cluster index for each sample.
   1234 
   1235     Convenience method; equivalent to calling fit(X) followed by
   (...)
   1253         Index of the cluster each sample belongs to.
   1254     """
-> 1255     return self.fit(X, sample_weight=sample_weight).labels_

File ~\Anaconda3\lib\site-packages\sklearn\cluster\_kmeans.py:1146, in KMeans.fit(self, X, y, sample_weight)
   1112 """Compute k-means clustering.
   1113 
   1114 Parameters
   (...)
   1135     Fitted estimator.
   1136 """
   1137 X = self._validate_data(
   1138     X,
   1139     accept_sparse="csr",
   (...)
   1143     accept_large_sparse=False,
   1144 )
-> 1146 self._check_params(X)
   1147 random_state = check_random_state(self.random_state)
   1148 sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)

File ~\Anaconda3\lib\site-packages\sklearn\cluster\_kmeans.py:937, in KMeans._check_params(self, X)
    935 def _check_params(self, X):
    936     # n_init
--> 937     if self.n_init <= 0:
    938         raise ValueError(f"n_init should be > 0, got {self.n_init} instead.")
    939     self._n_init = self.n_init

TypeError: '<=' not supported between instances of 'str' and 'int'
```

Is there something I am missing here? I iterated through the sample data and did not see any strings present in `X`. I copied and ran the exact same code as present on the website.

Thank you!

COMMENT:
> The examples on the stable webpage `https://scikit-learn.org/stable/` is validate for scikit-learn version 1.2. From the error message, I suspect you are on an older version of scikit-learn. Can you check your scikit-learn version to confirm?
> 
> For old versions such as 1.1, you can look at the same example but change the version in the URL: https://scikit-learn.org/1.1/auto_examples/cluster/plot_kmeans_silhouette_analysis.html# (Note the "1.1" in the URL)

scikit-learn version is currently set to 1.2.1, but the issue is still persisting

Labels: Question