CompStats 0.0.5__tar.gz → 0.1.0__tar.gz
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-0.1.0/CompStats/__init__.py +19 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/bootstrap.py +5 -2
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/measurements.py +31 -3
- compstats-0.1.0/CompStats/performance.py +672 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/tests/test_measurements.py +13 -2
- compstats-0.1.0/CompStats/tests/test_performance.py +113 -0
- CompStats-0.0.5/CompStats/__init__.py → compstats-0.1.0/CompStats/utils.py +12 -4
- compstats-0.1.0/CompStats.egg-info/PKG-INFO +52 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats.egg-info/SOURCES.txt +2 -1
- compstats-0.1.0/PKG-INFO +52 -0
- compstats-0.1.0/README.rst +28 -0
- compstats-0.1.0/pyproject.toml +32 -0
- CompStats-0.0.5/CompStats/performance.py +0 -132
- CompStats-0.0.5/CompStats/tests/test_performance.py +0 -56
- CompStats-0.0.5/CompStats.egg-info/PKG-INFO +0 -8
- CompStats-0.0.5/PKG-INFO +0 -8
- CompStats-0.0.5/README.md +0 -2
- CompStats-0.0.5/pyproject.toml +0 -12
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/tests/__init__.py +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/tests/data.csv +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats/tests/test_bootstrap.py +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats.egg-info/dependency_links.txt +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats.egg-info/requires.txt +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/CompStats.egg-info/top_level.txt +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/LICENSE +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/MANIFEST.in +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/setup.cfg +0 -0
- {CompStats-0.0.5 → compstats-0.1.0}/setup.py +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright 2024 Sergio Nava Muñoz and Mario Graff Guerrero
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
__version__ = '0.1.0'
|
|
15
|
+
from CompStats.bootstrap import StatisticSamples
|
|
16
|
+
from CompStats.measurements import CI, SE, difference_p_value
|
|
17
|
+
from CompStats.performance import performance, difference, all_differences, plot_performance, plot_difference
|
|
18
|
+
from CompStats.performance import performance_multiple_metrics, difference_multiple, plot_performance_multiple, plot_difference_multiple
|
|
19
|
+
from CompStats.performance import all_differences_multiple, plot_performance2, plot_difference2, plot_scatter_matrix
|
|
@@ -46,10 +46,12 @@ class StatisticSamples:
|
|
|
46
46
|
def __init__(self,
|
|
47
47
|
statistic: Callable[[np.ndarray], float]=np.mean,
|
|
48
48
|
num_samples: int=500,
|
|
49
|
-
n_jobs: int=1
|
|
49
|
+
n_jobs: int=1,
|
|
50
|
+
BiB: bool=True):
|
|
50
51
|
self.statistic = statistic
|
|
51
52
|
self.num_samples = num_samples
|
|
52
53
|
self.n_jobs = n_jobs
|
|
54
|
+
self.BiB = BiB # Guardar el parámetro BiB
|
|
53
55
|
self._samples = None
|
|
54
56
|
self._calls = {}
|
|
55
57
|
self._info = {}
|
|
@@ -67,7 +69,8 @@ class StatisticSamples:
|
|
|
67
69
|
"""Parameters"""
|
|
68
70
|
return dict(statistic=self.statistic,
|
|
69
71
|
num_samples=self.num_samples,
|
|
70
|
-
n_jobs=self.n_jobs
|
|
72
|
+
n_jobs=self.n_jobs,
|
|
73
|
+
BiB=self.BiB) # Añadir BiB a los parámetros
|
|
71
74
|
|
|
72
75
|
def __sklearn_clone__(self):
|
|
73
76
|
klass = self.__class__
|
|
@@ -15,6 +15,7 @@ import numpy as np
|
|
|
15
15
|
import pandas as pd
|
|
16
16
|
from CompStats.bootstrap import StatisticSamples
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
def CI(samples: np.ndarray, alpha=0.05):
|
|
19
20
|
"""Compute the Confidence Interval of a statistic using bootstrap.
|
|
20
21
|
:param samples: Bootstrap samples
|
|
@@ -32,12 +33,39 @@ def CI(samples: np.ndarray, alpha=0.05):
|
|
|
32
33
|
>>> CI(samples)
|
|
33
34
|
(0.6, 1.0)
|
|
34
35
|
"""
|
|
36
|
+
if isinstance(samples, StatisticSamples):
|
|
37
|
+
return {k: CI(v, alpha=alpha) for k, v in samples.calls.items()}
|
|
35
38
|
alpha = alpha / 2
|
|
36
39
|
return (np.percentile(samples, alpha * 100, axis=0),
|
|
37
40
|
np.percentile(samples, (1 - alpha) * 100, axis=0))
|
|
38
41
|
|
|
42
|
+
|
|
43
|
+
def SE(samples: np.ndarray):
|
|
44
|
+
"""Compute the Standard Error of a statistic using bootstrap.
|
|
45
|
+
|
|
46
|
+
>>> from CompStats import StatisticSamples, SE
|
|
47
|
+
>>> from sklearn.metrics import accuracy_score
|
|
48
|
+
>>> import numpy as np
|
|
49
|
+
>>> labels = np.r_[[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]
|
|
50
|
+
>>> pred = np.r_[[0, 0, 1, 0, 0, 1, 1, 1, 0, 1]]
|
|
51
|
+
>>> bootstrap = StatisticSamples(statistic=accuracy_score)
|
|
52
|
+
>>> samples = bootstrap(labels, pred)
|
|
53
|
+
>>> SE(samples)
|
|
54
|
+
"""
|
|
55
|
+
if isinstance(samples, StatisticSamples):
|
|
56
|
+
return {k: SE(v) for k, v in samples.calls.items()}
|
|
57
|
+
return np.std(samples, axis=0)
|
|
58
|
+
|
|
39
59
|
|
|
40
|
-
def difference_p_value(
|
|
60
|
+
def difference_p_value(samples: np.ndarray, BiB: bool = True):
|
|
41
61
|
"""Compute the difference p-value"""
|
|
42
|
-
|
|
43
|
-
|
|
62
|
+
if isinstance(samples, StatisticSamples):
|
|
63
|
+
if samples.BiB:
|
|
64
|
+
return {k: (v > 2 * np.mean(v)).mean() for k, v in samples.calls.items()}
|
|
65
|
+
else:
|
|
66
|
+
return {k: (v < 2 * np.mean(v)).mean() for k, v in samples.calls.items()}
|
|
67
|
+
else:
|
|
68
|
+
if BiB:
|
|
69
|
+
return np.mean(samples > 2 * np.mean(samples, axis=0), axis=0)
|
|
70
|
+
else:
|
|
71
|
+
return np.mean(samples < 2 * np.mean(samples, axis=0), axis=0)
|