@@ -240,26 +240,27 @@ def _fit(self, X, y=None, sample_weight=None):
240240 are assigned equal weight (default: None)
241241
242242 """
243- if self .precompute_distances != 'deprecated' :
244- if sklearn_check_version ('0.24' ):
245- warnings .warn ("'precompute_distances' was deprecated in version "
246- "0.23 and will be removed in 1.0 (renaming of 0.25). It has no "
247- "effect" , FutureWarning )
248- elif sklearn_check_version ('0.23' ):
249- warnings .warn ("'precompute_distances' was deprecated in version "
250- "0.23 and will be removed in 0.25. It has no "
251- "effect" , FutureWarning )
252-
253- if self .n_jobs != 'deprecated' :
254- if sklearn_check_version ('0.24' ):
255- warnings .warn ("'n_jobs' was deprecated in version 0.23 and will be"
256- " removed in 1.0 (renaming of 0.25)." , FutureWarning )
257- elif sklearn_check_version ('0.23' ):
258- warnings .warn ("'n_jobs' was deprecated in version 0.23 and will be"
259- " removed in 0.25." , FutureWarning )
260- self ._n_threads = self .n_jobs
261- else :
262- self ._n_threads = None
243+ if hasattr (self , 'precompute_distances' ):
244+ if self .precompute_distances != 'deprecated' :
245+ if sklearn_check_version ('0.24' ):
246+ warnings .warn ("'precompute_distances' was deprecated in version "
247+ "0.23 and will be removed in 1.0 (renaming of 0.25)."
248+ " It has no effect" , FutureWarning )
249+ elif sklearn_check_version ('0.23' ):
250+ warnings .warn ("'precompute_distances' was deprecated in version "
251+ "0.23 and will be removed in 0.25. It has no "
252+ "effect" , FutureWarning )
253+
254+ self ._n_threads = None
255+ if hasattr (self , 'n_jobs' ):
256+ if self .n_jobs != 'deprecated' :
257+ if sklearn_check_version ('0.24' ):
258+ warnings .warn ("'n_jobs' was deprecated in version 0.23 and will be"
259+ " removed in 1.0 (renaming of 0.25)." , FutureWarning )
260+ elif sklearn_check_version ('0.23' ):
261+ warnings .warn ("'n_jobs' was deprecated in version 0.23 and will be"
262+ " removed in 0.25." , FutureWarning )
263+ self ._n_threads = self .n_jobs
263264 self ._n_threads = _openmp_effective_n_threads (self ._n_threads )
264265
265266 if self .n_init <= 0 :
@@ -366,17 +367,29 @@ def _predict(self, X, sample_weight=None):
366367class KMeans (KMeans_original ):
367368 __doc__ = KMeans_original .__doc__
368369
369- @_deprecate_positional_args
370- def __init__ (self , n_clusters = 8 , * , init = 'k-means++' , n_init = 10 ,
371- max_iter = 300 , tol = 1e-4 , precompute_distances = 'deprecated' ,
372- verbose = 0 , random_state = None , copy_x = True ,
373- n_jobs = 'deprecated' , algorithm = 'auto' ):
374-
375- super (KMeans , self ).__init__ (
376- n_clusters = n_clusters , init = init , max_iter = max_iter ,
377- tol = tol , precompute_distances = precompute_distances ,
378- n_init = n_init , verbose = verbose , random_state = random_state ,
379- copy_x = copy_x , n_jobs = n_jobs , algorithm = algorithm )
370+ if sklearn_check_version ('1.0' ):
371+ @_deprecate_positional_args
372+ def __init__ (self , n_clusters = 8 , * , init = 'k-means++' , n_init = 10 ,
373+ max_iter = 300 , tol = 1e-4 , verbose = 0 , random_state = None ,
374+ copy_x = True , algorithm = 'auto' ):
375+
376+ super (KMeans , self ).__init__ (
377+ n_clusters = n_clusters , init = init , max_iter = max_iter ,
378+ tol = tol , n_init = n_init , verbose = verbose ,
379+ random_state = random_state , copy_x = copy_x ,
380+ algorithm = algorithm )
381+ else :
382+ @_deprecate_positional_args
383+ def __init__ (self , n_clusters = 8 , * , init = 'k-means++' , n_init = 10 ,
384+ max_iter = 300 , tol = 1e-4 , precompute_distances = 'deprecated' ,
385+ verbose = 0 , random_state = None , copy_x = True ,
386+ n_jobs = 'deprecated' , algorithm = 'auto' ):
387+
388+ super (KMeans , self ).__init__ (
389+ n_clusters = n_clusters , init = init , max_iter = max_iter ,
390+ tol = tol , precompute_distances = precompute_distances ,
391+ n_init = n_init , verbose = verbose , random_state = random_state ,
392+ copy_x = copy_x , n_jobs = n_jobs , algorithm = algorithm )
380393
381394 def fit (self , X , y = None , sample_weight = None ):
382395 return _fit (self , X , y = y , sample_weight = sample_weight )
0 commit comments