Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
.PHONY: tests doc build

mapie_v0_folder_name = mapie_v0_package

lint:
flake8 . --exclude=doc

type-check:
mypy mapie

v1-type-check:
mypy mapie_v1 --exclude $(mapie_v0_folder_name)

tests:
pytest -vs --doctest-modules mapie

integration-tests-v1:
@pip install mapie --no-dependencies --target=./mapie_v1/integration_tests/mapie_v0_package >/dev/null 2>&1
@mv ./mapie_v1/integration_tests/mapie_v0_package/mapie ./mapie_v1/integration_tests/mapie_v0_package/mapiev0
@- export PYTHONPATH="${PYTHONPATH}:./mapie_v1/integration_tests/mapie_v0_package"; pytest -vs mapie_v1/integration_tests/tests -k $(pattern)
@mv ./mapie_v1/integration_tests/mapie_v0_package/mapiev0 ./mapie_v1/integration_tests/mapie_v0_package/mapie
@pip install mapie --no-dependencies --target=./mapie_v1/integration_tests/$(mapie_v0_folder_name) >/dev/null 2>&1
@mv ./mapie_v1/integration_tests/$(mapie_v0_folder_name)/mapie ./mapie_v1/integration_tests/$(mapie_v0_folder_name)/mapiev0
@- export PYTHONPATH="${PYTHONPATH}:./mapie_v1/integration_tests/$(mapie_v0_folder_name)"; pytest -vs mapie_v1/integration_tests/tests -k $(pattern)
@mv ./mapie_v1/integration_tests/$(mapie_v0_folder_name)/mapiev0 ./mapie_v1/integration_tests/$(mapie_v0_folder_name)/mapie

coverage:
pytest -vs \
Expand Down
Empty file added mapie_v1/__init__.py
Empty file.
9 changes: 8 additions & 1 deletion mapie_v1/_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Union, List
from typing import Union, List, Tuple, cast

from numpy import array
from mapie._typing import ArrayLike, NDArray
Expand Down Expand Up @@ -56,3 +56,10 @@ def make_intervals_single_if_single_alpha(
if len(alphas) == 1:
return intervals[:, :, 0]
return intervals


def cast_point_predictions_to_ndarray(
point_predictions: Union[NDArray, Tuple[NDArray, NDArray]]
) -> NDArray:
# This will be useless when we split .predict and .predict_set in back-end
return cast(NDArray, point_predictions)
18 changes: 9 additions & 9 deletions mapie_v1/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def fit(
y_train: ArrayLike,
fit_params: Optional[dict] = None,
) -> Self:
pass
return self

def conformalize(
self,
X_conf: ArrayLike,
y_conf: ArrayLike,
predict_params: Optional[dict] = None,
) -> Self:
pass
return self

def predict(self, X: ArrayLike) -> NDArray:
"""
Expand All @@ -49,7 +49,7 @@ def predict(self, X: ArrayLike) -> NDArray:
scikit-learn classifiers
Shape (n_samples,)
"""
pass
return np.ndarray(0)

def predict_sets(
self,
Expand All @@ -66,7 +66,7 @@ def predict_sets(
Shape (n_samples, n_classes, confidence_level) if confidence_level
is a list of floats
"""
pass
return np.ndarray(0)


class CrossConformalClassifier:
Expand All @@ -89,26 +89,26 @@ def fit(
y_train: ArrayLike,
fit_params: Optional[dict] = None,
) -> Self:
pass
return self

def conformalize(
self,
X_conf: ArrayLike,
y_conf: ArrayLike,
predict_params: Optional[dict] = None
) -> Self:
pass
return self

def predict(self,
X: ArrayLike):
X: ArrayLike) -> NDArray:
"""
Return
-----
Return ponctual prediction similar to predict method of
scikit-learn classifiers
Shape (n_samples,)
"""
pass
return np.ndarray(0)

def predict_sets(
self,
Expand All @@ -125,4 +125,4 @@ def predict_sets(
Shape (n_samples, n_classes, confidence_level) if confidence_level
is a list of floats
"""
pass
return np.ndarray(0)
24 changes: 17 additions & 7 deletions mapie_v1/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
)
from mapie_v1._utils import transform_confidence_level_to_alpha_list, \
check_method_not_naive, check_cv_not_string, hash_X_y, \
check_if_X_y_different_from_fit, make_intervals_single_if_single_alpha
check_if_X_y_different_from_fit, make_intervals_single_if_single_alpha, \
cast_point_predictions_to_ndarray


class SplitConformalRegressor:
Expand Down Expand Up @@ -237,7 +238,7 @@ def predict(
Array of point predictions, with shape (n_samples,).
"""
predictions = self._mapie_regressor.predict(X, alpha=None)
return predictions
return cast_point_predictions_to_ndarray(predictions)


class CrossConformalRegressor:
Expand Down Expand Up @@ -439,6 +440,8 @@ def conformalize(
predict_params=predict_params
)

return self

def predict_set(
self,
X: ArrayLike,
Expand Down Expand Up @@ -518,7 +521,10 @@ def predict(
self._mapie_regressor._check_agg_function(aggregation_method)
self._mapie_regressor.agg_function = aggregation_method

return self._mapie_regressor.predict(X, alpha=None, ensemble=ensemble)
predictions = self._mapie_regressor.predict(
X, alpha=None, ensemble=ensemble
)
return cast_point_predictions_to_ndarray(predictions)


class JackknifeAfterBootstrapRegressor:
Expand Down Expand Up @@ -627,6 +633,7 @@ def fit(
Self
The fitted JackknifeAfterBootstrapRegressor instance.
"""
return self

def conformalize(
self,
Expand Down Expand Up @@ -659,6 +666,7 @@ def conformalize(
The JackknifeAfterBootstrapRegressor instance with
calibrated prediction intervals.
"""
return self

def predict_set(
self,
Expand All @@ -684,7 +692,7 @@ def predict_set(
Prediction intervals of shape `(n_samples, 2)`,
with lower and upper bounds for each sample.
"""
pass
return np.ndarray(0)

def predict(
self,
Expand Down Expand Up @@ -712,7 +720,7 @@ def predict(
NDArray
Array of point predictions, with shape `(n_samples,)`.
"""
pass
return np.ndarray(0)


class ConformalizedQuantileRegressor:
Expand Down Expand Up @@ -824,6 +832,7 @@ def fit(
Self
The fitted ConformalizedQuantileRegressor instance.
"""
return self

def conformalize(
self,
Expand Down Expand Up @@ -855,6 +864,7 @@ def conformalize(
The ConformalizedQuantileRegressor instance with calibrated
prediction intervals.
"""
return self

def predict_set(
self,
Expand Down Expand Up @@ -892,7 +902,7 @@ def predict_set(
Prediction intervals with shape `(n_samples, 2)`, with lower
and upper bounds for each sample.
"""
pass
return np.ndarray(0)

def predict(
self,
Expand All @@ -911,7 +921,7 @@ def predict(
NDArray
Array of point predictions with shape `(n_samples,)`.
"""
pass
return np.ndarray(0)


class GibbsConformalRegressor:
Expand Down
Loading