Skip to content

Commit

Permalink
UPD: change name of crf score class
Browse files Browse the repository at this point in the history
  • Loading branch information
Candice Moyet committed Jul 19, 2023
1 parent b27c567 commit ec7eab2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions mapie/conformity_scores/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .conformity_scores import ConformityScore
from .residual_conformity_scores import (AbsoluteConformityScore,
GammaConformityScore,
FittedResidualNormalisingScore)
ConformalResidualFittingScore)

__all__ = [
"ConformityScore",
"AbsoluteConformityScore",
"GammaConformityScore",
"FittedResidualNormalisingScore"
"ConformalResidualFittingScore"
]
6 changes: 2 additions & 4 deletions mapie/conformity_scores/residual_conformity_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ def get_estimation_distribution(
return np.multiply(y_pred, np.add(1, conformity_scores))


class FittedResidualNormalisingScore(ConformityScore):
# or ConformalResiudalFittingScore
# or NormalizedScore
class ConformalResidualFittingScore(ConformityScore):
"""
FittedResidualNormalisingScore (also called CRF) score.
ConformalResidualFittingScore (CRF) score.
The signed conformity score = (y - y_pred) / r_pred. r_pred being the
predicted residual (|y - y_pred|) of the base estimator.
Expand Down
4 changes: 2 additions & 2 deletions mapie/regression/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mapie._typing import ArrayLike, NDArray
from mapie.conformity_scores import (ConformityScore,
FittedResidualNormalisingScore)
ConformalResidualFittingScore)
from mapie.estimator.estimator import EnsembleRegressor
from mapie.utils import (check_alpha, check_alpha_and_n_samples,
check_conformity_score, check_cv,
Expand Down Expand Up @@ -420,7 +420,7 @@ def _check_fit_parameters(
cs_estimator = check_conformity_score(
self.conformity_score
)
if isinstance(cs_estimator, FittedResidualNormalisingScore) and \
if isinstance(cs_estimator, ConformalResidualFittingScore) and \
self.cv not in ["split", "prefit"]:
raise ValueError(
"The FittedResisualNormalizingScore can be used only with "
Expand Down
18 changes: 9 additions & 9 deletions mapie/tests/test_conformity_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from mapie.conformity_scores import (AbsoluteConformityScore,
ConformityScore,
GammaConformityScore,
FittedResidualNormalisingScore)
ConformalResidualFittingScore)
from mapie.regression import MapieRegressor

X_toy = np.array([0, 1, 2, 3, 4, 5]).reshape(-1, 1)
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_crf_prefit_conformity_score_get_conformity_scores(
when prefit is True.
"""
residual_estimator = LinearRegression().fit(X_toy, y_toy)
crf_conf_score = FittedResidualNormalisingScore(
crf_conf_score = ConformalResidualFittingScore(
residual_estimator=residual_estimator,
prefit=True,
random_state=random_state
Expand All @@ -249,7 +249,7 @@ def test_crf_conformity_score_get_conformity_scores(y_pred: NDArray) -> None:
Test conformity score computation for ConformalResidualFittingScore
when prefit is False.
"""
crf_conf_score = FittedResidualNormalisingScore(random_state=random_state)
crf_conf_score = ConformalResidualFittingScore(random_state=random_state)
conf_scores = crf_conf_score.get_conformity_scores(
X_toy, y_toy, y_pred
)
Expand All @@ -261,7 +261,7 @@ def test_crf_conformity_score_get_conformity_scores(y_pred: NDArray) -> None:

def test_crf_score_prefit_with_notfitted_estim() -> None:
"""Test that a not fitted estimator and prefit=True raises an error."""
crf_conf_score = FittedResidualNormalisingScore(
crf_conf_score = ConformalResidualFittingScore(
residual_estimator=LinearRegression(), prefit=True
)
with pytest.raises(ValueError):
Expand All @@ -272,7 +272,7 @@ def test_crf_score_prefit_with_notfitted_estim() -> None:

def test_crf_score_prefit_with_default_params() -> None:
"""Test that no error is raised with default parameters."""
crf_conf_score = FittedResidualNormalisingScore()
crf_conf_score = ConformalResidualFittingScore()
conf_scores = crf_conf_score.get_conformity_scores(
X_toy, y_toy, y_pred_list
)
Expand All @@ -286,7 +286,7 @@ class DumbEstimator:
def __init__(self):
pass

crf_conf_score = FittedResidualNormalisingScore(
crf_conf_score = ConformalResidualFittingScore(
residual_estimator=DumbEstimator()
)
with pytest.raises(ValueError):
Expand All @@ -298,7 +298,7 @@ def __init__(self):
def test_cross_crf() -> None:
"""Test that crf score called with cross method raises an error."""
with pytest.raises(ValueError):
MapieRegressor(conformity_score=FittedResidualNormalisingScore()).fit(
MapieRegressor(conformity_score=ConformalResidualFittingScore()).fit(
X_toy, y_toy
)

Expand All @@ -312,7 +312,7 @@ def test_crf_score_pipe() -> None:
("linear", LinearRegression())
])
mapie_reg = MapieRegressor(
conformity_score=FittedResidualNormalisingScore(
conformity_score=ConformalResidualFittingScore(
residual_estimator=pipe, split_size=0.2
),
cv="split",
Expand All @@ -333,7 +333,7 @@ def test_crf_score_pipe_prefit() -> None:
])
pipe.fit(X_toy, y_toy)
mapie_reg = MapieRegressor(
conformity_score=FittedResidualNormalisingScore(
conformity_score=ConformalResidualFittingScore(
residual_estimator=pipe, split_size=0.2, prefit=True
),
cv="split",
Expand Down
4 changes: 2 additions & 2 deletions mapie/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from mapie.conformity_scores import (AbsoluteConformityScore,
ConformityScore,
GammaConformityScore,
FittedResidualNormalisingScore)
ConformalResidualFittingScore)
from mapie.metrics import regression_coverage_score
from mapie.regression import MapieRegressor
from mapie.estimator.estimator import EnsembleRegressor
Expand Down Expand Up @@ -593,7 +593,7 @@ def test_conformity_score(


@pytest.mark.parametrize(
"conformity_score", [FittedResidualNormalisingScore()]
"conformity_score", [ConformalResidualFittingScore()]
)
def test_conformity_score_with_split_strategies(
conformity_score: ConformityScore
Expand Down

0 comments on commit ec7eab2

Please sign in to comment.