Skip to content

Commit c6fae1a

Browse files
committed
Plot the Lorenz curves for the quantile regression models
1 parent b467781 commit c6fae1a

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

content/python_files/feature_engineering.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ def mean_width(y_true, y_quantile_low, y_quantile_high):
15311531

15321532
# %% [markdown]
15331533
#
1534-
# ## Reliability diagrams for quantile regression
1534+
# ## Reliability diagrams and Lorenz curves for quantile regression
15351535

15361536
# %%
15371537
plot_reliability_diagram(
@@ -1554,6 +1554,22 @@ def mean_width(y_true, y_quantile_low, y_quantile_high):
15541554
title="Reliability diagram for quantile 0.95 from cross-validation predictions"
15551555
)
15561556

1557+
# %%
1558+
plot_lorenz_curve(cv_predictions_hgbr_50).interactive().properties(
1559+
title="Lorenz curve for quantile 0.50 from cross-validation predictions"
1560+
)
1561+
1562+
# %%
1563+
plot_lorenz_curve(cv_predictions_hgbr_05).interactive().properties(
1564+
title="Lorenz curve for quantile 0.05 from cross-validation predictions"
1565+
)
1566+
1567+
# %%
1568+
plot_lorenz_curve(cv_predictions_hgbr_95).interactive().properties(
1569+
title="Lorenz curve for quantile 0.95 from cross-validation predictions"
1570+
)
1571+
1572+
15571573
# %% [markdown]
15581574
#
15591575
# ## Quantile regression as classification
@@ -1746,6 +1762,9 @@ def predict(self, X):
17461762
print(f"d2_pinball score: {d2_pinball_score(observed, predicted):.3f}")
17471763
print()
17481764

1765+
# %% [markdown
1766+
# Let's assess the calibration of the quantile regression model:
1767+
17491768
# %%
17501769
plot_reliability_diagram(
17511770
cv_predictions_bqr_50, kind="quantile", quantile_level=0.50
@@ -1766,3 +1785,23 @@ def predict(self, X):
17661785
).interactive().properties(
17671786
title="Reliability diagram for quantile 0.95 from cross-validation predictions"
17681787
)
1788+
1789+
# %% [markdown]
1790+
#
1791+
# We can complement this assessment with the Lorenz curves, which only assess
1792+
# the ranking power of the predictions, irrespective of their absolute values.
1793+
1794+
# %%
1795+
plot_lorenz_curve(cv_predictions_bqr_50).interactive().properties(
1796+
title="Lorenz curve for quantile 0.50 from cross-validation predictions"
1797+
)
1798+
1799+
# %%
1800+
plot_lorenz_curve(cv_predictions_bqr_05).interactive().properties(
1801+
title="Lorenz curve for quantile 0.05 from cross-validation predictions"
1802+
)
1803+
1804+
# %%
1805+
plot_lorenz_curve(cv_predictions_bqr_95).interactive().properties(
1806+
title="Lorenz curve for quantile 0.95 from cross-validation predictions"
1807+
)

0 commit comments

Comments
 (0)