Skip to content

Commit 3c29bb0

Browse files
MTN: move v1 utils in mapie/utils.py, make all utils private except train_conformalize_test_split
1 parent 8bffe03 commit 3c29bb0

31 files changed

+741
-738
lines changed

doc/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Utils (from mapie_v1)
9898
:toctree: generated/
9999
:template: function.rst
100100

101-
mapie_v1.utils.train_conformalize_test_split
101+
mapie.utils.train_conformalize_test_split
102102

103103
Conformity Scores (Regression)
104104
==============================

doc/split_cross_conformal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In all cases, the training/conformalization process can be broken down as follow
1818
==============================
1919

2020
- Compute conformity scores ("conformalization") on a conformity set not seen by the model during training.
21-
(Use :func:`~mapie_v1.utils.train_conformalize_test_split` to obtain the different sets.)
21+
(Use :func:`~mapie.utils.train_conformalize_test_split` to obtain the different sets.)
2222

2323
**MAPIE** then uses the conformity scores to estimate sets associated with the desired coverage on new data with strong theoretical guarantees.
2424

examples/mondrian/1-quickstart/plot_main-tutorial-mondrian-regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from sklearn.ensemble import RandomForestRegressor
4646

4747
from mapie.metrics.regression import regression_coverage_score
48-
from mapie_v1.utils import train_conformalize_test_split
48+
from mapie.utils import train_conformalize_test_split
4949
from mapie.regression import SplitConformalRegressor
5050

5151
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"

examples/regression/1-quickstart/plot_prefit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from numpy.typing import NDArray
3030
from mapie.metrics.regression import regression_coverage_score
3131
from mapie.regression import SplitConformalRegressor, ConformalizedQuantileRegressor
32-
from mapie_v1.utils import train_conformalize_test_split
32+
from mapie.utils import train_conformalize_test_split
3333

3434
warnings.filterwarnings("ignore")
3535

examples/regression/1-quickstart/plot_toy_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from mapie.metrics.regression import regression_coverage_score
1313
from mapie.regression import SplitConformalRegressor
14-
from mapie_v1.utils import train_conformalize_test_split
14+
from mapie.utils import train_conformalize_test_split
1515

1616
RANDOM_STATE = 42
1717

examples/regression/2-advanced-analysis/plot_ResidualNormalisedScore_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
regression_ssc_score,
2727
)
2828
from mapie.regression import SplitConformalRegressor
29-
from mapie_v1.utils import train_conformalize_test_split
29+
from mapie.utils import train_conformalize_test_split
3030

3131
warnings.filterwarnings("ignore")
3232

examples/regression/2-advanced-analysis/plot_conformal_predictive_distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from mapie.conformity_scores import (AbsoluteConformityScore,
2828
ResidualNormalisedScore)
2929
from mapie.regression import SplitConformalRegressor
30-
from mapie_v1.utils import train_conformalize_test_split
30+
from mapie.utils import train_conformalize_test_split
3131

3232
warnings.filterwarnings('ignore')
3333

examples/regression/2-advanced-analysis/plot_cqr_symmetry_difference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from mapie.metrics.regression import regression_coverage_score
1616
from mapie.regression import ConformalizedQuantileRegressor
17-
from mapie_v1.utils import train_conformalize_test_split
17+
from mapie.utils import train_conformalize_test_split
1818

1919
RANDOM_STATE = 1
2020

mapie/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from . import classification, metrics, regression
1+
from . import classification, metrics, regression, utils
22
from ._version import __version__
33

44
__all__ = [
55
"regression",
66
"classification",
77
"metrics",
8+
"utils",
89
"__version__"
910
]

mapie/calibration.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
indexable)
1414

1515
from numpy.typing import ArrayLike, NDArray
16-
from .utils import (check_estimator_classification,
17-
check_estimator_fit_predict, check_n_features_in,
18-
check_null_weight, fit_estimator, get_calib_set)
16+
from .utils import (_check_estimator_classification,
17+
_check_estimator_fit_predict, _check_n_features_in,
18+
_check_null_weight, _fit_estimator, _get_calib_set)
1919

2020

2121
class MapieCalibrator(BaseEstimator, ClassifierMixin):
@@ -202,7 +202,7 @@ def _check_calibrator(
202202
"Please provide a string in: "
203203
+ (", ").join(self.named_calibrators.keys()) + "."
204204
)
205-
check_estimator_fit_predict(calibrator)
205+
_check_estimator_fit_predict(calibrator)
206206
return calibrator
207207

208208
def _get_labels(
@@ -313,14 +313,14 @@ def _fit_calibrator(
313313
sample_weight_ = sample_weight[given_label_indices]
314314
(
315315
sample_weight_, top_class_prob_, y_calib_
316-
) = check_null_weight(
316+
) = _check_null_weight(
317317
sample_weight_,
318318
top_class_prob_,
319319
y_calib_
320320
)
321321
else:
322322
sample_weight_ = sample_weight
323-
calibrator_ = fit_estimator(
323+
calibrator_ = _fit_estimator(
324324
calibrator_, top_class_prob_, y_calib_, sample_weight_
325325
)
326326
return calibrator_
@@ -479,10 +479,10 @@ def fit(
479479
X, y = indexable(X, y)
480480
y = _check_y(y)
481481
self._check_type_of_target(y)
482-
estimator = check_estimator_classification(X, y, cv, self.estimator)
482+
estimator = _check_estimator_classification(X, y, cv, self.estimator)
483483
calibrator = self._check_calibrator(self.calibrator)
484-
sample_weight, X, y = check_null_weight(sample_weight, X, y)
485-
self.n_features_in_ = check_n_features_in(X, cv, estimator)
484+
sample_weight, X, y = _check_null_weight(sample_weight, X, y)
485+
self.n_features_in_ = _check_n_features_in(X, cv, estimator)
486486
random_state = check_random_state(random_state)
487487

488488
if cv == "prefit":
@@ -493,7 +493,7 @@ def fit(
493493
X, y, sample_weight, calibrator
494494
)
495495
if cv == "split":
496-
results = get_calib_set(
496+
results = _get_calib_set(
497497
X,
498498
y,
499499
sample_weight=sample_weight,
@@ -505,12 +505,12 @@ def fit(
505505
X_train, y_train, X_calib, y_calib, sw_train, sw_calib = results
506506
X_train, y_train = indexable(X_train, y_train)
507507
y_train = _check_y(y_train)
508-
sw_train, X_train, y_train = check_null_weight(
508+
sw_train, X_train, y_train = _check_null_weight(
509509
sw_train,
510510
X_train,
511511
y_train
512512
)
513-
estimator = fit_estimator(
513+
estimator = _fit_estimator(
514514
clone(estimator), X_train, y_train, sw_train, **fit_params,
515515
)
516516
self.single_estimator_ = estimator

0 commit comments

Comments
 (0)