Skip to content

Commit 7e8ba7e

Browse files
committed
Pushing the docs to dev/ for branch: main, commit f22ebd2548aa45d8da8689ccd2548a73557299fa
1 parent f145745 commit 7e8ba7e

File tree

1,260 files changed

+4694
-4654
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,260 files changed

+4694
-4654
lines changed
Binary file not shown.

dev/_downloads/149ff4a0ff65a845f675cc7a0fcb86ea/plot_image_denoising.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
print("Learning the dictionary...")
8181
t0 = time()
82-
dico = MiniBatchDictionaryLearning(n_components=100, alpha=1, n_iter=500)
82+
dico = MiniBatchDictionaryLearning(n_components=50, alpha=1, n_iter=250)
8383
V = dico.fit(data).components_
8484
dt = time() - t0
8585
print("done in %.2fs." % dt)
@@ -139,7 +139,7 @@ def show_with_diff(image, reference, title):
139139
transform_algorithms = [
140140
("Orthogonal Matching Pursuit\n1 atom", "omp", {"transform_n_nonzero_coefs": 1}),
141141
("Orthogonal Matching Pursuit\n2 atoms", "omp", {"transform_n_nonzero_coefs": 2}),
142-
("Least-angle regression\n5 atoms", "lars", {"transform_n_nonzero_coefs": 5}),
142+
("Least-angle regression\n4 atoms", "lars", {"transform_n_nonzero_coefs": 4}),
143143
("Thresholding\n alpha=0.1", "threshold", {"transform_alpha": 0.1}),
144144
]
145145

dev/_downloads/2f3ef774a6d7e52e1e6b7ccbb75d25f0/plot_gradient_boosting_quantile.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def f(x):
6262
all_models = {}
6363
common_params = dict(
6464
learning_rate=0.05,
65-
n_estimators=250,
65+
n_estimators=200,
6666
max_depth=2,
6767
min_samples_leaf=9,
6868
min_samples_split=9,
@@ -97,7 +97,7 @@ def f(x):
9797
fig = plt.figure(figsize=(10, 10))
9898
plt.plot(xx, f(xx), "g:", linewidth=3, label=r"$f(x) = x\,\sin(x)$")
9999
plt.plot(X_test, y_test, "b.", markersize=10, label="Test observations")
100-
plt.plot(xx, y_med, "r-", label="Predicted median", color="orange")
100+
plt.plot(xx, y_med, "r-", label="Predicted median")
101101
plt.plot(xx, y_pred, "r-", label="Predicted mean")
102102
plt.plot(xx, y_upper, "k-")
103103
plt.plot(xx, y_lower, "k-")
@@ -224,25 +224,24 @@ def coverage_fraction(y, y_low, y_high):
224224
# underfit and could not adapt to sinusoidal shape of the signal.
225225
#
226226
# The hyper-parameters of the model were approximately hand-tuned for the
227-
# median regressor and there is no reason than the same hyper-parameters are
227+
# median regressor and there is no reason that the same hyper-parameters are
228228
# suitable for the 5th percentile regressor.
229229
#
230230
# To confirm this hypothesis, we tune the hyper-parameters of a new regressor
231231
# of the 5th percentile by selecting the best model parameters by
232232
# cross-validation on the pinball loss with alpha=0.05:
233233

234234
# %%
235-
from sklearn.model_selection import RandomizedSearchCV
235+
from sklearn.experimental import enable_halving_search_cv # noqa
236+
from sklearn.model_selection import HalvingRandomSearchCV
236237
from sklearn.metrics import make_scorer
237238
from pprint import pprint
238239

239-
240240
param_grid = dict(
241-
learning_rate=[0.01, 0.05, 0.1],
242-
n_estimators=[100, 150, 200, 250, 300],
243-
max_depth=[2, 5, 10, 15, 20],
244-
min_samples_leaf=[1, 5, 10, 20, 30, 50],
245-
min_samples_split=[2, 5, 10, 20, 30, 50],
241+
learning_rate=[0.05, 0.1, 0.2],
242+
max_depth=[2, 5, 10],
243+
min_samples_leaf=[1, 5, 10, 20],
244+
min_samples_split=[5, 10, 20, 30, 50],
246245
)
247246
alpha = 0.05
248247
neg_mean_pinball_loss_05p_scorer = make_scorer(
@@ -251,20 +250,22 @@ def coverage_fraction(y, y_low, y_high):
251250
greater_is_better=False, # maximize the negative loss
252251
)
253252
gbr = GradientBoostingRegressor(loss="quantile", alpha=alpha, random_state=0)
254-
search_05p = RandomizedSearchCV(
253+
search_05p = HalvingRandomSearchCV(
255254
gbr,
256255
param_grid,
257-
n_iter=10, # increase this if computational budget allows
256+
resource="n_estimators",
257+
max_resources=250,
258+
min_resources=50,
258259
scoring=neg_mean_pinball_loss_05p_scorer,
259260
n_jobs=2,
260261
random_state=0,
261262
).fit(X_train, y_train)
262263
pprint(search_05p.best_params_)
263264

264265
# %%
265-
# We observe that the search procedure identifies that deeper trees are needed
266-
# to get a good fit for the 5th percentile regressor. Deeper trees are more
267-
# expressive and less likely to underfit.
266+
# We observe that the hyper-parameters that were hand-tuned for the median
267+
# regressor are in the same range as the hyper-parameters suitable for the 5th
268+
# percentile regressor.
268269
#
269270
# Let's now tune the hyper-parameters for the 95th percentile regressor. We
270271
# need to redefine the `scoring` metric used to select the best model, along
@@ -286,15 +287,14 @@ def coverage_fraction(y, y_low, y_high):
286287
pprint(search_95p.best_params_)
287288

288289
# %%
289-
# This time, shallower trees are selected and lead to a more constant piecewise
290-
# and therefore more robust estimation of the 95th percentile. This is
291-
# beneficial as it avoids overfitting the large outliers of the log-normal
292-
# additive noise.
293-
#
294-
# We can confirm this intuition by displaying the predicted 90% confidence
295-
# interval comprised by the predictions of those two tuned quantile regressors:
296-
# the prediction of the upper 95th percentile has a much coarser shape than the
297-
# prediction of the lower 5th percentile:
290+
# The result shows that the hyper-parameters for the 95th percentile regressor
291+
# identified by the search procedure are roughly in the same range as the hand-
292+
# tuned hyper-parameters for the median regressor and the hyper-parameters
293+
# identified by the search procedure for the 5th percentile regressor. However,
294+
# the hyper-parameter searches did lead to an improved 90% confidence interval
295+
# that is comprised by the predictions of those two tuned quantile regressors.
296+
# Note that the prediction of the upper 95th percentile has a much coarser shape
297+
# than the prediction of the lower 5th percentile because of the outliers:
298298
y_lower = search_05p.predict(xx)
299299
y_upper = search_95p.predict(xx)
300300

Binary file not shown.

dev/_downloads/b5ac5dfd67b0aab146fcb9faaac8480c/plot_gradient_boosting_quantile.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
},
8888
"outputs": [],
8989
"source": [
90-
"from sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.metrics import mean_pinball_loss, mean_squared_error\n\n\nall_models = {}\ncommon_params = dict(\n learning_rate=0.05,\n n_estimators=250,\n max_depth=2,\n min_samples_leaf=9,\n min_samples_split=9,\n)\nfor alpha in [0.05, 0.5, 0.95]:\n gbr = GradientBoostingRegressor(loss=\"quantile\", alpha=alpha, **common_params)\n all_models[\"q %1.2f\" % alpha] = gbr.fit(X_train, y_train)"
90+
"from sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.metrics import mean_pinball_loss, mean_squared_error\n\n\nall_models = {}\ncommon_params = dict(\n learning_rate=0.05,\n n_estimators=200,\n max_depth=2,\n min_samples_leaf=9,\n min_samples_split=9,\n)\nfor alpha in [0.05, 0.5, 0.95]:\n gbr = GradientBoostingRegressor(loss=\"quantile\", alpha=alpha, **common_params)\n all_models[\"q %1.2f\" % alpha] = gbr.fit(X_train, y_train)"
9191
]
9292
},
9393
{
@@ -141,7 +141,7 @@
141141
},
142142
"outputs": [],
143143
"source": [
144-
"import matplotlib.pyplot as plt\n\n\ny_pred = all_models[\"mse\"].predict(xx)\ny_lower = all_models[\"q 0.05\"].predict(xx)\ny_upper = all_models[\"q 0.95\"].predict(xx)\ny_med = all_models[\"q 0.50\"].predict(xx)\n\nfig = plt.figure(figsize=(10, 10))\nplt.plot(xx, f(xx), \"g:\", linewidth=3, label=r\"$f(x) = x\\,\\sin(x)$\")\nplt.plot(X_test, y_test, \"b.\", markersize=10, label=\"Test observations\")\nplt.plot(xx, y_med, \"r-\", label=\"Predicted median\", color=\"orange\")\nplt.plot(xx, y_pred, \"r-\", label=\"Predicted mean\")\nplt.plot(xx, y_upper, \"k-\")\nplt.plot(xx, y_lower, \"k-\")\nplt.fill_between(\n xx.ravel(), y_lower, y_upper, alpha=0.4, label=\"Predicted 90% interval\"\n)\nplt.xlabel(\"$x$\")\nplt.ylabel(\"$f(x)$\")\nplt.ylim(-10, 25)\nplt.legend(loc=\"upper left\")\nplt.show()"
144+
"import matplotlib.pyplot as plt\n\n\ny_pred = all_models[\"mse\"].predict(xx)\ny_lower = all_models[\"q 0.05\"].predict(xx)\ny_upper = all_models[\"q 0.95\"].predict(xx)\ny_med = all_models[\"q 0.50\"].predict(xx)\n\nfig = plt.figure(figsize=(10, 10))\nplt.plot(xx, f(xx), \"g:\", linewidth=3, label=r\"$f(x) = x\\,\\sin(x)$\")\nplt.plot(X_test, y_test, \"b.\", markersize=10, label=\"Test observations\")\nplt.plot(xx, y_med, \"r-\", label=\"Predicted median\")\nplt.plot(xx, y_pred, \"r-\", label=\"Predicted mean\")\nplt.plot(xx, y_upper, \"k-\")\nplt.plot(xx, y_lower, \"k-\")\nplt.fill_between(\n xx.ravel(), y_lower, y_upper, alpha=0.4, label=\"Predicted 90% interval\"\n)\nplt.xlabel(\"$x$\")\nplt.ylabel(\"$f(x)$\")\nplt.ylim(-10, 25)\nplt.legend(loc=\"upper left\")\nplt.show()"
145145
]
146146
},
147147
{
@@ -220,7 +220,7 @@
220220
"cell_type": "markdown",
221221
"metadata": {},
222222
"source": [
223-
"On the test set, the estimated confidence interval is slightly too narrow.\nNote, however, that we would need to wrap those metrics in a cross-validation\nloop to assess their variability under data resampling.\n\n## Tuning the hyper-parameters of the quantile regressors\n\nIn the plot above, we observed that the 5th percentile regressor seems to\nunderfit and could not adapt to sinusoidal shape of the signal.\n\nThe hyper-parameters of the model were approximately hand-tuned for the\nmedian regressor and there is no reason than the same hyper-parameters are\nsuitable for the 5th percentile regressor.\n\nTo confirm this hypothesis, we tune the hyper-parameters of a new regressor\nof the 5th percentile by selecting the best model parameters by\ncross-validation on the pinball loss with alpha=0.05:\n\n"
223+
"On the test set, the estimated confidence interval is slightly too narrow.\nNote, however, that we would need to wrap those metrics in a cross-validation\nloop to assess their variability under data resampling.\n\n## Tuning the hyper-parameters of the quantile regressors\n\nIn the plot above, we observed that the 5th percentile regressor seems to\nunderfit and could not adapt to sinusoidal shape of the signal.\n\nThe hyper-parameters of the model were approximately hand-tuned for the\nmedian regressor and there is no reason that the same hyper-parameters are\nsuitable for the 5th percentile regressor.\n\nTo confirm this hypothesis, we tune the hyper-parameters of a new regressor\nof the 5th percentile by selecting the best model parameters by\ncross-validation on the pinball loss with alpha=0.05:\n\n"
224224
]
225225
},
226226
{
@@ -231,14 +231,14 @@
231231
},
232232
"outputs": [],
233233
"source": [
234-
"from sklearn.model_selection import RandomizedSearchCV\nfrom sklearn.metrics import make_scorer\nfrom pprint import pprint\n\n\nparam_grid = dict(\n learning_rate=[0.01, 0.05, 0.1],\n n_estimators=[100, 150, 200, 250, 300],\n max_depth=[2, 5, 10, 15, 20],\n min_samples_leaf=[1, 5, 10, 20, 30, 50],\n min_samples_split=[2, 5, 10, 20, 30, 50],\n)\nalpha = 0.05\nneg_mean_pinball_loss_05p_scorer = make_scorer(\n mean_pinball_loss,\n alpha=alpha,\n greater_is_better=False, # maximize the negative loss\n)\ngbr = GradientBoostingRegressor(loss=\"quantile\", alpha=alpha, random_state=0)\nsearch_05p = RandomizedSearchCV(\n gbr,\n param_grid,\n n_iter=10, # increase this if computational budget allows\n scoring=neg_mean_pinball_loss_05p_scorer,\n n_jobs=2,\n random_state=0,\n).fit(X_train, y_train)\npprint(search_05p.best_params_)"
234+
"from sklearn.experimental import enable_halving_search_cv # noqa\nfrom sklearn.model_selection import HalvingRandomSearchCV\nfrom sklearn.metrics import make_scorer\nfrom pprint import pprint\n\nparam_grid = dict(\n learning_rate=[0.05, 0.1, 0.2],\n max_depth=[2, 5, 10],\n min_samples_leaf=[1, 5, 10, 20],\n min_samples_split=[5, 10, 20, 30, 50],\n)\nalpha = 0.05\nneg_mean_pinball_loss_05p_scorer = make_scorer(\n mean_pinball_loss,\n alpha=alpha,\n greater_is_better=False, # maximize the negative loss\n)\ngbr = GradientBoostingRegressor(loss=\"quantile\", alpha=alpha, random_state=0)\nsearch_05p = HalvingRandomSearchCV(\n gbr,\n param_grid,\n resource=\"n_estimators\",\n max_resources=250,\n min_resources=50,\n scoring=neg_mean_pinball_loss_05p_scorer,\n n_jobs=2,\n random_state=0,\n).fit(X_train, y_train)\npprint(search_05p.best_params_)"
235235
]
236236
},
237237
{
238238
"cell_type": "markdown",
239239
"metadata": {},
240240
"source": [
241-
"We observe that the search procedure identifies that deeper trees are needed\nto get a good fit for the 5th percentile regressor. Deeper trees are more\nexpressive and less likely to underfit.\n\nLet's now tune the hyper-parameters for the 95th percentile regressor. We\nneed to redefine the `scoring` metric used to select the best model, along\nwith adjusting the alpha parameter of the inner gradient boosting estimator\nitself:\n\n"
241+
"We observe that the hyper-parameters that were hand-tuned for the median\nregressor are in the same range as the hyper-parameters suitable for the 5th\npercentile regressor.\n\nLet's now tune the hyper-parameters for the 95th percentile regressor. We\nneed to redefine the `scoring` metric used to select the best model, along\nwith adjusting the alpha parameter of the inner gradient boosting estimator\nitself:\n\n"
242242
]
243243
},
244244
{
@@ -256,7 +256,7 @@
256256
"cell_type": "markdown",
257257
"metadata": {},
258258
"source": [
259-
"This time, shallower trees are selected and lead to a more constant piecewise\nand therefore more robust estimation of the 95th percentile. This is\nbeneficial as it avoids overfitting the large outliers of the log-normal\nadditive noise.\n\nWe can confirm this intuition by displaying the predicted 90% confidence\ninterval comprised by the predictions of those two tuned quantile regressors:\nthe prediction of the upper 95th percentile has a much coarser shape than the\nprediction of the lower 5th percentile:\n\n"
259+
"The result shows that the hyper-parameters for the 95th percentile regressor\nidentified by the search procedure are roughly in the same range as the hand-\ntuned hyper-parameters for the median regressor and the hyper-parameters\nidentified by the search procedure for the 5th percentile regressor. However,\nthe hyper-parameter searches did lead to an improved 90% confidence interval\nthat is comprised by the predictions of those two tuned quantile regressors.\nNote that the prediction of the upper 95th percentile has a much coarser shape\nthan the prediction of the lower 5th percentile because of the outliers:\n\n"
260260
]
261261
},
262262
{

0 commit comments

Comments
 (0)