Skip to content

Commit 4c1caf0

Browse files
authored
Merge pull request #184 from scikit-learn-contrib/fix_typing_cqr
Fix typing cqr
2 parents d173beb + caab653 commit 4c1caf0

19 files changed

+485
-289
lines changed

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
History
33
=======
44

5-
0.3.3 (2022-XX-XX)
5+
0.4.0 (2022-06-24)
66
------------------
77
* Relax and fix typing
88
* Add Split Conformal Quantile Regression

doc/images/quickstart_1.png

0 Bytes
Loading

doc/tutorial_regression.rst

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,7 @@ prediction intervals.
144144
for strategy, params in STRATEGIES.items():
145145
if strategy == "conformalized_quantile_regression":
146146
mapie = MapieQuantileRegressor(polyn_model_quant, **params)
147-
X_train, X_calib, y_train, y_calib = train_test_split(
148-
X_train,
149-
y_train,
150-
test_size=0.3,
151-
random_state=1
152-
)
153-
mapie.fit(X_train, y_train, X_calib, y_calib)
147+
mapie.fit(X_train, y_train, random_state=1)
154148
y_pred[strategy], y_pis[strategy] = mapie.predict(X_test)
155149
else:
156150
mapie = MapieRegressor(polyn_model, **params)
@@ -462,13 +456,7 @@ prediction intervals.
462456
for strategy, params in STRATEGIES.items():
463457
if strategy == "conformalized_quantile_regression":
464458
mapie = MapieQuantileRegressor(polyn_model_quant, **params)
465-
X_train, X_calib, y_train, y_calib = train_test_split(
466-
X_train,
467-
y_train,
468-
test_size=0.3,
469-
random_state=1
470-
)
471-
mapie.fit(X_train, y_train, X_calib, y_calib)
459+
mapie.fit(X_train, y_train, random_state=1)
472460
y_pred[strategy], y_pis[strategy] = mapie.predict(X_test)
473461
else:
474462
mapie = MapieRegressor(polyn_model, **params)
@@ -567,7 +555,7 @@ next figure.
567555
recap ={}
568556
for i in range(len(bins)-1):
569557
bin1, bin2 = bins[i], bins[i+1]
570-
name = f"{bin1} to {bin2}"
558+
name = f"[{bin1}, {bin2}]"
571559
recap[name] = []
572560
for strategy in STRATEGIES:
573561
indices = np.where((X_test>=bins[i])*(X_test<=bins[i+1]))
@@ -590,6 +578,9 @@ next figure.
590578
heteroscedastic_coverage.T.plot.bar(figsize=(12, 4), alpha=0.7)
591579
plt.axhline(0.95, ls="--", color="k")
592580
plt.ylabel("Conditional coverage")
581+
plt.xlabel("x bins")
582+
plt.xticks(rotation=0)
583+
plt.ylim(0.8, 1.0)
593584
plt.legend(loc=[1, 0])
594585
595586
@@ -790,13 +781,7 @@ strategies.
790781
for strategy, params in STRATEGIES.items():
791782
if strategy == "conformalized_quantile_regression":
792783
mapie = MapieQuantileRegressor(polyn_model_quant, **params)
793-
X_train, X_calib, y_train, y_calib = train_test_split(
794-
X_train,
795-
y_train,
796-
test_size=0.3,
797-
random_state=1
798-
)
799-
mapie.fit(X_train, y_train, X_calib, y_calib)
784+
mapie.fit(X_train, y_train, random_state=1)
800785
y_pred[strategy], y_pis[strategy] = mapie.predict(X_test)
801786
else:
802787
mapie = MapieRegressor(polyn_model, **params)
@@ -1068,7 +1053,6 @@ method and compare their prediction interval.
10681053
10691054
.. parsed-literal::
10701055
1071-
Metal device set to: Apple M1
10721056
10731057
10741058
.. code-block:: python
12.2 KB
Loading
17.1 KB
Loading
2.67 KB
Loading
-34 Bytes
Loading
829 Bytes
Loading
-797 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.reshape(-1, 1),
171-
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,

0 commit comments

Comments
 (0)