Skip to content

Commit

Permalink
Adjust metrics (back to scipy distance)
Browse files Browse the repository at this point in the history
  • Loading branch information
breimanntools committed Jun 30, 2024
1 parent f64b9ea commit 2c9f853
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions aaanalysis/_utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
This is a script for utility functions for statistical measures.
"""
import numpy as np
from sklearn.metrics import roc_auc_score, pairwise_distances
from sklearn.metrics import roc_auc_score
from scipy.stats import entropy, gaussian_kde
from collections import OrderedDict
from scipy.spatial import distance


# AUC adjusted
Expand Down Expand Up @@ -54,7 +55,7 @@ def bic_score_(X, labels=None):

# Compute variance over all clusters
list_masks = [labels == label for label in center_labels]
sum_squared_dist = sum([sum(pairwise_distances(X[mask], [center], metric='euclidean') ** 2) for mask, center in zip(list_masks, centers)])
sum_squared_dist = sum([sum(distance.cdist(X[mask], [center], 'euclidean') ** 2) for mask, center in zip(list_masks, centers)])

# Compute between-cluster variance
denominator = max((n_samples - n_classes) * n_features, epsilon)
Expand Down
2 changes: 1 addition & 1 deletion aaanalysis/feature_engineering/_aaclust.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self,
self._model_class = model_class
self._model_kwargs = model_kwargs
# Output parameters (set during model fitting)
self.model : Optional[ClusterMixin] = None
self.model: Optional[ClusterMixin] = None
self.n_clusters: Optional[int] = None
self.labels_: Optional[ut.ArrayLike1D] = None
self.centers_: Optional[ut.ArrayLike1D] = None
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/aaclust_tests/test_aaclust_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def test_labels_none(self):
with pytest.raises(ValueError):
aa.AAclust().eval(X)

@settings(deadline=1000)
@settings(deadline=1500)
@given(X=npst.arrays(dtype=np.float64, shape=npst.array_shapes(min_dims=2, max_dims=2, min_side=10, max_side=50),
elements=some.floats(allow_nan=False, allow_infinity=False, min_value=1)),
labels_length=some.integers(min_value=10, max_value=50))
elements=some.floats(allow_nan=False, allow_infinity=False, min_value=1, max_value=10000)),
labels_length=some.integers(min_value=10, max_value=50))
def test_matching_X_labels(self, X, labels_length):
"""Test evaluate with matching X and labels dimensions."""
# Random label assignments
Expand Down

0 comments on commit 2c9f853

Please sign in to comment.