Skip to content

Commit

Permalink
DOC: fix docstrings including examples, test v1 docstring examples in…
Browse files Browse the repository at this point in the history
… CI (#581)

Co-authored-by: Valentin Laurent <[email protected]>
  • Loading branch information
jawadhussein462 and Valentin-Laurent committed Jan 6, 2025
1 parent 5475b33 commit efeb281
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 30 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ v1-type-check:

tests:
pytest -vs --doctest-modules mapie
pytest -vs --doctest-modules mapie_v1 --ignore=mapie_v1/integration_tests

integration-tests-v1:
@pip install git+https://github.com/scikit-learn-contrib/MAPIE@master --no-dependencies --target=./mapie_v1/integration_tests/$(mapie_v0_folder_name) >/dev/null 2>&1
Expand Down
129 changes: 99 additions & 30 deletions mapie_v1/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SplitConformalRegressor:
The conformity score method used to calculate the conformity error.
Valid options: see keys and values of the dictionnary
:py:const:`mapie_v1.conformity_scores.REGRESSION_CONFORMITY_SCORES_STRING_MAP`.
See :doc:`theoretical_description_conformity_scores`
See :ref:`theoretical_description_conformity_scores`
A custom score function inheriting from BaseRegressionScore may also
be provided.
Expand Down Expand Up @@ -74,11 +74,30 @@ class SplitConformalRegressor:
Examples
--------
>>> regressor = SplitConformalRegressor(estimator=LinearRegression(),
confidence_level=0.95)
>>> regressor.fit(X_train, y_train)
>>> regressor.conformalize(X_conf, y_conf)
>>> intervals = regressor.predict_set(X_test)
>>> from mapie_v1.regression import SplitConformalRegressor
>>> from sklearn.datasets import make_regression
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import Ridge
>>> X, y = make_regression(n_samples=500, n_features=2, noise=1.0)
>>> X_train, X_test_initial, y_train, y_test_initial = train_test_split(
... X,
... y,
... test_size=0.2,
... )
>>> X_conf, X_test, y_conf, y_test = train_test_split(
... X_test_initial,
... y_test_initial,
... test_size=0.5,
... )
>>> mapie_regressor = SplitConformalRegressor(
... estimator=Ridge(),
... confidence_level=0.95
... ).fit(X_train, y_train).conformalize(X_conf, y_conf)
>>> prediction_points = mapie_regressor.predict(X_test)
>>> prediction_intervals = mapie_regressor.predict_set(X_test)
"""

def __init__(
Expand Down Expand Up @@ -268,7 +287,7 @@ class CrossConformalRegressor:
The conformity score method used to calculate the conformity error.
Valid options: TODO : reference here the valid options, once the list
has been be created during the implementation.
See :doc:`theoretical_description_conformity_scores`
See :ref:`theoretical_description_conformity_scores`
A custom score function inheriting from BaseRegressionScore may also be
provided.
Expand Down Expand Up @@ -313,11 +332,30 @@ class CrossConformalRegressor:
Examples
--------
>>> regressor = CrossConformalRegressor(
... estimator=LinearRegression(), confidence_level=0.95, cv=10)
>>> regressor.fit(X, y)
>>> regressor.conformalize(X, y)
>>> intervals = regressor.predict_set(X_test)
>>> from mapie_v1.regression import CrossConformalRegressor
>>> from sklearn.datasets import make_regression
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import Ridge
>>> X_initial, y_initial = make_regression(
... n_samples=500,
... n_features=2,
... noise=1.0
... )
>>> X, X_test, y, y_test = train_test_split(
... X_initial,
... y_initial,
... test_size=0.2,
... )
>>> mapie_regressor = CrossConformalRegressor(
... estimator=Ridge(),
... confidence_level=0.95,
... cv=10
... ).fit(X, y).conformalize(X, y)
>>> prediction_points = mapie_regressor.predict(X_test)
>>> prediction_intervals = mapie_regressor.predict_set(X_test)
"""

_VALID_METHODS = ["base", "plus", "minmax"]
Expand Down Expand Up @@ -562,7 +600,7 @@ class JackknifeAfterBootstrapRegressor:
The conformity score method used to calculate the conformity error.
Valid options: TODO : reference here the valid options, once the list
has been be created during the implementation.
See :doc:`theoretical_description_conformity_scores`
See :ref:`theoretical_description_conformity_scores`
A custom score function inheriting from BaseRegressionScore may also
be provided.
Expand Down Expand Up @@ -606,14 +644,30 @@ class JackknifeAfterBootstrapRegressor:
Examples
--------
>>> regressor = JackknifeAfterBootstrapRegressor(
... estimator=LinearRegression(),
... confidence_level=0.9,
... resampling=8,
... aggregation_method="mean")
>>> regressor.fit(X_train, y_train)
>>> regressor.conformalize(X_conf, y_conf)
>>> intervals = regressor.predict_set(X_test)
>>> from mapie_v1.regression import JackknifeAfterBootstrapRegressor
>>> from sklearn.datasets import make_regression
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import Ridge
>>> X_initial, y_initial = make_regression(
... n_samples=500,
... n_features=2,
... noise=1.0
... )
>>> X, X_test, y, y_test = train_test_split(
... X_initial,
... y_initial,
... test_size=0.2,
... )
>>> mapie_regressor = JackknifeAfterBootstrapRegressor(
... estimator=Ridge(),
... confidence_level=0.95,
... resampling=25,
... ).fit(X, y).conformalize(X, y)
>>> prediction_points = mapie_regressor.predict(X_test)
>>> prediction_intervals = mapie_regressor.predict_set(X_test)
"""

_VALID_METHODS = ["plus", "minmax"]
Expand Down Expand Up @@ -907,11 +961,30 @@ class ConformalizedQuantileRegressor:
Examples
--------
>>> regressor = ConformalizedQuantileRegressor(
... estimator=QuantileRegressor(), confidence_level=0.95)
>>> regressor.fit(X_train, y_train)
>>> regressor.conformalize(X_conf, y_conf)
>>> intervals = regressor.predict_set(X_test)
>>> from mapie_v1.regression import ConformalizedQuantileRegressor
>>> from sklearn.datasets import make_regression
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import QuantileRegressor
>>> X, y = make_regression(n_samples=500, n_features=2, noise=1.0)
>>> X_train, X_test_initial, y_train, y_test_initial = train_test_split(
... X,
... y,
... test_size=0.2,
... )
>>> X_conf, X_test, y_conf, y_test = train_test_split(
... X_test_initial,
... y_test_initial,
... test_size=0.5,
... )
>>> mapie_regressor = ConformalizedQuantileRegressor(
... estimator=QuantileRegressor(),
... confidence_level=0.95,
... ).fit(X_train, y_train).conformalize(X_conf, y_conf)
>>> prediction_points = mapie_regressor.predict(X_test)
>>> prediction_intervals = mapie_regressor.predict_set(X_test)
"""

def __init__(
Expand Down Expand Up @@ -1098,7 +1171,3 @@ def predict(
estimator = self._mapie_quantile_regressor
predictions, _ = estimator.predict(X, **self.predict_params)
return predictions


class GibbsConformalRegressor:
pass # TODO

0 comments on commit efeb281

Please sign in to comment.