File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed 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."""
2
2
3
3
from typing import Callable
4
4
Original file line number Diff line number Diff line change 8
8
from . import SOM_Batch , map_data_to_codes
9
9
10
10
11
+ # TODO: try to use the same code for both SOMEstimator and BatchSOMEstimator
11
12
class BatchSOMEstimator (BaseClusterEstimator ):
12
13
"""Estimate a Self-Organizing Map (SOM) clustering model."""
13
14
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