Skip to content

Commit f6f052f

Browse files
DOC: simplify and improve example in quick_start.rst and plot_toy_model.py
1 parent b06d5b1 commit f6f052f

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

doc/images/quickstart_1.png

-8.75 KB
Loading

doc/quick_start.rst

+6-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Let us start with a basic regression problem.
3737
Here, we generate one-dimensional noisy data that we fit with a linear model.
3838

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

49-
RANDOM_STATE = 42
50-
X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=RANDOM_STATE)
51-
X_train_conformalize, X_test, y_train_conformalize, y_test = train_test_split(
52-
X, y, test_size=0.5, random_state=RANDOM_STATE
53-
)
54-
X_train, X_conformalize, y_train, y_conformalize = train_test_split(
55-
X_train_conformalize, y_train_conformalize, test_size=0.5, random_state=RANDOM_STATE
56-
)
49+
X, y = make_regression(n_samples=500, n_features=1, noise=20)
50+
51+
X_train, X_temp, y_train, y_temp = train_test_split(X, y)
52+
X_test, X_conformalize, y_test, y_conformalize = train_test_split(X_temp, y_temp)
5753

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

6258
from mapie_v1.regression import SplitConformalRegressor
6359

64-
mapie_regressor = SplitConformalRegressor(
65-
confidence_level=[0.95, 0.68],
66-
prefit=False,
67-
)
60+
mapie_regressor = SplitConformalRegressor(confidence_level=[0.95, 0.68], prefit=False)
6861
mapie_regressor.fit(X_train, y_train)
6962
mapie_regressor.conformalize(X_conformalize, y_conformalize)
7063

examples/regression/1-quickstart/plot_toy_model.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
from mapie_v1.regression import SplitConformalRegressor
1515

1616
RANDOM_STATE = 42
17+
1718
X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=RANDOM_STATE)
18-
X_train_conformalize, X_test, y_train_conformalize, y_test = train_test_split(
19-
X, y, test_size=0.5, random_state=RANDOM_STATE
19+
20+
X_train, X_test_conformalize, y_train, y_test_conformalize = train_test_split(
21+
X, y,test_size=0.4, random_state=RANDOM_STATE
2022
)
21-
X_train, X_conformalize, y_train, y_conformalize = train_test_split(
22-
X_train_conformalize, y_train_conformalize, test_size=0.5, random_state=RANDOM_STATE
23+
X_test, X_conformalize, y_test, y_conformalize = train_test_split(
24+
X_test_conformalize, y_test_conformalize, test_size=0.5, random_state=RANDOM_STATE
2325
)
2426

2527
confidence_level = [0.95, 0.68]

0 commit comments

Comments
 (0)