Skip to content

Commit

Permalink
Fix kmeans test instability (#172)
Browse files Browse the repository at this point in the history
* Fix kmeans test instability

* Update test_neighbors.py

* Update test_metrics.py

* Update CHANGELOG.md
  • Loading branch information
adamgayoso authored Aug 21, 2024
1 parent 7482c06 commit a04c58f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning][].
### Fixed

- Fix neighbors connectivities in test to use new scanpy fn {pr}`170`.
- Fix Kmeans test {pr}`172`.

## 0.5.1 (2024-02-23)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ def test_isolated_labels():


def test_kmeans():
centers = [[1, 1], [-1, -1], [1, -1]]
centers = np.array([[1, 1], [-1, -1], [1, -1]]) * 2
len(centers)
X, labels_true = make_blobs(n_samples=3000, centers=centers, cluster_std=0.7)
X, labels_true = make_blobs(n_samples=3000, centers=centers, cluster_std=0.7, random_state=42)

kmeans = scib_metrics.utils.KMeans(n_clusters=3)
kmeans.fit(X)
assert kmeans.labels_.shape == (X.shape[0],)
Expand Down
1 change: 0 additions & 1 deletion tests/test_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_neighbors_results(n):
neigh_result = pynndescent(adata.obsm[embedding_keys[0]], n_neighbors=n)
neigh_result = neigh_result.subset_neighbors(n=n)
new_connect = neigh_result.knn_graph_connectivities
new_dist = neigh_result.knn_graph_distances

sc_connect = sc.neighbors._connectivity.umap(
neigh_result.indices[:, :n], neigh_result.distances[:, :n], n_obs=adata.n_obs, n_neighbors=n
Expand Down

0 comments on commit a04c58f

Please sign in to comment.