CompStats 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CompStats/__init__.py +3 -3
- CompStats/measurements.py +8 -1
- CompStats/performance.py +25 -1
- CompStats/tests/test_measurements.py +16 -2
- CompStats/tests/test_performance.py +10 -2
- {CompStats-0.0.3.dist-info → CompStats-0.0.4.dist-info}/METADATA +1 -1
- CompStats-0.0.4.dist-info/RECORD +14 -0
- CompStats-0.0.3.dist-info/RECORD +0 -14
- {CompStats-0.0.3.dist-info → CompStats-0.0.4.dist-info}/LICENSE +0 -0
- {CompStats-0.0.3.dist-info → CompStats-0.0.4.dist-info}/WHEEL +0 -0
- {CompStats-0.0.3.dist-info → CompStats-0.0.4.dist-info}/top_level.txt +0 -0
CompStats/__init__.py
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
__version__ = '0.0.
|
|
14
|
+
__version__ = '0.0.4'
|
|
15
15
|
from CompStats.bootstrap import StatisticSamples
|
|
16
|
-
from CompStats.measurements import CI
|
|
17
|
-
from CompStats.performance import performance, difference, plot_performance, plot_difference
|
|
16
|
+
from CompStats.measurements import CI, difference_p_value
|
|
17
|
+
from CompStats.performance import performance, difference, all_differences, plot_performance, plot_difference
|
CompStats/measurements.py
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import numpy as np
|
|
15
|
-
|
|
15
|
+
import pandas as pd
|
|
16
|
+
from CompStats.bootstrap import StatisticSamples
|
|
16
17
|
|
|
17
18
|
def CI(samples: np.ndarray, alpha=0.05):
|
|
18
19
|
"""Compute the Confidence Interval of a statistic using bootstrap.
|
|
@@ -34,3 +35,9 @@ def CI(samples: np.ndarray, alpha=0.05):
|
|
|
34
35
|
alpha = alpha / 2
|
|
35
36
|
return (np.percentile(samples, alpha * 100, axis=0),
|
|
36
37
|
np.percentile(samples, (1 - alpha) * 100, axis=0))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def difference_p_value(statistic_samples: StatisticSamples):
|
|
41
|
+
"""Compute the difference p-value"""
|
|
42
|
+
return {k: (v > 2 * np.mean(v)).mean()
|
|
43
|
+
for k, v in statistic_samples.calls.items()}
|
CompStats/performance.py
CHANGED
|
@@ -37,7 +37,7 @@ def performance(data: pd.DataFrame,
|
|
|
37
37
|
return statistic_samples
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def difference(statistic_samples: StatisticSamples, best_index=-1):
|
|
40
|
+
def difference(statistic_samples: StatisticSamples, best_index: int=-1):
|
|
41
41
|
"""Bootstrap samples of a difference in performnace"""
|
|
42
42
|
|
|
43
43
|
items = list(statistic_samples.calls.items())
|
|
@@ -53,6 +53,30 @@ def difference(statistic_samples: StatisticSamples, best_index=-1):
|
|
|
53
53
|
output.calls = diff
|
|
54
54
|
output.info['best'] = best_name
|
|
55
55
|
return output
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def all_differences(statistic_samples: StatisticSamples, reverse: bool=True):
|
|
59
|
+
"""Calculates all possible differences in performance among algorithms and sorts by average performance"""
|
|
60
|
+
|
|
61
|
+
items = list(statistic_samples.calls.items())
|
|
62
|
+
# Calculamos el rendimiento medio y ordenamos los algoritmos basándonos en este
|
|
63
|
+
perf = [(k, v, np.mean(v)) for k, v in items]
|
|
64
|
+
perf.sort(key=lambda x: x[2], reverse=reverse) # Orden descendente por rendimiento medio
|
|
65
|
+
|
|
66
|
+
diffs = {} # Diccionario para guardar las diferencias
|
|
67
|
+
|
|
68
|
+
# Iteramos sobre todos los pares posibles de algoritmos ordenados
|
|
69
|
+
for i in range(len(perf)):
|
|
70
|
+
for j in range(i + 1, len(perf)):
|
|
71
|
+
name_i, perf_i, _ = perf[i]
|
|
72
|
+
name_j, perf_j, _ = perf[j]
|
|
73
|
+
|
|
74
|
+
# Diferencia de i a j
|
|
75
|
+
diff_key_i_to_j = f"{name_i} - {name_j}"
|
|
76
|
+
diffs[diff_key_i_to_j] = np.array(perf_i) - np.array(perf_j)
|
|
77
|
+
output = clone(statistic_samples)
|
|
78
|
+
output.calls = diffs
|
|
79
|
+
return output
|
|
56
80
|
|
|
57
81
|
|
|
58
82
|
def plot_performance(statistic_samples: StatisticSamples,
|
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import numpy as np
|
|
15
|
-
|
|
15
|
+
import pandas as pd
|
|
16
|
+
import os
|
|
17
|
+
from sklearn.metrics import f1_score
|
|
18
|
+
from CompStats.measurements import CI, difference_p_value
|
|
16
19
|
from CompStats.bootstrap import StatisticSamples
|
|
20
|
+
from CompStats.performance import performance, difference
|
|
17
21
|
|
|
22
|
+
DATA = os.path.join(os.path.dirname(__file__), 'data.csv')
|
|
18
23
|
|
|
19
24
|
def test_CI():
|
|
20
25
|
"""Test confidence interval"""
|
|
@@ -24,4 +29,13 @@ def test_CI():
|
|
|
24
29
|
samples = statistic(pop)
|
|
25
30
|
low, high = CI(samples)
|
|
26
31
|
mean = pop.mean()
|
|
27
|
-
assert low < mean < high
|
|
32
|
+
assert low < mean < high
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_difference_p_value():
|
|
36
|
+
"""Test difference p-values"""
|
|
37
|
+
df = pd.read_csv(DATA)
|
|
38
|
+
perf = performance(df, score=lambda y, hy: f1_score(y, hy, average='weighted'))
|
|
39
|
+
res = difference(perf)
|
|
40
|
+
p_value = difference_p_value(res)
|
|
41
|
+
assert p_value['BoW'] > 0.2
|
|
@@ -16,7 +16,7 @@ import pandas as pd
|
|
|
16
16
|
import os
|
|
17
17
|
from sklearn.metrics import f1_score
|
|
18
18
|
import seaborn as sns
|
|
19
|
-
from CompStats.performance import performance, plot_performance, difference, plot_difference
|
|
19
|
+
from CompStats.performance import performance, plot_performance, difference, plot_difference, all_differences
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
DATA = os.path.join(os.path.dirname(__file__), 'data.csv')
|
|
@@ -44,4 +44,12 @@ def test_difference():
|
|
|
44
44
|
assert 'INGEOTEC' not in res.calls
|
|
45
45
|
assert res.info['best'] == 'INGEOTEC'
|
|
46
46
|
ins = plot_difference(res)
|
|
47
|
-
assert isinstance(ins, sns.FacetGrid)
|
|
47
|
+
assert isinstance(ins, sns.FacetGrid)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_all_differences():
|
|
51
|
+
"""Test all_differences"""
|
|
52
|
+
df = pd.read_csv(DATA)
|
|
53
|
+
perf = performance(df, score=lambda y, hy: f1_score(y, hy, average='weighted'))
|
|
54
|
+
res = all_differences(perf)
|
|
55
|
+
assert 'INGEOTEC - BoW' in res.calls
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
CompStats/__init__.py,sha256=Im-sUuG5hZdTgOl3hsNWedSeIzBTPPPLXVi7-Eg6IWM,843
|
|
2
|
+
CompStats/bootstrap.py,sha256=xOGrxYMnM-78Sl8SUiVDjgxR2sBdNqUoHl-UkCZErbY,9883
|
|
3
|
+
CompStats/measurements.py,sha256=PVul0CeKNH592edezLmz9aXOnorjJNpR-Uxk6RhRdDg,1710
|
|
4
|
+
CompStats/performance.py,sha256=wVklccCC4fmIHjOJNji8wuf832YIZ8sWwtmc7Qsb1d0,5103
|
|
5
|
+
CompStats/tests/__init__.py,sha256=0SgrIBJT9fwEo-RGwyYoigMbWOZBbMxFyMPUEj2obG0,603
|
|
6
|
+
CompStats/tests/data.csv,sha256=yiyfu-QxDoXbEKVCsiKVRaBHvWTQzsCUMxJ0VlGnyVk,22182
|
|
7
|
+
CompStats/tests/test_bootstrap.py,sha256=EyW2wrH6XnfPT0ldqmwo0zRZWpbp_M5eJ3-siRjkvHs,3352
|
|
8
|
+
CompStats/tests/test_measurements.py,sha256=LjlDiZ6S4NHA4XYMSZ-HEBQq9Xme3Q6Dm55689q7ndE,1441
|
|
9
|
+
CompStats/tests/test_performance.py,sha256=XDRzvhVKIM_alA4bWJubPxqWHAiyoJGCn47RyrD4e9U,1892
|
|
10
|
+
CompStats-0.0.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
CompStats-0.0.4.dist-info/METADATA,sha256=g1P3Cuz73l9bpW0dx0uWRhnGQDelkWzm6-8gPRLXHBE,187
|
|
12
|
+
CompStats-0.0.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
13
|
+
CompStats-0.0.4.dist-info/top_level.txt,sha256=dK1wZh1NWAXl3-aLQCSp1ds4FsuxZrmwV0IPnP9fzWM,10
|
|
14
|
+
CompStats-0.0.4.dist-info/RECORD,,
|
CompStats-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
CompStats/__init__.py,sha256=OslXX7s4pEDCTHeLzExyo0v_-E5BG9qJBBkqzO6XfGs,806
|
|
2
|
-
CompStats/bootstrap.py,sha256=xOGrxYMnM-78Sl8SUiVDjgxR2sBdNqUoHl-UkCZErbY,9883
|
|
3
|
-
CompStats/measurements.py,sha256=pO9kwNWiK7YemJXf91_8o3Datx2B6k91Vdo3tnmV_AA,1435
|
|
4
|
-
CompStats/performance.py,sha256=veG0dUYgk6ko5HycDXPQxBjGHCsLrJgYmnO33rqHeFI,4077
|
|
5
|
-
CompStats/tests/__init__.py,sha256=0SgrIBJT9fwEo-RGwyYoigMbWOZBbMxFyMPUEj2obG0,603
|
|
6
|
-
CompStats/tests/data.csv,sha256=yiyfu-QxDoXbEKVCsiKVRaBHvWTQzsCUMxJ0VlGnyVk,22182
|
|
7
|
-
CompStats/tests/test_bootstrap.py,sha256=EyW2wrH6XnfPT0ldqmwo0zRZWpbp_M5eJ3-siRjkvHs,3352
|
|
8
|
-
CompStats/tests/test_measurements.py,sha256=VU8u3zNcMMi51dIAXsgKODnFieIaMzldwJ5i0ERNLOk,961
|
|
9
|
-
CompStats/tests/test_performance.py,sha256=i6svhgs9jHnoWiGq10p7F2bu57WHe-UNkc0XitFN2JA,1630
|
|
10
|
-
CompStats-0.0.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
-
CompStats-0.0.3.dist-info/METADATA,sha256=0wt_UiH2hCYBua2zavcky5xZEkTToT82Jm_8XJikzc8,187
|
|
12
|
-
CompStats-0.0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
13
|
-
CompStats-0.0.3.dist-info/top_level.txt,sha256=dK1wZh1NWAXl3-aLQCSp1ds4FsuxZrmwV0IPnP9fzWM,10
|
|
14
|
-
CompStats-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|