Skip to content

Commit ae51184

Browse files
committed
modifications documentation
1 parent 4f359a7 commit ae51184

File tree

9 files changed

+22
-58
lines changed

9 files changed

+22
-58
lines changed

doc/tutorial_regression.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ next figure.
577577
fig = plt.figure()
578578
heteroscedastic_coverage.T.plot.bar(figsize=(12, 4), alpha=0.7)
579579
plt.axhline(0.95, ls="--", color="k")
580-
plt.ylim([0.8, 1])
581580
plt.ylabel("Conditional coverage")
582581
plt.xlabel("x bins")
583582
plt.xticks(rotation=0)
-899 Bytes
Loading
-28 Bytes
Loading

examples/regression/1-quickstart/plot_heteroscedastic_1d_data.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import scipy
1616
import numpy as np
1717
from sklearn.linear_model import LinearRegression, QuantileRegressor
18-
from sklearn.model_selection import train_test_split
1918
from sklearn.pipeline import Pipeline
2019
from sklearn.preprocessing import PolynomialFeatures
2120
from matplotlib import pyplot as plt
@@ -25,6 +24,8 @@
2524
from mapie.subsample import Subsample
2625
from mapie._typing import NDArray
2726

27+
random_state = 42
28+
2829

2930
def f(x: NDArray) -> NDArray:
3031
"""Polynomial function used to generate one-dimensional data"""
@@ -59,7 +60,7 @@ def get_heteroscedastic_data(
5960
[3]: y_true
6061
[4]: y_true_sigma
6162
"""
62-
np.random.seed(59)
63+
np.random.seed(random_state)
6364
q95 = scipy.stats.norm.ppf(0.95)
6465
X_train = np.linspace(0, 1, n_train)
6566
X_true = np.linspace(0, 1, n_true)
@@ -158,22 +159,8 @@ def plot_1d_data(
158159
polyn_model_quant,
159160
**params
160161
)
161-
X_train_split, X_calib, y_train_spit, y_calib = train_test_split(
162-
X_train,
163-
y_train,
164-
test_size=0.3,
165-
random_state=1
166-
)
167-
mapie.fit(
168-
X_train_split.reshape(-1, 1),
169-
y_train_spit,
170-
X_calib=X_calib.reshape(-1, 1),
171-
y_calib=y_calib
172-
)
173-
y_pred, y_pis = mapie.predict(
174-
X_test.reshape(-1, 1)
175-
)
176-
X_train, y_train = X_train_split, y_train_spit
162+
mapie.fit(X_train.reshape(-1, 1), y_train, random_state=random_state)
163+
y_pred, y_pis = mapie.predict(X_test.reshape(-1, 1))
177164
else:
178165
mapie = MapieRegressor( # type: ignore
179166
polyn_model,

examples/regression/1-quickstart/plot_homoscedastic_1d_data.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import scipy
1414
import numpy as np
1515
from sklearn.linear_model import LinearRegression, QuantileRegressor
16-
from sklearn.model_selection import train_test_split
1716
from sklearn.pipeline import Pipeline
1817
from sklearn.preprocessing import PolynomialFeatures
1918
from matplotlib import pyplot as plt
@@ -23,6 +22,8 @@
2322
from mapie.subsample import Subsample
2423
from mapie._typing import NDArray
2524

25+
random_state = 42
26+
2627

2728
def f(x: NDArray) -> NDArray:
2829
"""Polynomial function used to generate one-dimensional data"""
@@ -57,7 +58,7 @@ def get_homoscedastic_data(
5758
[3]: y_true
5859
[4]: y_true_sigma
5960
"""
60-
np.random.seed(59)
61+
np.random.seed(random_state)
6162
q95 = scipy.stats.norm.ppf(0.95)
6263
X_train = np.linspace(0, 1, n_train)
6364
X_true = np.linspace(0, 1, n_true)
@@ -156,18 +157,7 @@ def plot_1d_data(
156157
polyn_model_quant,
157158
**params
158159
)
159-
X_train, X_calib, y_train, y_calib = train_test_split(
160-
X_train,
161-
y_train,
162-
test_size=0.3,
163-
random_state=1
164-
)
165-
mapie.fit(
166-
X_train.reshape(-1, 1),
167-
y_train,
168-
X_calib=X_calib.reshape(-1, 1),
169-
y_calib=y_calib
170-
)
160+
mapie.fit(X_train.reshape(-1, 1), y_train, random_state=random_state)
171161
y_pred, y_pis = mapie.predict(X_test.reshape(-1, 1))
172162
else:
173163
mapie = MapieRegressor( # type: ignore

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import numpy as np
1313
from sklearn.linear_model import LinearRegression, QuantileRegressor
14-
from sklearn.model_selection import train_test_split
1514
from sklearn.pipeline import Pipeline
1615
from sklearn.preprocessing import PolynomialFeatures
1716
import matplotlib.pyplot as plt
@@ -22,6 +21,7 @@
2221
from mapie._typing import NDArray
2322

2423
F = TypeVar("F", bound=Callable[..., Any])
24+
random_state = 42
2525

2626

2727
# Functions for generating our dataset
@@ -60,7 +60,7 @@ def get_1d_data_with_normal_distrib(
6060
[3]: y_test
6161
[4]: y_mesh
6262
"""
63-
np.random.seed(42)
63+
np.random.seed(random_state)
6464
X_train = np.random.normal(mu, sigma, n_samples)
6565
X_test = np.arange(mu - 4 * sigma, mu + 4 * sigma, sigma / 20.0)
6666
y_train, y_mesh, y_test = funct(X_train), funct(X_test), funct(X_test)
@@ -114,21 +114,8 @@ def get_1d_data_with_normal_distrib(
114114
polyn_model_quant,
115115
**params
116116
)
117-
X_train, X_calib, y_train, y_calib = train_test_split(
118-
X_train,
119-
y_train,
120-
test_size=0.3,
121-
random_state=1
122-
)
123-
mapie.fit(
124-
X_train,
125-
y_train,
126-
X_calib=X_calib,
127-
y_calib=y_calib
128-
)
129-
y_pred[strategy], y_pis[strategy] = mapie.predict(
130-
X_test
131-
)
117+
mapie.fit(X_train, y_train, random_state=random_state)
118+
y_pred[strategy], y_pis[strategy] = mapie.predict(X_test)
132119
else:
133120
mapie = MapieRegressor(polyn_model, **params) # type: ignore
134121
mapie.fit(X_train, y_train)

mapie/tests/test_quantile_regression.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,10 @@ def test_calib_dataset_is_none_with_sample_weight() -> None:
429429

430430

431431
def test_calib_dataset_is_none_vs_defined() -> None:
432-
"""Test that the fit method works when X_calib or y_calib is None."""
432+
"""
433+
Test that for the same results whether you split before
434+
or in the fit method.
435+
"""
433436
mapie = MapieQuantileRegressor()
434437
mapie_defined = clone(mapie)
435438
mapie.fit(X, y, calib_size=0.5, random_state=random_state)

notebooks/regression/tutorial_regression.ipynb

Lines changed: 5 additions & 6 deletions
Large diffs are not rendered by default.

notebooks/regression/tutorial_regression.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ heteroscedastic_coverage = get_heteroscedastic_coverage(y_test, y_pis, STRATEGIE
456456
fig = plt.figure()
457457
heteroscedastic_coverage.T.plot.bar(figsize=(12, 4), alpha=0.7)
458458
plt.axhline(0.95, ls="--", color="k")
459-
plt.ylim([0.8, 1])
460459
plt.ylabel("Conditional coverage")
461460
plt.xlabel("x bins")
462461
plt.xticks(rotation=0)

0 commit comments

Comments
 (0)