Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
berombau committed Sep 25, 2024
1 parent f96267a commit e728cae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/flowsom/models/batch/_som.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations
"""Code adapted from student assignment Computational Biology 2024, Ghent University."""

from typing import Callable

Expand Down
1 change: 1 addition & 0 deletions src/flowsom/models/batch/som_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from . import SOM_Batch, map_data_to_codes


# TODO: try to use the same code for both SOMEstimator and BatchSOMEstimator
class BatchSOMEstimator(BaseClusterEstimator):
"""Estimate a Self-Organizing Map (SOM) clustering model."""

Expand Down
35 changes: 35 additions & 0 deletions tests/models/test_BatchFlowSOM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from sklearn.metrics import v_measure_score

from flowsom.models import BatchFlowSOMEstimator


def test_clustering(X):
fsom = BatchFlowSOMEstimator(n_clusters=10)
y_pred = fsom.fit_predict(X)
assert y_pred.shape == (100,)


def test_clustering_v_measure(X_and_y):
som = BatchFlowSOMEstimator(n_clusters=10)
X, y_true = X_and_y
y_pred = som.fit_predict(X)
score = v_measure_score(y_true, y_pred)
assert score > 0.7


def test_reproducibility_no_seed(X):
fsom_1 = BatchFlowSOMEstimator(n_clusters=10)
fsom_2 = BatchFlowSOMEstimator(n_clusters=10)
y_pred_1 = fsom_1.fit_predict(X)
y_pred_2 = fsom_2.fit_predict(X)

assert not all(y_pred_1 == y_pred_2)


def test_reproducibility_seed(X):
fsom_1 = BatchFlowSOMEstimator(n_clusters=10, seed=0)
fsom_2 = BatchFlowSOMEstimator(n_clusters=10, seed=0)
y_pred_1 = fsom_1.fit_predict(X)
y_pred_2 = fsom_2.fit_predict(X)

assert all(y_pred_1 == y_pred_2)

0 comments on commit e728cae

Please sign in to comment.