@@ -94,8 +94,8 @@ class KMedoids(BaseEstimator, ClusterMixin, TransformerMixin):
9494 >>> kmedoids.predict([[0,0], [4,4]])
9595 array([0, 1])
9696 >>> kmedoids.cluster_centers_
97- array([[1, 2],
98- [4, 2]])
97+ array([[1. , 2. ],
98+ [4. , 2. ]])
9999 >>> kmedoids.inertia_
100100 8.0
101101
@@ -185,7 +185,9 @@ def fit(self, X, y=None):
185185 random_state_ = check_random_state (self .random_state )
186186
187187 self ._check_init_args ()
188- X = check_array (X , accept_sparse = ["csr" , "csc" ])
188+ X = check_array (
189+ X , accept_sparse = ["csr" , "csc" ], dtype = [np .float64 , np .float32 ]
190+ )
189191 if self .n_clusters > X .shape [0 ]:
190192 raise ValueError (
191193 "The number of medoids (%d) must be less "
@@ -315,7 +317,9 @@ def transform(self, X):
315317 X_new : {array-like, sparse matrix}, shape=(n_query, n_clusters)
316318 X transformed in the new space of distances to cluster centers.
317319 """
318- X = check_array (X , accept_sparse = ["csr" , "csc" ])
320+ X = check_array (
321+ X , accept_sparse = ["csr" , "csc" ], dtype = [np .float64 , np .float32 ]
322+ )
319323
320324 if self .metric == "precomputed" :
321325 check_is_fitted (self , "medoid_indices_" )
@@ -345,7 +349,9 @@ def predict(self, X):
345349 labels : array, shape = (n_query,)
346350 Index of the cluster each sample belongs to.
347351 """
348- X = check_array (X , accept_sparse = ["csr" , "csc" ])
352+ X = check_array (
353+ X , accept_sparse = ["csr" , "csc" ], dtype = [np .float64 , np .float32 ]
354+ )
349355
350356 if self .metric == "precomputed" :
351357 check_is_fitted (self , "medoid_indices_" )
0 commit comments