Skip to content

Commit b702ae4

Browse files
committed
Confidence interval
1 parent 51471a8 commit b702ae4

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
{"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
1+
{"image": "mcr.microsoft.com/devcontainers/python:3.13",
22
"features": {
33
"ghcr.io/rocker-org/devcontainer-features/quarto-cli":
4-
{"installChromium": true, "installTinyTex": true},
5-
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1":
6-
{"packages": "ca-certificates,fonts-liberation,libasound2,libatk-bridge2.0-0,libatk1.0-0,libc6,libcairo2,libcups2,libdbus-1-3,libexpat1,libfontconfig1,libgbm1,libgcc1,libglib2.0-0,libgtk-3-0,libnspr4,libnss3,libpango-1.0-0,libpangocairo-1.0-0,libstdc++6,libx11-6,libx11-xcb1,libxcb1,libxcomposite1,libxcursor1,libxdamage1,libxext6,libxfixes3,libxi6,libxrandr2,libxrender1,libxss1,libxtst6,lsb-release,wget,xdg-utils"},
7-
"ghcr.io/rocker-org/devcontainer-features/miniforge:2": {}
4+
{"installChromium": true, "installTinyTex": true}
85
},
9-
"postCreateCommand": "conda env create --file environment.yml"
6+
"postCreateCommand": "python -m pip install -r requirements.txt"
107
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,5 @@ cython_debug/
160160
#.idea/
161161

162162
.vscode/settings.json
163-
quarto/CompStats_files/
163+
quarto/CompStats_files/
164+
quarto/

CompStats/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
__version__ = '0.1.13'
14+
__version__ = '0.1.14'
1515
from CompStats.bootstrap import StatisticSamples
1616
from CompStats.measurements import CI, SE, difference_p_value
1717
from CompStats.performance import performance, difference, all_differences, plot_performance, plot_difference

CompStats/interface.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from CompStats.bootstrap import StatisticSamples
2020
from CompStats.utils import progress_bar
2121
from CompStats import measurements
22-
from CompStats.measurements import SE
22+
from CompStats.measurements import SE, CI
2323
from CompStats.utils import dataframe
2424

2525

@@ -270,7 +270,7 @@ def best(self):
270270
best = data.argmin()
271271
self._best = keys[best]
272272
return self._best
273-
273+
274274
@best.setter
275275
def best(self, value):
276276
self._best = value
@@ -279,7 +279,7 @@ def best(self, value):
279279
def sorting_func(self):
280280
"""Rank systems when multiple performances are used"""
281281
return self._sorting_func
282-
282+
283283
@sorting_func.setter
284284
def sorting_func(self, value):
285285
self._sorting_func = value
@@ -315,7 +315,7 @@ def statistic(self):
315315
else:
316316
self._statistic = dict(data)
317317
return self._statistic
318-
318+
319319
@statistic.setter
320320
def statistic(self, value):
321321
"""statistic setter"""
@@ -346,6 +346,30 @@ def se(self):
346346
return list(output.values())[0]
347347
return output
348348

349+
@property
350+
def ci(self):
351+
"""Confidence interval
352+
353+
>>> from sklearn.svm import LinearSVC
354+
>>> from sklearn.datasets import load_iris
355+
>>> from sklearn.model_selection import train_test_split
356+
>>> from CompStats.interface import Perf
357+
>>> X, y = load_iris(return_X_y=True)
358+
>>> _ = train_test_split(X, y, test_size=0.3)
359+
>>> X_train, X_val, y_train, y_val = _
360+
>>> m = LinearSVC().fit(X_train, y_train)
361+
>>> hy = m.predict(X_val)
362+
>>> ens = RandomForestClassifier().fit(X_train, y_train)
363+
>>> perf = Perf(y_val, hy, name='LinearSVC')
364+
>>> perf.ci
365+
(np.float64(0.9333333333333332), np.float64(1.0))
366+
"""
367+
368+
output = CI(self.statistic_samples)
369+
if len(output) == 1:
370+
return list(output.values())[0]
371+
return output
372+
349373
def plot(self, value_name:str=None,
350374
var_name:str='Performance',
351375
alg_legend:str='Algorithm',

CompStats/tests/test_interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def test_Perf_plot_multi():
121121
f_grid = score.plot()
122122
assert f_grid is not None
123123

124+
124125
def test_Perf_statistic_one():
125126
"""Test Perf statistic one alg"""
126127
from CompStats.metrics import f1_score
@@ -142,6 +143,9 @@ def test_Perf_statistic_one():
142143
assert isinstance(score.statistic, float)
143144
assert isinstance(str(score), str)
144145
assert isinstance(score.se, float)
146+
assert isinstance(score.ci, tuple)
147+
assert len(score.ci) == 2
148+
145149

146150
def test_Perf_best():
147151
"""Test Perf best"""
@@ -191,7 +195,7 @@ def test_difference_best():
191195
score(svm.predict(X_val), name='svm')
192196
diff = score.difference()
193197
assert isinstance(diff.best, str)
194-
198+
195199

196200
def test_difference_str__():
197201
"""Test f1_score"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = 'CompStats'
33
description = 'CompStats implements an evaluation methodology for statistically analyzing competition results and competition'
44
readme = "README.rst"
5+
license = "Apache-2.0"
56
dependencies = [
67
'numpy',
78
'scikit-learn>=1.3.0',
@@ -17,7 +18,6 @@ classifiers = [
1718
"Intended Audience :: Developers",
1819
"Intended Audience :: Information Technology",
1920
"Intended Audience :: Science/Research",
20-
"License :: OSI Approved :: MIT License",
2121
"Operating System :: OS Independent",
2222
"Programming Language :: Python",
2323
"Topic :: Scientific/Engineering :: Artificial Intelligence",

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
numpy
2+
scikit-learn
3+
seaborn
4+
jupyter
5+
pyyaml
6+
sphinx
7+
pytest
8+
statsmodels

0 commit comments

Comments
 (0)