Skip to content

Commit 44770c0

Browse files
committed
Pushing the docs to dev/ for branch: main, commit bb72ec0e8e82e7665e90b523b755ae54cb6d8050
1 parent 470d824 commit 44770c0

File tree

1,277 files changed

+4581
-4523
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,277 files changed

+4581
-4523
lines changed

dev/_downloads/010337852815f8103ac6cca38a812b3c/plot_roc_crossval.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
from sklearn.metrics import RocCurveDisplay
7171
from sklearn.model_selection import StratifiedKFold
7272

73-
cv = StratifiedKFold(n_splits=6)
73+
n_splits = 6
74+
cv = StratifiedKFold(n_splits=n_splits)
7475
classifier = svm.SVC(kernel="linear", probability=True, random_state=random_state)
7576

7677
tprs = []
@@ -88,12 +89,12 @@
8889
alpha=0.3,
8990
lw=1,
9091
ax=ax,
92+
plot_chance_level=(fold == n_splits - 1),
9193
)
9294
interp_tpr = np.interp(mean_fpr, viz.fpr, viz.tpr)
9395
interp_tpr[0] = 0.0
9496
tprs.append(interp_tpr)
9597
aucs.append(viz.roc_auc)
96-
ax.plot([0, 1], [0, 1], "k--", label="chance level (AUC = 0.5)")
9798

9899
mean_tpr = np.mean(tprs, axis=0)
99100
mean_tpr[-1] = 1.0

dev/_downloads/055e8313e28f2f3b5fd508054dfe5fe0/plot_roc_crossval.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
"outputs": [],
7171
"source": [
72-
"import matplotlib.pyplot as plt\n\nfrom sklearn import svm\nfrom sklearn.metrics import auc\nfrom sklearn.metrics import RocCurveDisplay\nfrom sklearn.model_selection import StratifiedKFold\n\ncv = StratifiedKFold(n_splits=6)\nclassifier = svm.SVC(kernel=\"linear\", probability=True, random_state=random_state)\n\ntprs = []\naucs = []\nmean_fpr = np.linspace(0, 1, 100)\n\nfig, ax = plt.subplots(figsize=(6, 6))\nfor fold, (train, test) in enumerate(cv.split(X, y)):\n classifier.fit(X[train], y[train])\n viz = RocCurveDisplay.from_estimator(\n classifier,\n X[test],\n y[test],\n name=f\"ROC fold {fold}\",\n alpha=0.3,\n lw=1,\n ax=ax,\n )\n interp_tpr = np.interp(mean_fpr, viz.fpr, viz.tpr)\n interp_tpr[0] = 0.0\n tprs.append(interp_tpr)\n aucs.append(viz.roc_auc)\nax.plot([0, 1], [0, 1], \"k--\", label=\"chance level (AUC = 0.5)\")\n\nmean_tpr = np.mean(tprs, axis=0)\nmean_tpr[-1] = 1.0\nmean_auc = auc(mean_fpr, mean_tpr)\nstd_auc = np.std(aucs)\nax.plot(\n mean_fpr,\n mean_tpr,\n color=\"b\",\n label=r\"Mean ROC (AUC = %0.2f $\\pm$ %0.2f)\" % (mean_auc, std_auc),\n lw=2,\n alpha=0.8,\n)\n\nstd_tpr = np.std(tprs, axis=0)\ntprs_upper = np.minimum(mean_tpr + std_tpr, 1)\ntprs_lower = np.maximum(mean_tpr - std_tpr, 0)\nax.fill_between(\n mean_fpr,\n tprs_lower,\n tprs_upper,\n color=\"grey\",\n alpha=0.2,\n label=r\"$\\pm$ 1 std. dev.\",\n)\n\nax.set(\n xlim=[-0.05, 1.05],\n ylim=[-0.05, 1.05],\n xlabel=\"False Positive Rate\",\n ylabel=\"True Positive Rate\",\n title=f\"Mean ROC curve with variability\\n(Positive label '{target_names[1]}')\",\n)\nax.axis(\"square\")\nax.legend(loc=\"lower right\")\nplt.show()"
72+
"import matplotlib.pyplot as plt\n\nfrom sklearn import svm\nfrom sklearn.metrics import auc\nfrom sklearn.metrics import RocCurveDisplay\nfrom sklearn.model_selection import StratifiedKFold\n\nn_splits = 6\ncv = StratifiedKFold(n_splits=n_splits)\nclassifier = svm.SVC(kernel=\"linear\", probability=True, random_state=random_state)\n\ntprs = []\naucs = []\nmean_fpr = np.linspace(0, 1, 100)\n\nfig, ax = plt.subplots(figsize=(6, 6))\nfor fold, (train, test) in enumerate(cv.split(X, y)):\n classifier.fit(X[train], y[train])\n viz = RocCurveDisplay.from_estimator(\n classifier,\n X[test],\n y[test],\n name=f\"ROC fold {fold}\",\n alpha=0.3,\n lw=1,\n ax=ax,\n plot_chance_level=(fold == n_splits - 1),\n )\n interp_tpr = np.interp(mean_fpr, viz.fpr, viz.tpr)\n interp_tpr[0] = 0.0\n tprs.append(interp_tpr)\n aucs.append(viz.roc_auc)\n\nmean_tpr = np.mean(tprs, axis=0)\nmean_tpr[-1] = 1.0\nmean_auc = auc(mean_fpr, mean_tpr)\nstd_auc = np.std(aucs)\nax.plot(\n mean_fpr,\n mean_tpr,\n color=\"b\",\n label=r\"Mean ROC (AUC = %0.2f $\\pm$ %0.2f)\" % (mean_auc, std_auc),\n lw=2,\n alpha=0.8,\n)\n\nstd_tpr = np.std(tprs, axis=0)\ntprs_upper = np.minimum(mean_tpr + std_tpr, 1)\ntprs_lower = np.maximum(mean_tpr - std_tpr, 0)\nax.fill_between(\n mean_fpr,\n tprs_lower,\n tprs_upper,\n color=\"grey\",\n alpha=0.2,\n label=r\"$\\pm$ 1 std. dev.\",\n)\n\nax.set(\n xlim=[-0.05, 1.05],\n ylim=[-0.05, 1.05],\n xlabel=\"False Positive Rate\",\n ylabel=\"True Positive Rate\",\n title=f\"Mean ROC curve with variability\\n(Positive label '{target_names[1]}')\",\n)\nax.axis(\"square\")\nax.legend(loc=\"lower right\")\nplt.show()"
7373
]
7474
}
7575
],
Binary file not shown.

dev/_downloads/40f4aad91af595a370d7582e3a23bed7/plot_roc.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
},
117117
"outputs": [],
118118
"source": [
119-
"import matplotlib.pyplot as plt\nfrom sklearn.metrics import RocCurveDisplay\n\nRocCurveDisplay.from_predictions(\n y_onehot_test[:, class_id],\n y_score[:, class_id],\n name=f\"{class_of_interest} vs the rest\",\n color=\"darkorange\",\n)\nplt.plot([0, 1], [0, 1], \"k--\", label=\"chance level (AUC = 0.5)\")\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"One-vs-Rest ROC curves:\\nVirginica vs (Setosa & Versicolor)\")\nplt.legend()\nplt.show()"
119+
"import matplotlib.pyplot as plt\nfrom sklearn.metrics import RocCurveDisplay\n\nRocCurveDisplay.from_predictions(\n y_onehot_test[:, class_id],\n y_score[:, class_id],\n name=f\"{class_of_interest} vs the rest\",\n color=\"darkorange\",\n plot_chance_level=True,\n)\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"One-vs-Rest ROC curves:\\nVirginica vs (Setosa & Versicolor)\")\nplt.legend()\nplt.show()"
120120
]
121121
},
122122
{
@@ -152,7 +152,7 @@
152152
},
153153
"outputs": [],
154154
"source": [
155-
"RocCurveDisplay.from_predictions(\n y_onehot_test.ravel(),\n y_score.ravel(),\n name=\"micro-average OvR\",\n color=\"darkorange\",\n)\nplt.plot([0, 1], [0, 1], \"k--\", label=\"chance level (AUC = 0.5)\")\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Micro-averaged One-vs-Rest\\nReceiver Operating Characteristic\")\nplt.legend()\nplt.show()"
155+
"RocCurveDisplay.from_predictions(\n y_onehot_test.ravel(),\n y_score.ravel(),\n name=\"micro-average OvR\",\n color=\"darkorange\",\n plot_chance_level=True,\n)\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Micro-averaged One-vs-Rest\\nReceiver Operating Characteristic\")\nplt.legend()\nplt.show()"
156156
]
157157
},
158158
{
@@ -242,7 +242,7 @@
242242
},
243243
"outputs": [],
244244
"source": [
245-
"from itertools import cycle\n\nfig, ax = plt.subplots(figsize=(6, 6))\n\nplt.plot(\n fpr[\"micro\"],\n tpr[\"micro\"],\n label=f\"micro-average ROC curve (AUC = {roc_auc['micro']:.2f})\",\n color=\"deeppink\",\n linestyle=\":\",\n linewidth=4,\n)\n\nplt.plot(\n fpr[\"macro\"],\n tpr[\"macro\"],\n label=f\"macro-average ROC curve (AUC = {roc_auc['macro']:.2f})\",\n color=\"navy\",\n linestyle=\":\",\n linewidth=4,\n)\n\ncolors = cycle([\"aqua\", \"darkorange\", \"cornflowerblue\"])\nfor class_id, color in zip(range(n_classes), colors):\n RocCurveDisplay.from_predictions(\n y_onehot_test[:, class_id],\n y_score[:, class_id],\n name=f\"ROC curve for {target_names[class_id]}\",\n color=color,\n ax=ax,\n )\n\nplt.plot([0, 1], [0, 1], \"k--\", label=\"ROC curve for chance level (AUC = 0.5)\")\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Extension of Receiver Operating Characteristic\\nto One-vs-Rest multiclass\")\nplt.legend()\nplt.show()"
245+
"from itertools import cycle\n\nfig, ax = plt.subplots(figsize=(6, 6))\n\nplt.plot(\n fpr[\"micro\"],\n tpr[\"micro\"],\n label=f\"micro-average ROC curve (AUC = {roc_auc['micro']:.2f})\",\n color=\"deeppink\",\n linestyle=\":\",\n linewidth=4,\n)\n\nplt.plot(\n fpr[\"macro\"],\n tpr[\"macro\"],\n label=f\"macro-average ROC curve (AUC = {roc_auc['macro']:.2f})\",\n color=\"navy\",\n linestyle=\":\",\n linewidth=4,\n)\n\ncolors = cycle([\"aqua\", \"darkorange\", \"cornflowerblue\"])\nfor class_id, color in zip(range(n_classes), colors):\n RocCurveDisplay.from_predictions(\n y_onehot_test[:, class_id],\n y_score[:, class_id],\n name=f\"ROC curve for {target_names[class_id]}\",\n color=color,\n ax=ax,\n plot_chance_level=(class_id == 2),\n )\n\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Extension of Receiver Operating Characteristic\\nto One-vs-Rest multiclass\")\nplt.legend()\nplt.show()"
246246
]
247247
},
248248
{
@@ -271,7 +271,7 @@
271271
},
272272
"outputs": [],
273273
"source": [
274-
"pair_scores = []\nmean_tpr = dict()\n\nfor ix, (label_a, label_b) in enumerate(pair_list):\n\n a_mask = y_test == label_a\n b_mask = y_test == label_b\n ab_mask = np.logical_or(a_mask, b_mask)\n\n a_true = a_mask[ab_mask]\n b_true = b_mask[ab_mask]\n\n idx_a = np.flatnonzero(label_binarizer.classes_ == label_a)[0]\n idx_b = np.flatnonzero(label_binarizer.classes_ == label_b)[0]\n\n fpr_a, tpr_a, _ = roc_curve(a_true, y_score[ab_mask, idx_a])\n fpr_b, tpr_b, _ = roc_curve(b_true, y_score[ab_mask, idx_b])\n\n mean_tpr[ix] = np.zeros_like(fpr_grid)\n mean_tpr[ix] += np.interp(fpr_grid, fpr_a, tpr_a)\n mean_tpr[ix] += np.interp(fpr_grid, fpr_b, tpr_b)\n mean_tpr[ix] /= 2\n mean_score = auc(fpr_grid, mean_tpr[ix])\n pair_scores.append(mean_score)\n\n fig, ax = plt.subplots(figsize=(6, 6))\n plt.plot(\n fpr_grid,\n mean_tpr[ix],\n label=f\"Mean {label_a} vs {label_b} (AUC = {mean_score :.2f})\",\n linestyle=\":\",\n linewidth=4,\n )\n RocCurveDisplay.from_predictions(\n a_true,\n y_score[ab_mask, idx_a],\n ax=ax,\n name=f\"{label_a} as positive class\",\n )\n RocCurveDisplay.from_predictions(\n b_true,\n y_score[ab_mask, idx_b],\n ax=ax,\n name=f\"{label_b} as positive class\",\n )\n plt.plot([0, 1], [0, 1], \"k--\", label=\"chance level (AUC = 0.5)\")\n plt.axis(\"square\")\n plt.xlabel(\"False Positive Rate\")\n plt.ylabel(\"True Positive Rate\")\n plt.title(f\"{target_names[idx_a]} vs {label_b} ROC curves\")\n plt.legend()\n plt.show()\n\nprint(f\"Macro-averaged One-vs-One ROC AUC score:\\n{np.average(pair_scores):.2f}\")"
274+
"pair_scores = []\nmean_tpr = dict()\n\nfor ix, (label_a, label_b) in enumerate(pair_list):\n\n a_mask = y_test == label_a\n b_mask = y_test == label_b\n ab_mask = np.logical_or(a_mask, b_mask)\n\n a_true = a_mask[ab_mask]\n b_true = b_mask[ab_mask]\n\n idx_a = np.flatnonzero(label_binarizer.classes_ == label_a)[0]\n idx_b = np.flatnonzero(label_binarizer.classes_ == label_b)[0]\n\n fpr_a, tpr_a, _ = roc_curve(a_true, y_score[ab_mask, idx_a])\n fpr_b, tpr_b, _ = roc_curve(b_true, y_score[ab_mask, idx_b])\n\n mean_tpr[ix] = np.zeros_like(fpr_grid)\n mean_tpr[ix] += np.interp(fpr_grid, fpr_a, tpr_a)\n mean_tpr[ix] += np.interp(fpr_grid, fpr_b, tpr_b)\n mean_tpr[ix] /= 2\n mean_score = auc(fpr_grid, mean_tpr[ix])\n pair_scores.append(mean_score)\n\n fig, ax = plt.subplots(figsize=(6, 6))\n plt.plot(\n fpr_grid,\n mean_tpr[ix],\n label=f\"Mean {label_a} vs {label_b} (AUC = {mean_score :.2f})\",\n linestyle=\":\",\n linewidth=4,\n )\n RocCurveDisplay.from_predictions(\n a_true,\n y_score[ab_mask, idx_a],\n ax=ax,\n name=f\"{label_a} as positive class\",\n )\n RocCurveDisplay.from_predictions(\n b_true,\n y_score[ab_mask, idx_b],\n ax=ax,\n name=f\"{label_b} as positive class\",\n plot_chance_level=True,\n )\n plt.axis(\"square\")\n plt.xlabel(\"False Positive Rate\")\n plt.ylabel(\"True Positive Rate\")\n plt.title(f\"{target_names[idx_a]} vs {label_b} ROC curves\")\n plt.legend()\n plt.show()\n\nprint(f\"Macro-averaged One-vs-One ROC AUC score:\\n{np.average(pair_scores):.2f}\")"
275275
]
276276
},
277277
{
@@ -307,7 +307,7 @@
307307
},
308308
"outputs": [],
309309
"source": [
310-
"ovo_tpr = np.zeros_like(fpr_grid)\n\nfig, ax = plt.subplots(figsize=(6, 6))\nfor ix, (label_a, label_b) in enumerate(pair_list):\n ovo_tpr += mean_tpr[ix]\n plt.plot(\n fpr_grid,\n mean_tpr[ix],\n label=f\"Mean {label_a} vs {label_b} (AUC = {pair_scores[ix]:.2f})\",\n )\n\novo_tpr /= sum(1 for pair in enumerate(pair_list))\n\nplt.plot(\n fpr_grid,\n ovo_tpr,\n label=f\"One-vs-One macro-average (AUC = {macro_roc_auc_ovo:.2f})\",\n linestyle=\":\",\n linewidth=4,\n)\nplt.plot([0, 1], [0, 1], \"k--\", label=\"chance level (AUC = 0.5)\")\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Extension of Receiver Operating Characteristic\\nto One-vs-One multiclass\")\nplt.legend()\nplt.show()"
310+
"ovo_tpr = np.zeros_like(fpr_grid)\n\nfig, ax = plt.subplots(figsize=(6, 6))\nfor ix, (label_a, label_b) in enumerate(pair_list):\n ovo_tpr += mean_tpr[ix]\n plt.plot(\n fpr_grid,\n mean_tpr[ix],\n label=f\"Mean {label_a} vs {label_b} (AUC = {pair_scores[ix]:.2f})\",\n )\n\novo_tpr /= sum(1 for pair in enumerate(pair_list))\n\nplt.plot(\n fpr_grid,\n ovo_tpr,\n label=f\"One-vs-One macro-average (AUC = {macro_roc_auc_ovo:.2f})\",\n linestyle=\":\",\n linewidth=4,\n)\nplt.plot([0, 1], [0, 1], \"k--\", label=\"Chance level (AUC = 0.5)\")\nplt.axis(\"square\")\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"Extension of Receiver Operating Characteristic\\nto One-vs-One multiclass\")\nplt.legend()\nplt.show()"
311311
]
312312
},
313313
{
Binary file not shown.

dev/_downloads/80fef09514fd851560e999a5b7daa303/plot_roc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
y_score[:, class_id],
126126
name=f"{class_of_interest} vs the rest",
127127
color="darkorange",
128+
plot_chance_level=True,
128129
)
129-
plt.plot([0, 1], [0, 1], "k--", label="chance level (AUC = 0.5)")
130130
plt.axis("square")
131131
plt.xlabel("False Positive Rate")
132132
plt.ylabel("True Positive Rate")
@@ -161,8 +161,8 @@
161161
y_score.ravel(),
162162
name="micro-average OvR",
163163
color="darkorange",
164+
plot_chance_level=True,
164165
)
165-
plt.plot([0, 1], [0, 1], "k--", label="chance level (AUC = 0.5)")
166166
plt.axis("square")
167167
plt.xlabel("False Positive Rate")
168168
plt.ylabel("True Positive Rate")
@@ -281,9 +281,9 @@
281281
name=f"ROC curve for {target_names[class_id]}",
282282
color=color,
283283
ax=ax,
284+
plot_chance_level=(class_id == 2),
284285
)
285286

286-
plt.plot([0, 1], [0, 1], "k--", label="ROC curve for chance level (AUC = 0.5)")
287287
plt.axis("square")
288288
plt.xlabel("False Positive Rate")
289289
plt.ylabel("True Positive Rate")
@@ -364,8 +364,8 @@
364364
y_score[ab_mask, idx_b],
365365
ax=ax,
366366
name=f"{label_b} as positive class",
367+
plot_chance_level=True,
367368
)
368-
plt.plot([0, 1], [0, 1], "k--", label="chance level (AUC = 0.5)")
369369
plt.axis("square")
370370
plt.xlabel("False Positive Rate")
371371
plt.ylabel("True Positive Rate")
@@ -413,7 +413,7 @@
413413
linestyle=":",
414414
linewidth=4,
415415
)
416-
plt.plot([0, 1], [0, 1], "k--", label="chance level (AUC = 0.5)")
416+
plt.plot([0, 1], [0, 1], "k--", label="Chance level (AUC = 0.5)")
417417
plt.axis("square")
418418
plt.xlabel("False Positive Rate")
419419
plt.ylabel("True Positive Rate")

dev/_downloads/b7e32fe54d613dce0d3c376377af061d/plot_outlier_detection_bench.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ def compute_prediction(X, model_name):
172172
pos_label = 0 # mean 0 belongs to positive class
173173
rows = math.ceil(len(datasets_name) / cols)
174174

175-
fig, axs = plt.subplots(rows, cols, figsize=(10, rows * 3))
175+
fig, axs = plt.subplots(rows, cols, figsize=(10, rows * 3), sharex=True, sharey=True)
176176

177177
for i, dataset_name in enumerate(datasets_name):
178178
(X, y) = preprocess_dataset(dataset_name=dataset_name)
179179

180-
for model_name in models_name:
180+
for model_idx, model_name in enumerate(models_name):
181181
y_pred = compute_prediction(X, model_name=model_name)
182182
display = RocCurveDisplay.from_predictions(
183183
y,
@@ -186,10 +186,12 @@ def compute_prediction(X, model_name):
186186
name=model_name,
187187
linewidth=linewidth,
188188
ax=axs[i // cols, i % cols],
189+
plot_chance_level=(model_idx == len(models_name) - 1),
190+
chance_level_kw={
191+
"linewidth": linewidth,
192+
"linestyle": ":",
193+
},
189194
)
190-
axs[i // cols, i % cols].plot([0, 1], [0, 1], linewidth=linewidth, linestyle=":")
191195
axs[i // cols, i % cols].set_title(dataset_name)
192-
axs[i // cols, i % cols].set_xlabel("False Positive Rate")
193-
axs[i // cols, i % cols].set_ylabel("True Positive Rate")
194196
plt.tight_layout(pad=2.0) # spacing between subplots
195197
plt.show()

dev/_downloads/eacb6a63c887dafcff02b3cee64854ef/plot_outlier_detection_bench.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
},
8181
"outputs": [],
8282
"source": [
83-
"import math\nimport matplotlib.pyplot as plt\nfrom sklearn.metrics import RocCurveDisplay\n\ndatasets_name = [\n \"http\",\n \"smtp\",\n \"SA\",\n \"SF\",\n \"forestcover\",\n \"glass\",\n \"wdbc\",\n \"cardiotocography\",\n]\n\nmodels_name = [\n \"LOF\",\n \"IForest\",\n]\n\n# plotting parameters\ncols = 2\nlinewidth = 1\npos_label = 0 # mean 0 belongs to positive class\nrows = math.ceil(len(datasets_name) / cols)\n\nfig, axs = plt.subplots(rows, cols, figsize=(10, rows * 3))\n\nfor i, dataset_name in enumerate(datasets_name):\n (X, y) = preprocess_dataset(dataset_name=dataset_name)\n\n for model_name in models_name:\n y_pred = compute_prediction(X, model_name=model_name)\n display = RocCurveDisplay.from_predictions(\n y,\n y_pred,\n pos_label=pos_label,\n name=model_name,\n linewidth=linewidth,\n ax=axs[i // cols, i % cols],\n )\n axs[i // cols, i % cols].plot([0, 1], [0, 1], linewidth=linewidth, linestyle=\":\")\n axs[i // cols, i % cols].set_title(dataset_name)\n axs[i // cols, i % cols].set_xlabel(\"False Positive Rate\")\n axs[i // cols, i % cols].set_ylabel(\"True Positive Rate\")\nplt.tight_layout(pad=2.0) # spacing between subplots\nplt.show()"
83+
"import math\nimport matplotlib.pyplot as plt\nfrom sklearn.metrics import RocCurveDisplay\n\ndatasets_name = [\n \"http\",\n \"smtp\",\n \"SA\",\n \"SF\",\n \"forestcover\",\n \"glass\",\n \"wdbc\",\n \"cardiotocography\",\n]\n\nmodels_name = [\n \"LOF\",\n \"IForest\",\n]\n\n# plotting parameters\ncols = 2\nlinewidth = 1\npos_label = 0 # mean 0 belongs to positive class\nrows = math.ceil(len(datasets_name) / cols)\n\nfig, axs = plt.subplots(rows, cols, figsize=(10, rows * 3), sharex=True, sharey=True)\n\nfor i, dataset_name in enumerate(datasets_name):\n (X, y) = preprocess_dataset(dataset_name=dataset_name)\n\n for model_idx, model_name in enumerate(models_name):\n y_pred = compute_prediction(X, model_name=model_name)\n display = RocCurveDisplay.from_predictions(\n y,\n y_pred,\n pos_label=pos_label,\n name=model_name,\n linewidth=linewidth,\n ax=axs[i // cols, i % cols],\n plot_chance_level=(model_idx == len(models_name) - 1),\n chance_level_kw={\n \"linewidth\": linewidth,\n \"linestyle\": \":\",\n },\n )\n axs[i // cols, i % cols].set_title(dataset_name)\nplt.tight_layout(pad=2.0) # spacing between subplots\nplt.show()"
8484
]
8585
}
8686
],

dev/_downloads/scikit-learn-docs.zip

1.86 KB
Binary file not shown.
55 Bytes

0 commit comments

Comments
 (0)