Skip to content

Commit a67964c

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 318a28243e8fc0866ff72003b2a462cdae491ebd
1 parent d8f830f commit a67964c

File tree

1,536 files changed

+6368
-6089
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,536 files changed

+6368
-6089
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.
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.
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/b367e30cc681ed484e0148f4ce9eccb0/plot_calibration_multiclass.ipynb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,32 @@
9494
},
9595
"outputs": [],
9696
"source": [
97-
"from sklearn.metrics import log_loss\n\nscore = log_loss(y_test, clf_probs)\ncal_score = log_loss(y_test, cal_clf_probs)\n\nprint(\"Log-loss of\")\nprint(f\" * uncalibrated classifier: {score:.3f}\")\nprint(f\" * calibrated classifier: {cal_score:.3f}\")"
97+
"from sklearn.metrics import log_loss\n\nloss = log_loss(y_test, clf_probs)\ncal_loss = log_loss(y_test, cal_clf_probs)\n\nprint(\"Log-loss of:\")\nprint(f\" - uncalibrated classifier: {loss:.3f}\")\nprint(f\" - calibrated classifier: {cal_loss:.3f}\")"
9898
]
9999
},
100100
{
101101
"cell_type": "markdown",
102102
"metadata": {},
103103
"source": [
104-
"Finally we generate a grid of possible uncalibrated probabilities over\nthe 2-simplex, compute the corresponding calibrated probabilities and\nplot arrows for each. The arrows are colored according the highest\nuncalibrated probability. This illustrates the learned calibration map:\n\n"
104+
"We can also assess calibration with the Brier score for probabilistics predictions\n(lower is better, possible range is [0, 2]):\n\n"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {
111+
"collapsed": false
112+
},
113+
"outputs": [],
114+
"source": [
115+
"from sklearn.metrics import brier_score_loss\n\nloss = brier_score_loss(y_test, clf_probs)\ncal_loss = brier_score_loss(y_test, cal_clf_probs)\n\nprint(\"Brier score of\")\nprint(f\" - uncalibrated classifier: {loss:.3f}\")\nprint(f\" - calibrated classifier: {cal_loss:.3f}\")"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {},
121+
"source": [
122+
"According to the Brier score, the calibrated classifier is not better than\nthe original model.\n\nFinally we generate a grid of possible uncalibrated probabilities over\nthe 2-simplex, compute the corresponding calibrated probabilities and\nplot arrows for each. The arrows are colored according the highest\nuncalibrated probability. This illustrates the learned calibration map:\n\n"
105123
]
106124
},
107125
{
@@ -114,6 +132,13 @@
114132
"source": [
115133
"plt.figure(figsize=(10, 10))\n# Generate grid of probability values\np1d = np.linspace(0, 1, 20)\np0, p1 = np.meshgrid(p1d, p1d)\np2 = 1 - p0 - p1\np = np.c_[p0.ravel(), p1.ravel(), p2.ravel()]\np = p[p[:, 2] >= 0]\n\n# Use the three class-wise calibrators to compute calibrated probabilities\ncalibrated_classifier = cal_clf.calibrated_classifiers_[0]\nprediction = np.vstack(\n [\n calibrator.predict(this_p)\n for calibrator, this_p in zip(calibrated_classifier.calibrators, p.T)\n ]\n).T\n\n# Re-normalize the calibrated predictions to make sure they stay inside the\n# simplex. This same renormalization step is performed internally by the\n# predict method of CalibratedClassifierCV on multiclass problems.\nprediction /= prediction.sum(axis=1)[:, None]\n\n# Plot changes in predicted probabilities induced by the calibrators\nfor i in range(prediction.shape[0]):\n plt.arrow(\n p[i, 0],\n p[i, 1],\n prediction[i, 0] - p[i, 0],\n prediction[i, 1] - p[i, 1],\n head_width=1e-2,\n color=colors[np.argmax(p[i])],\n )\n\n# Plot the boundaries of the unit simplex\nplt.plot([0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], \"k\", label=\"Simplex\")\n\nplt.grid(False)\nfor x in [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:\n plt.plot([0, x], [x, 0], \"k\", alpha=0.2)\n plt.plot([0, 0 + (1 - x) / 2], [x, x + (1 - x) / 2], \"k\", alpha=0.2)\n plt.plot([x, x + (1 - x) / 2], [0, 0 + (1 - x) / 2], \"k\", alpha=0.2)\n\nplt.title(\"Learned sigmoid calibration map\")\nplt.xlabel(\"Probability class 1\")\nplt.ylabel(\"Probability class 2\")\nplt.xlim(-0.05, 1.05)\nplt.ylim(-0.05, 1.05)\n\nplt.show()"
116134
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {},
139+
"source": [
140+
"One can observe that, on average, the calibrator is pushing highly confident\npredictions away from the boundaries of the simplex while simultaneously\nmoving uncertain predictions towards one of three modes, one for each class.\nWe can also observe that the mapping is not symmetric. Furthermore some\narrows seems to cross class assignment boundaries which is not necessarily\nwhat one would expect from a calibration map as it means that some predicted\nclasses will change after calibration.\n\nAll in all, the One-vs-Rest multiclass-calibration strategy implemented in\n`CalibratedClassifierCV` should not be trusted blindly.\n\n"
141+
]
117142
}
118143
],
119144
"metadata": {
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/f4a2350e7cc794cdb19840052e96a1e7/plot_calibration_multiclass.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,30 @@ class of an instance (red: class 1, green: class 2, blue: class 3).
212212

213213
from sklearn.metrics import log_loss
214214

215-
score = log_loss(y_test, clf_probs)
216-
cal_score = log_loss(y_test, cal_clf_probs)
215+
loss = log_loss(y_test, clf_probs)
216+
cal_loss = log_loss(y_test, cal_clf_probs)
217217

218-
print("Log-loss of")
219-
print(f" * uncalibrated classifier: {score:.3f}")
220-
print(f" * calibrated classifier: {cal_score:.3f}")
218+
print("Log-loss of:")
219+
print(f" - uncalibrated classifier: {loss:.3f}")
220+
print(f" - calibrated classifier: {cal_loss:.3f}")
221221

222222
# %%
223+
# We can also assess calibration with the Brier score for probabilistics predictions
224+
# (lower is better, possible range is [0, 2]):
225+
226+
from sklearn.metrics import brier_score_loss
227+
228+
loss = brier_score_loss(y_test, clf_probs)
229+
cal_loss = brier_score_loss(y_test, cal_clf_probs)
230+
231+
print("Brier score of")
232+
print(f" - uncalibrated classifier: {loss:.3f}")
233+
print(f" - calibrated classifier: {cal_loss:.3f}")
234+
235+
# %%
236+
# According to the Brier score, the calibrated classifier is not better than
237+
# the original model.
238+
#
223239
# Finally we generate a grid of possible uncalibrated probabilities over
224240
# the 2-simplex, compute the corresponding calibrated probabilities and
225241
# plot arrows for each. The arrows are colored according the highest
@@ -274,3 +290,15 @@ class of an instance (red: class 1, green: class 2, blue: class 3).
274290
plt.ylim(-0.05, 1.05)
275291

276292
plt.show()
293+
294+
# %%
295+
# One can observe that, on average, the calibrator is pushing highly confident
296+
# predictions away from the boundaries of the simplex while simultaneously
297+
# moving uncertain predictions towards one of three modes, one for each class.
298+
# We can also observe that the mapping is not symmetric. Furthermore some
299+
# arrows seems to cross class assignment boundaries which is not necessarily
300+
# what one would expect from a calibration map as it means that some predicted
301+
# classes will change after calibration.
302+
#
303+
# All in all, the One-vs-Rest multiclass-calibration strategy implemented in
304+
# `CalibratedClassifierCV` should not be trusted blindly.
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

-3.96 KB
Binary file not shown.
-221 Bytes
-583 Bytes
-169 Bytes

0 commit comments

Comments
 (0)