13
13
from ..metrics .pairwise import euclidean_distances
14
14
from ..base import TransformerMixin , ClusterMixin , BaseEstimator
15
15
from ..utils .extmath import row_norms
16
+ from ..utils import deprecated
16
17
from ..utils .validation import check_is_fitted , _deprecate_positional_args
17
18
from ..exceptions import ConvergenceWarning
18
19
from . import AgglomerativeClustering
@@ -440,6 +441,24 @@ def __init__(self, *, threshold=0.5, branching_factor=50, n_clusters=3,
440
441
self .compute_labels = compute_labels
441
442
self .copy = copy
442
443
444
+ # TODO: Remove in 1.2
445
+ # mypy error: Decorated property not supported
446
+ @deprecated ( # type: ignore
447
+ "fit_ is deprecated in 1.0 and will be removed in 1.2"
448
+ )
449
+ @property
450
+ def fit_ (self ):
451
+ return self ._deprecated_fit
452
+
453
+ # TODO: Remove in 1.2
454
+ # mypy error: Decorated property not supported
455
+ @deprecated ( # type: ignore
456
+ "partial_fit_ is deprecated in 1.0 and will be removed in 1.2"
457
+ )
458
+ @property
459
+ def partial_fit_ (self ):
460
+ return self ._deprecated_partial_fit
461
+
443
462
def fit (self , X , y = None ):
444
463
"""
445
464
Build a CF Tree for the input data.
@@ -457,12 +476,13 @@ def fit(self, X, y=None):
457
476
self
458
477
Fitted estimator.
459
478
"""
460
- self .fit_ , self .partial_fit_ = True , False
461
- return self ._fit (X )
479
+ # TODO: Remove deprected flags in 1.2
480
+ self ._deprecated_fit , self ._deprecated_partial_fit = True , False
481
+ return self ._fit (X , partial = False )
462
482
463
- def _fit (self , X ):
483
+ def _fit (self , X , partial ):
464
484
has_root = getattr (self , 'root_' , None )
465
- first_call = self . fit_ or ( self . partial_fit_ and not has_root )
485
+ first_call = not ( partial and has_root )
466
486
467
487
X = self ._validate_data (X , accept_sparse = 'csr' , copy = self .copy ,
468
488
reset = first_call )
@@ -552,13 +572,14 @@ def partial_fit(self, X=None, y=None):
552
572
self
553
573
Fitted estimator.
554
574
"""
555
- self .partial_fit_ , self .fit_ = True , False
575
+ # TODO: Remove deprected flags in 1.2
576
+ self ._deprecated_partial_fit , self ._deprecated_fit = True , False
556
577
if X is None :
557
578
# Perform just the final global clustering step.
558
579
self ._global_clustering ()
559
580
return self
560
581
else :
561
- return self ._fit (X )
582
+ return self ._fit (X , partial = True )
562
583
563
584
def _check_fit (self , X ):
564
585
check_is_fitted (self )
0 commit comments