Skip to content

Commit ea92c45

Browse files
committed
bugfix in bayesian cc, merged
2 parents 68d2f84 + a271fe1 commit ea92c45

File tree

13 files changed

+103
-93
lines changed

13 files changed

+103
-93
lines changed

.github/workflows/ci.yml

+15-11
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ jobs:
2020
env:
2121
QUAPY_TESTS_OMIT_LARGE_DATASETS: True
2222
steps:
23-
- uses: actions/checkout@v3
23+
- uses: actions/checkout@v4
2424
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v4
25+
uses: actions/setup-python@v5
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip setuptools wheel
31-
python -m pip install -e .[bayes,composable,tests]
31+
python -m pip install "qunfold @ git+https://github.com/mirkobunse/[email protected]"
32+
python -m pip install -e .[bayes,tests]
3233
- name: Test with unittest
3334
run: python -m unittest
3435

@@ -38,15 +39,18 @@ jobs:
3839
runs-on: ubuntu-latest
3940
if: github.ref == 'refs/heads/master'
4041
steps:
41-
- uses: actions/checkout@v1
42-
- name: Build documentation
43-
uses: ammaraskar/sphinx-action@master
42+
- uses: actions/checkout@v4
43+
- name: Set up Python
44+
uses: actions/setup-python@v5
4445
with:
45-
pre-build-command: |
46-
apt-get --allow-releaseinfo-change update -y && apt-get install -y git && git --version
47-
python -m pip install --upgrade pip setuptools wheel "jax[cpu]"
48-
python -m pip install -e .[composable,neural,docs]
49-
docs-folder: "docs/"
46+
python-version: 3.11
47+
- name: Install dependencies
48+
run: |
49+
python -m pip install --upgrade pip setuptools wheel "jax[cpu]"
50+
python -m pip install "qunfold @ git+https://github.com/mirkobunse/[email protected]"
51+
python -m pip install -e .[neural,docs]
52+
- name: Build documentation
53+
run: sphinx-build -M html docs/source docs/build
5054
- name: Publish documentation
5155
run: |
5256
git clone ${{ github.server_url }}/${{ github.repository }}.git --branch gh-pages --single-branch __gh-pages/

.github/workflows/pylint.yml

-23
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ TweetSentQuant
167167

168168

169169
*.png
170+
.idea

CHANGE_LOG.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
Change Log 0.1.10
2+
-----------------
3+
4+
- ...
5+
16
Change Log 0.1.9
27
----------------
3-
- [TODO] add LeQua2024 and normalized match distance to qp.error
4-
- [TODO] add CDE-iteration and Bayes-CDE methods
5-
- [TODO] add Friedman's method and DeBias
6-
- [TODO] check ignore warning stuff (check https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings)
78

89
- Added LeQua 2024 datasets and normalized match distance to qp.error
910

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,18 @@ of the test set.
4545

4646
```python
4747
import quapy as qp
48-
from sklearn.linear_model import LogisticRegression
4948

50-
dataset = qp.datasets.fetch_twitter('semeval16')
49+
dataset = qp.datasets.fetch_UCIBinaryDataset("yeast")
50+
training, test = dataset.train_test
5151

5252
# create an "Adjusted Classify & Count" quantifier
53-
model = qp.method.aggregative.ACC(LogisticRegression())
54-
model.fit(dataset.training)
53+
model = qp.method.aggregative.ACC()
54+
model.fit(training)
5555

56-
estim_prevalence = model.quantify(dataset.test.instances)
57-
true_prevalence = dataset.test.prevalence()
56+
estim_prevalence = model.quantify(test.X)
57+
true_prevalence = test.prevalence()
5858

5959
error = qp.error.mae(true_prevalence, estim_prevalence)
60-
6160
print(f'Mean Absolute Error (MAE)={error:.3f}')
6261
```
6362

TODO.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
- Test the return_type="index" in protocols and finish the "distributin_samples.py" example
2-
- Add EDy (an implementation is available at quantificationlib)
3-
-
1+
- [TODO] Test the return_type="index" in protocols and finish the "distributin_samples.py" example
2+
- [TODO] Add EDy (an implementation is available at quantificationlib)
3+
- [TODO] add ensemble methods SC-MQ, MC-SQ, MC-MQ
4+
- [TODO] add HistNetQ
5+
- [TODO] add CDE-iteration and Bayes-CDE methods
6+
- [TODO] add Friedman's method and DeBias
7+
- [TODO] check ignore warning stuff
8+
check https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings

docs/source/conf.py

+5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
from os.path import join
1212
quapy_path = join(pathlib.Path(__file__).parents[2].resolve().as_posix(), 'quapy')
1313
wiki_path = join(pathlib.Path(__file__).parents[0].resolve().as_posix(), 'wiki')
14+
source_path = pathlib.Path(__file__).parents[2].resolve().as_posix()
1415
print(f'quapy path={quapy_path}')
16+
print(f'quapy source path={source_path}')
1517
sys.path.insert(0, quapy_path)
1618
sys.path.insert(0, wiki_path)
19+
sys.path.insert(0, source_path)
20+
21+
print(sys.path)
1722

1823

1924
project = 'QuaPy: A Python-based open-source framework for quantification'

docs/source/manuals/methods.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ The [](quapy.method.composable) module allows the composition of quantification
447447
```sh
448448
pip install --upgrade pip setuptools wheel
449449
pip install "jax[cpu]"
450-
pip install quapy[composable]
450+
pip install "qunfold @ git+https://github.com/mirkobunse/[email protected]"
451451
```
452452

453453
### Basics

examples/14.composable_methods.py

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
This example illustrates the composition of quantification methods from
33
arbitrary loss functions and feature transformations. It will extend the basic
44
example on the usage of quapy with this composition.
5+
6+
This example requires the installation of qunfold, the back-end of QuaPy's
7+
composition module:
8+
9+
pip install --upgrade pip setuptools wheel
10+
pip install "jax[cpu]"
11+
pip install "qunfold @ git+https://github.com/mirkobunse/[email protected]"
512
"""
613

714
import numpy as np

examples/4b.lequa2024_experiments.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
# model selection
3535
param_grid = {
36-
'classifier__C': np.logspace(-3, 3, 7), # classifier-dependent: inverse of regularization strength
37-
'classifier__class_weight': ['balanced', None], # classifier-dependent: weights of each class
38-
'bandwidth': np.linspace(0.01, 0.2, 20) # quantifier-dependent: bandwidth of the kernel
36+
'classifier__C': np.logspace(-3, 3, 7), # classifier-dependent: inverse of regularization strength
37+
'classifier__class_weight': ['balanced', None], # classifier-dependent: weights of each class
38+
'bandwidth': np.linspace(0.01, 0.2, 20) # quantifier-dependent: bandwidth of the kernel
3939
}
4040
model_selection = GridSearchQ(quantifier, param_grid, protocol=val_generator, error='mrae', refit=False, verbose=True)
4141
quantifier = model_selection.fit(training)

quapy/data/datasets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def fetch_UCIMulticlassDataset(
637637
if n_train > max_train_instances:
638638
train_prop = (max_train_instances / n)
639639

640-
data = Dataset(*data.split_stratified(train_prop, random_state=0))
640+
data = Dataset(*data.split_stratified(train_prop, random_state=0), name=dataset_name)
641641

642642
if standardize:
643643
data = standardizer(data)

quapy/method/composable.py

+51-39
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,57 @@
11
"""This module allows the composition of quantification methods from loss functions and feature transformations. This functionality is realized through an integration of the qunfold package: https://github.com/mirkobunse/qunfold."""
22

3-
import qunfold
4-
from qunfold.quapy import QuaPyWrapper
5-
from qunfold.sklearn import CVClassifier
6-
from qunfold import (
7-
LeastSquaresLoss, # losses
8-
BlobelLoss,
9-
EnergyLoss,
10-
HellingerSurrogateLoss,
11-
CombinedLoss,
12-
TikhonovRegularization,
13-
TikhonovRegularized,
14-
ClassTransformer, # transformers
15-
HistogramTransformer,
16-
DistanceTransformer,
17-
KernelTransformer,
18-
EnergyKernelTransformer,
19-
LaplacianKernelTransformer,
20-
GaussianKernelTransformer,
21-
GaussianRFFKernelTransformer,
22-
)
3+
_import_error_message = """qunfold, the back-end of quapy.method.composable, is not properly installed.
234
24-
__all__ = [ # control public members, e.g., for auto-documentation in sphinx; omit QuaPyWrapper
25-
"ComposableQuantifier",
26-
"CVClassifier",
27-
"LeastSquaresLoss",
28-
"BlobelLoss",
29-
"EnergyLoss",
30-
"HellingerSurrogateLoss",
31-
"CombinedLoss",
32-
"TikhonovRegularization",
33-
"TikhonovRegularized",
34-
"ClassTransformer",
35-
"HistogramTransformer",
36-
"DistanceTransformer",
37-
"KernelTransformer",
38-
"EnergyKernelTransformer",
39-
"LaplacianKernelTransformer",
40-
"GaussianKernelTransformer",
41-
"GaussianRFFKernelTransformer",
42-
]
5+
To fix this error, call:
6+
7+
pip install --upgrade pip setuptools wheel
8+
pip install "jax[cpu]"
9+
pip install "qunfold @ git+https://github.com/mirkobunse/[email protected]"
10+
"""
11+
12+
try:
13+
import qunfold
14+
from qunfold.quapy import QuaPyWrapper
15+
from qunfold.sklearn import CVClassifier
16+
from qunfold import (
17+
LeastSquaresLoss, # losses
18+
BlobelLoss,
19+
EnergyLoss,
20+
HellingerSurrogateLoss,
21+
CombinedLoss,
22+
TikhonovRegularization,
23+
TikhonovRegularized,
24+
ClassTransformer, # transformers
25+
HistogramTransformer,
26+
DistanceTransformer,
27+
KernelTransformer,
28+
EnergyKernelTransformer,
29+
LaplacianKernelTransformer,
30+
GaussianKernelTransformer,
31+
GaussianRFFKernelTransformer,
32+
)
33+
34+
__all__ = [ # control public members, e.g., for auto-documentation in sphinx; omit QuaPyWrapper
35+
"ComposableQuantifier",
36+
"CVClassifier",
37+
"LeastSquaresLoss",
38+
"BlobelLoss",
39+
"EnergyLoss",
40+
"HellingerSurrogateLoss",
41+
"CombinedLoss",
42+
"TikhonovRegularization",
43+
"TikhonovRegularized",
44+
"ClassTransformer",
45+
"HistogramTransformer",
46+
"DistanceTransformer",
47+
"KernelTransformer",
48+
"EnergyKernelTransformer",
49+
"LaplacianKernelTransformer",
50+
"GaussianKernelTransformer",
51+
"GaussianRFFKernelTransformer",
52+
]
53+
except ImportError as e:
54+
raise ImportError(_import_error_message) from e
4355

4456
def ComposableQuantifier(loss, transformer, **kwargs):
4557
"""A generic quantification / unfolding method that solves a linear system of equations.

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def get_version(rel_path):
125125
# projects.
126126
extras_require={ # Optional
127127
'bayes': ['jax', 'jaxlib', 'numpyro'],
128-
'composable': ['qunfold @ git+https://github.com/mirkobunse/[email protected]'],
129128
'neural': ['torch'],
130129
'tests': ['certifi'],
131130
'docs' : ['sphinx-rtd-theme', 'myst-parser'],

0 commit comments

Comments
 (0)