Skip to content

Commit

Permalink
Merge pull request #368 from theislab/danielStrobl-iso-label-fix
Browse files Browse the repository at this point in the history
Update isolated_labels.py
  • Loading branch information
danielStrobl authored Jan 27, 2023
2 parents 1be0daa + 3aa8303 commit e96da39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions scib/metrics/isolated_labels.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pandas as pd
from sklearn.metrics import f1_score
from sklearn.metrics import f1_score, silhouette_samples

from .clustering import cluster_optimal_resolution
from .silhouette import silhouette


def isolated_labels_f1(
Expand Down Expand Up @@ -227,7 +226,10 @@ def max_f1(adata, label_key, cluster_key, label, argmax=False):
else:
# AWS score between isolated label vs rest
adata.obs[iso_label_key] = adata.obs[label_key] == isolated_label
score = silhouette(adata, iso_label_key, embed)
adata.obs["silhouette_temp"] = silhouette_samples(
adata.obsm[embed], adata.obs[iso_label_key]
)
score = adata.obs[adata.obs[iso_label_key]].silhouette_temp.mean()

if verbose:
print(f"{isolated_label}: {score}")
Expand Down
2 changes: 1 addition & 1 deletion tests/metrics/test_isolated_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_isolated_labels_ASW(adata_pca):
verbose=True,
)
LOGGER.info(f"score: {score}")
assert_near_exact(score, 0.6101431176066399, diff=1e-3)
assert_near_exact(score, 0.1938440054655075, diff=1e-3)


def test_isolated_labels_perfect(adata_pca):
Expand Down
2 changes: 1 addition & 1 deletion tests/metrics/test_silhouette_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def test_isolated_labels_silhouette(adata_pca):
verbose=True,
)
LOGGER.info(f"score: {score}")
assert_near_exact(score, 0.6101431176066399, diff=1e-3)
assert_near_exact(score, 0.1938440054655075, diff=1e-3)

0 comments on commit e96da39

Please sign in to comment.