File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from __future__ import annotations
1+ """Code adapted from student assignment Computational Biology 2024, Ghent University."""
22
33from typing import Callable
44
Original file line number Diff line number Diff line change 88from . import SOM_Batch , map_data_to_codes
99
1010
11+ # TODO: try to use the same code for both SOMEstimator and BatchSOMEstimator
1112class BatchSOMEstimator (BaseClusterEstimator ):
1213 """Estimate a Self-Organizing Map (SOM) clustering model."""
1314
Original file line number Diff line number Diff line change 1+ from sklearn .metrics import v_measure_score
2+
3+ from flowsom .models import BatchFlowSOMEstimator
4+
5+
6+ def test_clustering (X ):
7+ fsom = BatchFlowSOMEstimator (n_clusters = 10 )
8+ y_pred = fsom .fit_predict (X )
9+ assert y_pred .shape == (100 ,)
10+
11+
12+ def test_clustering_v_measure (X_and_y ):
13+ som = BatchFlowSOMEstimator (n_clusters = 10 )
14+ X , y_true = X_and_y
15+ y_pred = som .fit_predict (X )
16+ score = v_measure_score (y_true , y_pred )
17+ assert score > 0.7
18+
19+
20+ def test_reproducibility_no_seed (X ):
21+ fsom_1 = BatchFlowSOMEstimator (n_clusters = 10 )
22+ fsom_2 = BatchFlowSOMEstimator (n_clusters = 10 )
23+ y_pred_1 = fsom_1 .fit_predict (X )
24+ y_pred_2 = fsom_2 .fit_predict (X )
25+
26+ assert not all (y_pred_1 == y_pred_2 )
27+
28+
29+ def test_reproducibility_seed (X ):
30+ fsom_1 = BatchFlowSOMEstimator (n_clusters = 10 , seed = 0 )
31+ fsom_2 = BatchFlowSOMEstimator (n_clusters = 10 , seed = 0 )
32+ y_pred_1 = fsom_1 .fit_predict (X )
33+ y_pred_2 = fsom_2 .fit_predict (X )
34+
35+ assert all (y_pred_1 == y_pred_2 )
You can’t perform that action at this time.
0 commit comments