Skip to content

Commit d349b78

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 89cf3d24e8ff892e14d611fdabc852928f46e27b
1 parent bbbd11d commit d349b78

File tree

1,528 files changed

+6110
-6107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,528 files changed

+6110
-6107
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/10754505339af88c10b8a48127535a4a/plot_quantile_regression.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"cell_type": "markdown",
142142
"metadata": {},
143143
"source": [
144-
"Due to the asymmetry of the distribution of the noise, we observe that the\ntrue mean and estimated conditional median are different. We also observe\nthat each quantile model has different parameters to better fit the desired\nquantile. Note that ideally, all quantiles would be parallel in this case,\nwhich would become more visible with more data points or less extreme\nquantiles, e.g. 10% and 90%.\n\n## Comparing `QuantileRegressor` and `LinearRegression`\n\nIn this section, we will linger on the difference regarding the error that\n:class:`~sklearn.linear_model.QuantileRegressor` and\n:class:`~sklearn.linear_model.LinearRegression` are minimizing.\n\nIndeed, :class:`~sklearn.linear_model.LinearRegression` is a least squares\napproach minimizing the mean squared error (MSE) between the training and\npredicted targets. In contrast,\n:class:`~sklearn.linear_model.QuantileRegressor` with `quantile=0.5`\nminimizes the mean absolute error (MAE) instead.\n\nLet's first compute the training errors of such models in terms of mean\nsquared error and mean absolute error. We will use the asymmetric Pareto\ndistributed target to make it more interesting as mean and median are not\nequal.\n\n"
144+
"Due to the asymmetry of the distribution of the noise, we observe that the\ntrue mean and estimated conditional median are different. We also observe\nthat each quantile model has different parameters to better fit the desired\nquantile. Note that ideally, all quantiles would be parallel in this case,\nwhich would become more visible with more data points or less extreme\nquantiles, e.g. 10% and 90%.\n\n## Comparing `QuantileRegressor` and `LinearRegression`\n\nIn this section, we will linger on the difference regarding the loss functions that\n:class:`~sklearn.linear_model.QuantileRegressor` and\n:class:`~sklearn.linear_model.LinearRegression` are minimizing.\n\nIndeed, :class:`~sklearn.linear_model.LinearRegression` is a least squares\napproach minimizing the mean squared error (MSE) between the training and\npredicted targets. In contrast,\n:class:`~sklearn.linear_model.QuantileRegressor` with `quantile=0.5`\nminimizes the mean absolute error (MAE) instead.\n\nWhy does it matter? The loss functions specify what exactly the model is aiming\nto predict, see\n`user guide on the choice of scoring function<which_scoring_function>`.\nIn short, a model minimizing MSE predicts the mean (expectation) and a model\nminimizing MAE predicts the median.\n\nLet's compute the training errors of such models in terms of mean\nsquared error and mean absolute error. We will use the asymmetric Pareto\ndistributed target to make it more interesting as mean and median are not\nequal.\n\n"
145145
]
146146
},
147147
{
@@ -152,7 +152,7 @@
152152
},
153153
"outputs": [],
154154
"source": [
155-
"from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error\n\nlinear_regression = LinearRegression()\nquantile_regression = QuantileRegressor(quantile=0.5, alpha=0)\n\ny_pred_lr = linear_regression.fit(X, y_pareto).predict(X)\ny_pred_qr = quantile_regression.fit(X, y_pareto).predict(X)\n\nprint(\n f\"\"\"Training error (in-sample performance)\n {linear_regression.__class__.__name__}:\n MAE = {mean_absolute_error(y_pareto, y_pred_lr):.3f}\n MSE = {mean_squared_error(y_pareto, y_pred_lr):.3f}\n {quantile_regression.__class__.__name__}:\n MAE = {mean_absolute_error(y_pareto, y_pred_qr):.3f}\n MSE = {mean_squared_error(y_pareto, y_pred_qr):.3f}\n \"\"\"\n)"
155+
"from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error\n\nlinear_regression = LinearRegression()\nquantile_regression = QuantileRegressor(quantile=0.5, alpha=0)\n\ny_pred_lr = linear_regression.fit(X, y_pareto).predict(X)\ny_pred_qr = quantile_regression.fit(X, y_pareto).predict(X)\n\nprint(\n \"Training error (in-sample performance)\\n\"\n f\"{'model':<20} MAE MSE\\n\"\n f\"{linear_regression.__class__.__name__:<20} \"\n f\"{mean_absolute_error(y_pareto, y_pred_lr):5.3f} \"\n f\"{mean_squared_error(y_pareto, y_pred_lr):5.3f}\\n\"\n f\"{quantile_regression.__class__.__name__:<20} \"\n f\"{mean_absolute_error(y_pareto, y_pred_qr):5.3f} \"\n f\"{mean_squared_error(y_pareto, y_pred_qr):5.3f}\"\n)"
156156
]
157157
},
158158
{
@@ -170,7 +170,7 @@
170170
},
171171
"outputs": [],
172172
"source": [
173-
"from sklearn.model_selection import cross_validate\n\ncv_results_lr = cross_validate(\n linear_regression,\n X,\n y_pareto,\n cv=3,\n scoring=[\"neg_mean_absolute_error\", \"neg_mean_squared_error\"],\n)\ncv_results_qr = cross_validate(\n quantile_regression,\n X,\n y_pareto,\n cv=3,\n scoring=[\"neg_mean_absolute_error\", \"neg_mean_squared_error\"],\n)\nprint(\n f\"\"\"Test error (cross-validated performance)\n {linear_regression.__class__.__name__}:\n MAE = {-cv_results_lr[\"test_neg_mean_absolute_error\"].mean():.3f}\n MSE = {-cv_results_lr[\"test_neg_mean_squared_error\"].mean():.3f}\n {quantile_regression.__class__.__name__}:\n MAE = {-cv_results_qr[\"test_neg_mean_absolute_error\"].mean():.3f}\n MSE = {-cv_results_qr[\"test_neg_mean_squared_error\"].mean():.3f}\n \"\"\"\n)"
173+
"from sklearn.model_selection import cross_validate\n\ncv_results_lr = cross_validate(\n linear_regression,\n X,\n y_pareto,\n cv=3,\n scoring=[\"neg_mean_absolute_error\", \"neg_mean_squared_error\"],\n)\ncv_results_qr = cross_validate(\n quantile_regression,\n X,\n y_pareto,\n cv=3,\n scoring=[\"neg_mean_absolute_error\", \"neg_mean_squared_error\"],\n)\nprint(\n \"Test error (cross-validated performance)\\n\"\n f\"{'model':<20} MAE MSE\\n\"\n f\"{linear_regression.__class__.__name__:<20} \"\n f\"{-cv_results_lr['test_neg_mean_absolute_error'].mean():5.3f} \"\n f\"{-cv_results_lr['test_neg_mean_squared_error'].mean():5.3f}\\n\"\n f\"{quantile_regression.__class__.__name__:<20} \"\n f\"{-cv_results_qr['test_neg_mean_absolute_error'].mean():5.3f} \"\n f\"{-cv_results_qr['test_neg_mean_squared_error'].mean():5.3f}\"\n)"
174174
]
175175
},
176176
{
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/8a712694e4d011e8f35bfcb1b1b5fc82/plot_quantile_regression.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
# Comparing `QuantileRegressor` and `LinearRegression`
232232
# ----------------------------------------------------
233233
#
234-
# In this section, we will linger on the difference regarding the error that
234+
# In this section, we will linger on the difference regarding the loss functions that
235235
# :class:`~sklearn.linear_model.QuantileRegressor` and
236236
# :class:`~sklearn.linear_model.LinearRegression` are minimizing.
237237
#
@@ -241,7 +241,13 @@
241241
# :class:`~sklearn.linear_model.QuantileRegressor` with `quantile=0.5`
242242
# minimizes the mean absolute error (MAE) instead.
243243
#
244-
# Let's first compute the training errors of such models in terms of mean
244+
# Why does it matter? The loss functions specify what exactly the model is aiming
245+
# to predict, see
246+
# :ref:`user guide on the choice of scoring function<which_scoring_function>`.
247+
# In short, a model minimizing MSE predicts the mean (expectation) and a model
248+
# minimizing MAE predicts the median.
249+
#
250+
# Let's compute the training errors of such models in terms of mean
245251
# squared error and mean absolute error. We will use the asymmetric Pareto
246252
# distributed target to make it more interesting as mean and median are not
247253
# equal.
@@ -255,14 +261,14 @@
255261
y_pred_qr = quantile_regression.fit(X, y_pareto).predict(X)
256262

257263
print(
258-
f"""Training error (in-sample performance)
259-
{linear_regression.__class__.__name__}:
260-
MAE = {mean_absolute_error(y_pareto, y_pred_lr):.3f}
261-
MSE = {mean_squared_error(y_pareto, y_pred_lr):.3f}
262-
{quantile_regression.__class__.__name__}:
263-
MAE = {mean_absolute_error(y_pareto, y_pred_qr):.3f}
264-
MSE = {mean_squared_error(y_pareto, y_pred_qr):.3f}
265-
"""
264+
"Training error (in-sample performance)\n"
265+
f"{'model':<20} MAE MSE\n"
266+
f"{linear_regression.__class__.__name__:<20} "
267+
f"{mean_absolute_error(y_pareto, y_pred_lr):5.3f} "
268+
f"{mean_squared_error(y_pareto, y_pred_lr):5.3f}\n"
269+
f"{quantile_regression.__class__.__name__:<20} "
270+
f"{mean_absolute_error(y_pareto, y_pred_qr):5.3f} "
271+
f"{mean_squared_error(y_pareto, y_pred_qr):5.3f}"
266272
)
267273

268274
# %%
@@ -294,14 +300,14 @@
294300
scoring=["neg_mean_absolute_error", "neg_mean_squared_error"],
295301
)
296302
print(
297-
f"""Test error (cross-validated performance)
298-
{linear_regression.__class__.__name__}:
299-
MAE = {-cv_results_lr["test_neg_mean_absolute_error"].mean():.3f}
300-
MSE = {-cv_results_lr["test_neg_mean_squared_error"].mean():.3f}
301-
{quantile_regression.__class__.__name__}:
302-
MAE = {-cv_results_qr["test_neg_mean_absolute_error"].mean():.3f}
303-
MSE = {-cv_results_qr["test_neg_mean_squared_error"].mean():.3f}
304-
"""
303+
"Test error (cross-validated performance)\n"
304+
f"{'model':<20} MAE MSE\n"
305+
f"{linear_regression.__class__.__name__:<20} "
306+
f"{-cv_results_lr['test_neg_mean_absolute_error'].mean():5.3f} "
307+
f"{-cv_results_lr['test_neg_mean_squared_error'].mean():5.3f}\n"
308+
f"{quantile_regression.__class__.__name__:<20} "
309+
f"{-cv_results_qr['test_neg_mean_absolute_error'].mean():5.3f} "
310+
f"{-cv_results_qr['test_neg_mean_squared_error'].mean():5.3f}"
305311
)
306312

307313
# %%
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/scikit-learn-docs.zip

10.2 KB
Binary file not shown.
-264 Bytes
-131 Bytes
-66 Bytes

0 commit comments

Comments
 (0)