[MRG] ENH: Allow connectivity to be a callable in AgglomerativeClutering et.al

Fixes https://github.com/scikit-learn/scikit-learn/issues/3851 (It was marked easy, but I went ahead and fixed it)

The current AgglomerativeClustering conditions connectivity on the input data, which is prevents the reuse of the model for different data (if connectivity is provided initially) and definitely not in a pipeline where the input data is modified (as pointed by @jnothman ).

This fixes it by allowing it to be an int or a callable. If an int, then the kneighbors_graph is used.
Well I have no problem if you rather use collections.Callable!

On 12 December 2014 at 23:19, Manoj Kumar <notifications@github.com> wrote:

>  In sklearn/cluster/hierarchical.py
> <https://github.com/scikit-learn/scikit-learn/pull/3952#discussion-diff-21741106>
> :
>
> > @@ -624,9 +628,16 @@ def fit(self, X):
> >                                                         _TREE_BUILDERS.keys()))
> >          tree_builder = _TREE_BUILDERS[self.linkage]
> >
> > -        if not self.connectivity is None:
> > -            if (self.connectivity.shape[0] != X.shape[0] or
> > -                    self.connectivity.shape[1] != X.shape[0]):
> > +        connectivity = self.connectivity
> > +        if self.connectivity is not None:
> > +            if hasattr(connectivity, "__call__"):
>
> It seems callable was initially deprecated in Python 3.0 and then
> "un-deprecated". http://bugs.python.org/issue10518
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/scikit-learn/scikit-learn/pull/3952/files#r21741106>.
>