Skip to content

Commit 0209bc8

Browse files
author
gmartinonQM
committed
ENH use score functions in some examples for classification
1 parent 5550686 commit 0209bc8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

examples/regression/1-quickstart/plot_timeseries_example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@
3030
Jackknife+ and CV+ methods.
3131
"""
3232
import pandas as pd
33-
from mapie.metrics import regression_coverage_score
34-
from mapie.regression import MapieRegressor
3533
from matplotlib import pylab as plt
3634
from scipy.stats import randint
3735
from sklearn.ensemble import RandomForestRegressor
3836
from sklearn.model_selection import RandomizedSearchCV, TimeSeriesSplit
3937

38+
from mapie.metrics import (
39+
regression_coverage_score,
40+
regression_mean_width_score
41+
)
42+
from mapie.regression import MapieRegressor
43+
4044
# Load input data and feature engineering
4145
demand_df = pd.read_csv(
4246
"../../data/demand_temperature.csv", parse_dates=True, index_col=0
@@ -86,7 +90,7 @@
8690
mapie.fit(X_train, y_train)
8791
y_pred, y_pis = mapie.predict(X_test, alpha=alpha)
8892
coverage = regression_coverage_score(y_test, y_pis[:, 0, 0], y_pis[:, 1, 0])
89-
width = (y_pis[:, 1, 0] - y_pis[:, 0, 0]).mean()
93+
width = regression_mean_width_score(y_pis[:, 0, 0], y_pis[:, 1, 0])
9094

9195
# Print results
9296
print(

examples/regression/3-scientific-articles/plot_barber2020_simulations.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
from sklearn.linear_model import LinearRegression
3535
from matplotlib import pyplot as plt
3636

37-
from mapie.metrics import regression_coverage_score
37+
from mapie.metrics import (
38+
regression_coverage_score,
39+
regression_mean_width_score
40+
)
3841
from mapie.regression import MapieRegressor
3942
from mapie._typing import ArrayLike
4043

@@ -116,12 +119,14 @@ def PIs_vs_dimensions(
116119
**params
117120
)
118121
mapie.fit(X_train, y_train)
119-
y_pred, y_pis = mapie.predict(X_test, alpha=alpha)
122+
_, y_pis = mapie.predict(X_test, alpha=alpha)
120123
coverage = regression_coverage_score(
121124
y_test, y_pis[:, 0, 0], y_pis[:, 1, 0]
122125
)
123126
results[strategy][dimension]["coverage"][trial] = coverage
124-
width_mean = (y_pis[:, 1, 0] - y_pis[:, 0, 0]).mean()
127+
width_mean = regression_mean_width_score(
128+
y_pis[:, 0, 0], y_pis[:, 1, 0]
129+
)
125130
results[strategy][dimension]["width_mean"][trial] = width_mean
126131
return results
127132

0 commit comments

Comments
 (0)