Skip to content

Commit

Permalink
add metric argument to allow for other linkages in clusterer (#222)
Browse files Browse the repository at this point in the history
* add `metric` argument to allow for other linkages

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add docstring

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jan Kwakkel <[email protected]>
  • Loading branch information
3 people authored Mar 6, 2023
1 parent b003ee1 commit f3e10d6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ema_workbench/analysis/clusterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ def plot_dendrogram(distances):
return fig


def apply_agglomerative_clustering(distances, n_clusters, linkage="average"):
def apply_agglomerative_clustering(distances, n_clusters, metric="precomputed", linkage="average"):
"""apply agglomerative clustering to the distances
Parameters
----------
distances : ndarray
n_clusters : int
metric : str, optional. The distance metric to use. The default is 'precomputed'. For a list of available metrics, see the documentation of scipy.spatial.distance.pdist.
linkage : {'average', 'complete', 'single'}
Returns
Expand All @@ -99,8 +100,6 @@ def apply_agglomerative_clustering(distances, n_clusters, linkage="average"):
"""

c = cluster.AgglomerativeClustering(
n_clusters=n_clusters, metric="precomputed", linkage=linkage
)
c = cluster.AgglomerativeClustering(n_clusters=n_clusters, metric=metric, linkage=linkage)
clusters = c.fit_predict(distances)
return clusters

0 comments on commit f3e10d6

Please sign in to comment.