Skip to content

Commit 4b28ebe

Browse files
authored
Merge pull request #26 from INGEOTEC/develop
Version - 0.1.12
2 parents ad6eb81 + 01bec69 commit 4b28ebe

12 files changed

Lines changed: 189 additions & 11 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
22
"features": {
3+
"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"},
37
"ghcr.io/rocker-org/devcontainer-features/miniforge:2": {}
48
},
59
"postCreateCommand": "conda env create --file environment.yml"

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
workflow_dispatch:
3+
4+
name: Quarto Publish
5+
6+
jobs:
7+
build-deploy:
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
shell: bash -el {0}
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v3
17+
- name: Set up Quarto
18+
uses: quarto-dev/quarto-actions/setup@v2
19+
with:
20+
tinytex: true
21+
# version: "pre-release"
22+
- name: Set up Python
23+
uses: conda-incubator/setup-miniconda@v3
24+
with:
25+
activate-environment: test
26+
auto-update-conda: true
27+
python-version: "3.10"
28+
channels: conda-forge
29+
allow-softlinks: true
30+
channel-priority: flexible
31+
show-channel-urls: true
32+
- name: Install dependencies
33+
run: |
34+
conda install --yes -c numpy scipy scikit-learn statsmodels pandas seaborn jupyter tabulate
35+
- name: Render and Publish
36+
run: |
37+
git config --global user.email "mgraffg@ieee.org"
38+
git config --global user.name "mgraffg"
39+
cd quarto
40+
quarto publish gh-pages CompStats.qmd --no-browser
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,4 @@ cython_debug/
160160
#.idea/
161161

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

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"ms-toolsai.jupyter",
88
"ms-python.vscode-pylance",
99
"ms-python.python",
10-
"ms-python.pylint"
10+
"ms-python.pylint",
11+
"quarto.quarto"
1112
],
1213
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
1314
"unwantedRecommendations": [

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.11'
14+
__version__ = '0.1.12'
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: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Perf(object):
9090
9191
"""
9292
def __init__(self, y_true, *y_pred,
93+
name:str=None,
9394
score_func=balanced_accuracy_score,
9495
error_func=None,
9596
num_samples: int=500,
@@ -100,8 +101,13 @@ def __init__(self, y_true, *y_pred,
100101
self.score_func = score_func
101102
self.error_func = error_func
102103
algs = {}
103-
for k, v in enumerate(y_pred):
104-
algs[f'alg-{k+1}'] = np.asanyarray(v)
104+
if name is not None:
105+
if isinstance(name, str):
106+
name = [name]
107+
else:
108+
name = [f'alg-{k+1}' for k, _ in enumerate(y_pred)]
109+
for key, v in zip(name, y_pred):
110+
algs[key] = np.asanyarray(v)
105111
algs.update(**kwargs)
106112
self.predictions = algs
107113
self.y_true = y_true
@@ -186,6 +192,7 @@ def __call__(self, y_pred, name=None):
186192
k = 1
187193
name = f'alg-{k}'
188194
self.best = None
195+
self.statistic = None
189196
self.predictions[name] = np.asanyarray(y_pred)
190197
samples = self._statistic_samples
191198
calls = samples.calls
@@ -296,14 +303,23 @@ def statistic(self):
296303
>>> perf.statistic
297304
{'alg-1': 1.0, 'forest': 0.9500891265597148}
298305
"""
299-
306+
if hasattr(self, '_statistic') and self._statistic is not None:
307+
return self._statistic
308+
BiB = True if self.score_func is not None else False
300309
data = sorted([(k, self.statistic_func(self.y_true, v))
301310
for k, v in self.predictions.items()],
302-
key=lambda x: self.sorting_func(x[1]),
303-
reverse=self.statistic_samples.BiB)
311+
key=lambda x: self.sorting_func(x[1]),
312+
reverse=BiB)
304313
if len(data) == 1:
305-
return data[0][1]
306-
return dict(data)
314+
self._statistic = data[0][1]
315+
else:
316+
self._statistic = dict(data)
317+
return self._statistic
318+
319+
@statistic.setter
320+
def statistic(self, value):
321+
"""statistic setter"""
322+
self._statistic = value
307323

308324
@property
309325
def se(self):
@@ -509,7 +525,7 @@ def y_true(self, value):
509525
algs[c] = value[c].to_numpy()
510526
self.predictions.update(algs)
511527
return
512-
self._y_true = value
528+
self._y_true = np.asanyarray(value)
513529

514530
@property
515531
def score_func(self):

CompStats/tests/test_interface.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
from CompStats.tests.test_performance import DATA
2424

2525

26+
def test_Perf_name():
27+
"""Test Perf name keyword"""
28+
from CompStats.metrics import f1_score
29+
score = f1_score([1, 0, 1], [1, 0, 0], name='algo')
30+
assert 'algo' in score.predictions
31+
32+
2633
def test_Perf_plot_col_wrap():
2734
"""Test plot when 2 classes"""
2835
from CompStats.metrics import f1_score

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Let us incorporate another predictions, now with Naive Bayes classifier, and His
7070

7171
>>> nb = GaussianNB().fit(X_train, y_train)
7272
>>> score(nb.predict(X_val), name='Naive Bayes')
73+
>>> hist = HistGradientBoostingClassifier().fit(X_train, y_train)
74+
>>> score(hist.predict(X_val), name='Hist. Grad. Boost. Tree')
7375
<Perf(score_func=f1_score)>
7476
Statistic with its standard error (se)
7577
statistic (se)

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dependencies:
99
- pytest
1010
- tqdm
1111
- sphinx
12+
- yaml
13+
- jupyter
1214
- pip:
1315
- pandas
1416
- seaborn

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ dependencies = [
66
'numpy',
77
'scikit-learn>=1.3.0',
88
'pandas',
9-
'seaborn>=0.13.0'
9+
'seaborn>=0.13.0',
10+
'statsmodels'
1011
]
1112
dynamic = ['version']
1213

@@ -26,6 +27,9 @@ classifiers = [
2627
[tool.setuptools.dynamic]
2728
version = {attr = 'CompStats.__version__'}
2829

30+
[tool.setuptools]
31+
packages = ['CompStats', 'CompStats.tests']
32+
2933
[project.urls]
3034
Homepage = "https://compstats.readthedocs.io"
3135
Repository = "https://github.com/INGEOTEC/CompStats"

0 commit comments

Comments
 (0)