Skip to content

Commit

Permalink
DOC: simplify and improve example in quick_start.rst and plot_toy_mod…
Browse files Browse the repository at this point in the history
…el.py
  • Loading branch information
Valentin-Laurent committed Jan 31, 2025
1 parent b06d5b1 commit f6f052f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Binary file modified doc/images/quickstart_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 6 additions & 13 deletions doc/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Let us start with a basic regression problem.
Here, we generate one-dimensional noisy data that we fit with a linear model.

..
Comment to developers: the following piece of code is duplicated in `examples/regression/1-quickstart/plot_toy_model.py`.
Comment to developers: the following piece of code is heavily inspired by `examples/regression/1-quickstart/plot_toy_model.py`.
When updating it, please replicate the changes to this other file.
.. testcode::
Expand All @@ -46,25 +46,18 @@ Here, we generate one-dimensional noisy data that we fit with a linear model.
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

RANDOM_STATE = 42
X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=RANDOM_STATE)
X_train_conformalize, X_test, y_train_conformalize, y_test = train_test_split(
X, y, test_size=0.5, random_state=RANDOM_STATE
)
X_train, X_conformalize, y_train, y_conformalize = train_test_split(
X_train_conformalize, y_train_conformalize, test_size=0.5, random_state=RANDOM_STATE
)
X, y = make_regression(n_samples=500, n_features=1, noise=20)

X_train, X_temp, y_train, y_temp = train_test_split(X, y)
X_test, X_conformalize, y_test, y_conformalize = train_test_split(X_temp, y_temp)

# We follow a sequential ``fit``, ``conformalize``, and ``predict`` process.
# We set the confidence level to estimate prediction intervals at approximately one and two
# standard deviation from the mean.

from mapie_v1.regression import SplitConformalRegressor

mapie_regressor = SplitConformalRegressor(
confidence_level=[0.95, 0.68],
prefit=False,
)
mapie_regressor = SplitConformalRegressor(confidence_level=[0.95, 0.68], prefit=False)
mapie_regressor.fit(X_train, y_train)
mapie_regressor.conformalize(X_conformalize, y_conformalize)

Expand Down
10 changes: 6 additions & 4 deletions examples/regression/1-quickstart/plot_toy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
from mapie_v1.regression import SplitConformalRegressor

RANDOM_STATE = 42

X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=RANDOM_STATE)
X_train_conformalize, X_test, y_train_conformalize, y_test = train_test_split(
X, y, test_size=0.5, random_state=RANDOM_STATE

X_train, X_test_conformalize, y_train, y_test_conformalize = train_test_split(
X, y,test_size=0.4, random_state=RANDOM_STATE
)
X_train, X_conformalize, y_train, y_conformalize = train_test_split(
X_train_conformalize, y_train_conformalize, test_size=0.5, random_state=RANDOM_STATE
X_test, X_conformalize, y_test, y_conformalize = train_test_split(
X_test_conformalize, y_test_conformalize, test_size=0.5, random_state=RANDOM_STATE
)

confidence_level = [0.95, 0.68]
Expand Down

0 comments on commit f6f052f

Please sign in to comment.