From ec7eab23446a7c6a08043fc541aedc72a5fed783 Mon Sep 17 00:00:00 2001 From: Candice Moyet Date: Wed, 19 Jul 2023 09:35:16 +0200 Subject: [PATCH] UPD: change name of crf score class --- mapie/conformity_scores/__init__.py | 4 ++-- .../residual_conformity_scores.py | 6 ++---- mapie/regression/regression.py | 4 ++-- mapie/tests/test_conformity_scores.py | 18 +++++++++--------- mapie/tests/test_regression.py | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/mapie/conformity_scores/__init__.py b/mapie/conformity_scores/__init__.py index 27c12ceb..5402571a 100644 --- a/mapie/conformity_scores/__init__.py +++ b/mapie/conformity_scores/__init__.py @@ -1,11 +1,11 @@ from .conformity_scores import ConformityScore from .residual_conformity_scores import (AbsoluteConformityScore, GammaConformityScore, - FittedResidualNormalisingScore) + ConformalResidualFittingScore) __all__ = [ "ConformityScore", "AbsoluteConformityScore", "GammaConformityScore", - "FittedResidualNormalisingScore" + "ConformalResidualFittingScore" ] diff --git a/mapie/conformity_scores/residual_conformity_scores.py b/mapie/conformity_scores/residual_conformity_scores.py index 02213c61..812c4cd5 100644 --- a/mapie/conformity_scores/residual_conformity_scores.py +++ b/mapie/conformity_scores/residual_conformity_scores.py @@ -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. diff --git a/mapie/regression/regression.py b/mapie/regression/regression.py index f2fb4663..61055dde 100644 --- a/mapie/regression/regression.py +++ b/mapie/regression/regression.py @@ -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, @@ -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 " diff --git a/mapie/tests/test_conformity_scores.py b/mapie/tests/test_conformity_scores.py index 6830bfc3..e1c41709 100644 --- a/mapie/tests/test_conformity_scores.py +++ b/mapie/tests/test_conformity_scores.py @@ -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) @@ -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 @@ -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 ) @@ -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): @@ -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 ) @@ -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): @@ -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 ) @@ -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", @@ -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", diff --git a/mapie/tests/test_regression.py b/mapie/tests/test_regression.py index cf529ef5..cf0c9629 100644 --- a/mapie/tests/test_regression.py +++ b/mapie/tests/test_regression.py @@ -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 @@ -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