|
1 | 1 | import pandas |
2 | 2 | import wvpy.util |
3 | 3 | import data_algebra.test_util |
4 | | - |
| 4 | +import data_algebra.util |
5 | 5 |
|
6 | 6 | def test_stats1(): |
7 | 7 | d = pandas.DataFrame({"x": [1, 2, 3, 4, 5], "y": [False, False, True, True, False]}) |
8 | 8 |
|
9 | 9 | stats = wvpy.util.threshold_statistics(d, model_predictions="x", yvalues="y",) |
| 10 | + # print(data_algebra.util.pandas_to_example_str(stats)) |
10 | 11 |
|
11 | | - expect = pandas.DataFrame( |
12 | | - { |
13 | | - "threshold": [0.999999, 1.0, 2.0, 3.0, 4.0, 5.0, 5.000001], |
14 | | - "count": [5, 5, 4, 3, 2, 1, 0], |
15 | | - "fraction": [1.0, 1.0, 0.8, 0.6, 0.4, 0.2, 0.0], |
16 | | - "precision": [0.4, 0.4, 0.5, 0.6666666666666666, 0.5, 0.0, 0.0], |
17 | | - "true_positive_rate": [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
18 | | - "false_positive_rate": [ |
19 | | - 1.0, |
20 | | - 1.0, |
21 | | - 0.6666666666666666, |
22 | | - 0.3333333333333333, |
23 | | - 0.3333333333333333, |
24 | | - 0.3333333333333333, |
25 | | - 0.0, |
26 | | - ], |
27 | | - "true_negative_rate": [ |
28 | | - 0.0, |
29 | | - 0.0, |
30 | | - 0.3333333333333333, |
31 | | - 0.6666666666666666, |
32 | | - 0.6666666666666666, |
33 | | - 0.6666666666666666, |
34 | | - 1.0, |
35 | | - ], |
36 | | - "false_negative_rate": [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0], |
37 | | - "recall": [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
38 | | - "sensitivity": [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
39 | | - "specificity": [ |
40 | | - 0.0, |
41 | | - 0.0, |
42 | | - 0.33333333333333337, |
43 | | - 0.6666666666666667, |
44 | | - 0.6666666666666667, |
45 | | - 0.6666666666666667, |
46 | | - 1.0, |
47 | | - ], |
48 | | - } |
49 | | - ) |
| 12 | + expect = pandas.DataFrame({ |
| 13 | + 'threshold': [0.999999, 1.0, 2.0, 3.0, 4.0, 5.0, 5.000001], |
| 14 | + 'count': [5, 5, 4, 3, 2, 1, 0], |
| 15 | + 'fraction': [1.0, 1.0, 0.8, 0.6, 0.4, 0.2, 0.0], |
| 16 | + 'precision': [0.4, 0.4, 0.5, 0.6666666666666666, 0.5, 0.0, 0.0], |
| 17 | + 'true_positive_rate': [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
| 18 | + 'false_positive_rate': [1.0, 1.0, 0.6666666666666666, 0.3333333333333333, 0.3333333333333333, 0.3333333333333333, 0.0], |
| 19 | + 'true_negative_rate': [0.0, 0.0, 0.3333333333333333, 0.6666666666666666, 0.6666666666666666, 0.6666666666666666, 1.0], |
| 20 | + 'false_negative_rate': [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0], |
| 21 | + 'cdf': [0.0, 0.0, 0.19999999999999996, 0.4, 0.6, 0.8, 1.0], |
| 22 | + 'recall': [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
| 23 | + 'sensitivity': [1.0, 1.0, 1.0, 1.0, 0.5, 0.0, 0.0], |
| 24 | + 'specificity': [0.0, 0.0, 0.33333333333333337, 0.6666666666666667, 0.6666666666666667, 0.6666666666666667, 1.0], |
| 25 | + }) |
50 | 26 |
|
51 | 27 | assert data_algebra.test_util.equivalent_frames(stats, expect) |
0 commit comments