Skip to content

Commit

Permalink
Bug fix in agglomerative clustering due to new version restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
Old-Shatterhand committed Mar 15, 2024
1 parent 23577b2 commit 62a3bd3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions datasail/cluster/clustering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, Tuple, List, Union, Optional, Literal

import numpy as np
import sklearn
from sklearn.cluster import AgglomerativeClustering, SpectralClustering

from datasail.cluster.caching import load_from_cache, store_to_cache
Expand Down Expand Up @@ -194,11 +195,18 @@ def additional_clustering(
)
else:
cluster_matrix = np.array(dataset.cluster_distance, dtype=float)
ca = AgglomerativeClustering(
n_clusters=n_clusters,
affinity="precomputed",
linkage=linkage,
)
if sklearn.__version__ < '1.4':
ca = AgglomerativeClustering(
n_clusters=n_clusters,
affinity="precomputed",
linkage=linkage,
)
else:
ca = AgglomerativeClustering(
n_clusters=n_clusters,
metric="precomputed",
linkage=linkage,
)
LOGGER.info(
f"Clustering based on distances. "
f"Distances above {np.average(dataset.cluster_distance) * 0.9} cannot end up in same cluster."
Expand Down

0 comments on commit 62a3bd3

Please sign in to comment.