Description
Describe the bug
When using sklearn.cluster.AgglomerativeClustering, a ValueError "Ward can only work with euclidean distances." is thrown when using ward linkage and l2 affinity. l2 should also work since it is the same thing as euclidean. This is a quite simple problem and I have a fix ready to submit a pull request.
Steps/Code to Reproduce
To simply reproduce with no imports. (self.linkage and self.affinity are altered here to make it easily reproducible)
self_linkage = 'ward'
self_affinity = 'l2'
if self_linkage == "ward" and self_affinity != "euclidean":
raise ValueError("%s was provided as affinity. Ward can only "
"work with euclidean distances." %
(self_affinity, ))
Expected Results
When using l2 affinity, no ValueError should be thrown.
Actual Results
ValueError("%s was provided as affinity. Ward can only "
"work with euclidean distances." %
(self_affinity, ))
Versions
System:
python: 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
executable: /usr/bin/python3
machine: Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
Python dependencies:
pip: 19.3.1
setuptools: 50.3.0
sklearn: 0.22.2.post1
numpy: 1.18.5
scipy: 1.4.1
Cython: 0.29.21
pandas: 1.1.2
matplotlib: 3.2.2
joblib: 0.16.0