Skip to content

Commit 6846dc1

Browse files
Merge branch 'master' into fix-gitignore-mondrian-doc
2 parents 71a3178 + 50a76b2 commit 6846dc1

File tree

11 files changed

+377
-8
lines changed

11 files changed

+377
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ target/
8686

8787
# ZIP files
8888
*.zip
89+
90+
# Pyenv
91+
.python-version

CONTRIBUTING.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,26 @@ Documenting your change
5050

5151
If you're adding a class or a function, then you'll need to add a docstring with a doctest. We follow the `numpy docstring convention <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html>`_, so please do too.
5252
Any estimator should follow the [scikit-learn API](https://scikit-learn.org/stable/developers/develop.html), so please follow these guidelines.
53-
In order to build the documentation locally, run :
53+
In order to build the documentation locally, you first need to install some dependencies :
54+
55+
Create a dedicated virtual environment via `conda`:
56+
57+
.. code:: sh
58+
59+
$ conda env create -f environment.doc.yml
60+
$ conda activate mapie-doc
61+
62+
Alternatively, using `pip`, create a different virtual environment than the one used for development, and install the dependencies:
63+
64+
.. code:: sh
65+
66+
$ pip install -r requirements.doc.txt
67+
$ pip install -e .
68+
69+
Finally, once dependencies are installed, you can build the documentation locally by running:
5470

5571
.. code:: sh
5672
57-
$ cd doc
5873
$ make clean-doc
5974
$ make doc
6075

HISTORY.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
History
33
=======
44

5-
0.9.x (2024-xx-xx)
5+
0.9.1 (2024-09-13)
66
------------------
7+
8+
* Fix issue 511 to access non-conformity scores with previous path
79
* Update gitignore by including the documentation folder generated for Mondrian
10+
* Fix (partially) the set-up with pip instead of conda for new contributors
11+
812

913

1014
0.9.0 (2024-09-03)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
from abc import ABCMeta, abstractmethod
2+
3+
from sklearn.utils import deprecated
4+
5+
from mapie.conformity_scores.regression import BaseConformityScore
6+
from mapie._machine_precision import EPSILON
7+
from mapie._typing import NDArray
8+
9+
10+
@deprecated(
11+
"WARNING: Deprecated path to import ConformityScore. "
12+
"Please prefer the new path: "
13+
"[from mapie.conformity_scores import BaseRegressionScore]."
14+
)
15+
class ConformityScore(BaseConformityScore, metaclass=ABCMeta):
16+
"""
17+
Base conformity score class for regression task.
18+
19+
This class should not be used directly. Use derived classes instead.
20+
21+
Parameters
22+
----------
23+
sym: bool
24+
Whether to consider the conformity score as symmetrical or not.
25+
26+
consistency_check: bool, optional
27+
Whether to check the consistency between the methods
28+
``get_estimation_distribution`` and ``get_conformity_scores``.
29+
If ``True``, the following equality must be verified:
30+
``self.get_estimation_distribution(
31+
y_pred, self.get_conformity_scores(y, y_pred, **kwargs), **kwargs
32+
) == y``
33+
34+
By default ``True``.
35+
36+
eps: float, optional
37+
Threshold to consider when checking the consistency between
38+
``get_estimation_distribution`` and ``get_conformity_scores``.
39+
It should be specified if ``consistency_check==True``.
40+
41+
By default, it is defined by the default precision.
42+
"""
43+
44+
def __init__(
45+
self,
46+
sym: bool,
47+
consistency_check: bool = True,
48+
eps: float = float(EPSILON),
49+
):
50+
super().__init__()
51+
self.sym = sym
52+
self.consistency_check = consistency_check
53+
self.eps = eps
54+
55+
@abstractmethod
56+
def get_signed_conformity_scores(
57+
self,
58+
y: NDArray,
59+
y_pred: NDArray,
60+
**kwargs
61+
) -> NDArray:
62+
"""
63+
Placeholder for ``get_conformity_scores``.
64+
Subclasses should implement this method!
65+
66+
Compute the sample conformity scores given the predicted and
67+
observed targets.
68+
69+
Parameters
70+
----------
71+
y: NDArray of shape (n_samples,)
72+
Observed target values.
73+
74+
y_pred: NDArray of shape (n_samples,)
75+
Predicted target values.
76+
77+
Returns
78+
-------
79+
NDArray of shape (n_samples,)
80+
Signed conformity scores.
81+
"""
82+
83+
@abstractmethod
84+
def get_conformity_scores(
85+
self,
86+
y: NDArray,
87+
y_pred: NDArray,
88+
**kwargs
89+
) -> NDArray:
90+
"""
91+
Placeholder for ``get_conformity_scores``.
92+
Subclasses should implement this method!
93+
94+
Compute the sample conformity scores given the predicted and
95+
observed targets.
96+
97+
Parameters
98+
----------
99+
y: NDArray of shape (n_samples,)
100+
Observed target values.
101+
102+
y_pred: NDArray of shape (n_samples,)
103+
Predicted target values.
104+
105+
Returns
106+
-------
107+
NDArray of shape (n_samples,)
108+
Conformity scores.
109+
"""
110+
111+
@abstractmethod
112+
def get_estimation_distribution(
113+
self,
114+
y_pred: NDArray,
115+
conformity_scores: NDArray,
116+
**kwargs
117+
) -> NDArray:
118+
"""
119+
Placeholder for ``get_estimation_distribution``.
120+
Subclasses should implement this method!
121+
122+
Compute samples of the estimation distribution given the predicted
123+
targets and the conformity scores.
124+
125+
Parameters
126+
----------
127+
y_pred: NDArray of shape (n_samples,)
128+
Predicted target values.
129+
130+
conformity_scores: NDArray of shape (n_samples,)
131+
Conformity scores.
132+
133+
Returns
134+
-------
135+
NDArray of shape (n_samples,)
136+
Observed values.
137+
"""
138+
139+
@abstractmethod
140+
def predict_set(
141+
self,
142+
X: NDArray,
143+
alpha_np: NDArray,
144+
**kwargs
145+
):
146+
"""
147+
Compute the prediction sets on new samples based on the uncertainty of
148+
the target confidence set.
149+
150+
Parameters:
151+
-----------
152+
X: NDArray of shape (n_samples,)
153+
The input data or samples for prediction.
154+
155+
alpha_np: NDArray of shape (n_alpha, )
156+
Represents the uncertainty of the confidence set to produce.
157+
158+
**kwargs: dict
159+
Additional keyword arguments.
160+
161+
Returns:
162+
--------
163+
The output structure depend on the subclass.
164+
The prediction sets for each sample and each alpha level.
165+
"""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from sklearn.utils import deprecated
2+
3+
from .bounds import (
4+
AbsoluteConformityScore as NewAbsoluteConformityScore,
5+
GammaConformityScore as NewGammaConformityScore,
6+
ResidualNormalisedScore as NewResidualNormalisedScore
7+
)
8+
9+
10+
@deprecated(
11+
"WARNING: Deprecated path to import AbsoluteConformityScore. "
12+
"Please prefer the new path: "
13+
"[from mapie.conformity_scores.bounds import AbsoluteConformityScore]."
14+
)
15+
class AbsoluteConformityScore(NewAbsoluteConformityScore):
16+
pass
17+
18+
19+
@deprecated(
20+
"WARNING: Deprecated path to import GammaConformityScore. "
21+
"Please prefer the new path: "
22+
"[from mapie.conformity_scores.bounds import GammaConformityScore]."
23+
)
24+
class GammaConformityScore(NewGammaConformityScore):
25+
pass
26+
27+
28+
@deprecated(
29+
"WARNING: Deprecated path to import ResidualNormalisedScore. "
30+
"Please prefer the new path: "
31+
"[from mapie.conformity_scores.bounds import ResidualNormalisedScore]."
32+
)
33+
class ResidualNormalisedScore(NewResidualNormalisedScore):
34+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from sklearn.utils import deprecated
2+
3+
from mapie.conformity_scores.sets.utils import (
4+
get_true_label_position as get_true_label_position_new_path,
5+
)
6+
7+
8+
@deprecated(
9+
"WARNING: Deprecated path to import get_true_label_position. "
10+
"Please prefer the new path: "
11+
"[from mapie.conformity_scores.sets.utils import get_true_label_position]."
12+
)
13+
def get_true_label_position(*args, **kwargs):
14+
return get_true_label_position_new_path(*args, **kwargs)

mapie/estimator/estimator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from sklearn.utils import deprecated
2+
3+
from mapie.estimator.regressor import EnsembleRegressor as NewEnsembleRegressor
4+
5+
6+
@deprecated(
7+
"WARNING: Deprecated path to import EnsembleRegressor. "
8+
"Please prefer the new path: "
9+
"[from mapie.estimator.regressor import EnsembleRegressor]."
10+
)
11+
class EnsembleRegressor(NewEnsembleRegressor):
12+
pass

0 commit comments

Comments
 (0)