diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index 51d2fab65be81..13efcfd6cc84d 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -142,3 +142,9 @@ Metrics for :func:`metrics.roc_auc_score`. Moreover using ``reorder=True`` can hide bugs due to floating point error in the input. :issue:`9851` by :user:`Hanmin Qin `. + +Cluster + +- Deprecate ``pooling_func`` unused parameter in + :class:`cluster.AgglomerativeClustering`. :issue:`9875` by :user:`Kumar Ashutosh + `. diff --git a/sklearn/cluster/hierarchical.py b/sklearn/cluster/hierarchical.py index c8ead243192b0..deb0bb5b0c23c 100644 --- a/sklearn/cluster/hierarchical.py +++ b/sklearn/cluster/hierarchical.py @@ -641,10 +641,12 @@ class AgglomerativeClustering(BaseEstimator, ClusterMixin): - complete or maximum linkage uses the maximum distances between all observations of the two sets. - pooling_func : callable, default=np.mean - This combines the values of agglomerated features into a single - value, and should accept an array of shape [M, N] and the keyword - argument ``axis=1``, and reduce it to an array of size [M]. + pooling_func : callable, default='deprecated' + Ignored. + + .. deprecated:: 0.20 + ``pooling_func`` has been deprecated in 0.20 and will be removed + in 0.22. Attributes ---------- @@ -670,7 +672,7 @@ class AgglomerativeClustering(BaseEstimator, ClusterMixin): def __init__(self, n_clusters=2, affinity="euclidean", memory=None, connectivity=None, compute_full_tree='auto', - linkage='ward', pooling_func=np.mean): + linkage='ward', pooling_func='deprecated'): self.n_clusters = n_clusters self.memory = memory self.connectivity = connectivity @@ -694,6 +696,10 @@ def fit(self, X, y=None): ------- self """ + if self.pooling_func != 'deprecated': + warnings.warn('Agglomerative "pooling_func" parameter is not used.' + ' It has been deprecated in version 0.20 and will be' + 'removed in 0.22', DeprecationWarning) X = check_array(X, ensure_min_samples=2, estimator=self) memory = check_memory(self.memory) @@ -829,6 +835,16 @@ class FeatureAgglomeration(AgglomerativeClustering, AgglomerationTransform): are merged to form node `n_features + i` """ + def __init__(self, n_clusters=2, affinity="euclidean", + memory=None, + connectivity=None, compute_full_tree='auto', + linkage='ward', pooling_func=np.mean): + super(FeatureAgglomeration, self).__init__( + n_clusters=n_clusters, memory=memory, connectivity=connectivity, + compute_full_tree=compute_full_tree, linkage=linkage, + affinity=affinity) + self.pooling_func = pooling_func + def fit(self, X, y=None, **params): """Fit the hierarchical clustering on the data