Skip to content

Commit e532949

Browse files
committed
Pushing the docs to dev/ for branch: master, commit e030010c6c9a2073d4150decf1e1ff749bfdb837
1 parent 665a2dc commit e532949

File tree

1,214 files changed

+4596
-3811
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,214 files changed

+4596
-3811
lines changed

dev/_downloads/10bb40e21b74618cdeed618ff1eae595/plot_det.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n====================================\nDetection error tradeoff (DET) curve\n====================================\n\nIn this example, we compare receiver operating characteristic (ROC) and\ndetection error tradeoff (DET) curves for different classification algorithms\nfor the same classification task.\n\nDET curves are commonly plotted in normal deviate scale.\nTo achieve this we transform the error rates as returned by the\n:func:`~sklearn.metrics.detection_error_tradeoff_curve` function and the axis\nscale using :func:`scipy.stats.norm`.\n\nThe point of this example is to demonstrate two properties of DET curves,\nnamely:\n\n1. It might be easier to visually assess the overall performance of different\n classification algorithms using DET curves over ROC curves.\n Due to the linear scale used for plotting ROC curves, different classifiers\n usually only differ in the top left corner of the graph and appear similar\n for a large part of the plot. On the other hand, because DET curves\n represent straight lines in normal deviate scale. As such, they tend to be\n distinguishable as a whole and the area of interest spans a large part of\n the plot.\n2. DET curves give the user direct feedback of the detection error tradeoff to\n aid in operating point analysis.\n The user can deduct directly from the DET-curve plot at which rate\n false-negative error rate will improve when willing to accept an increase in\n false-positive error rate (or vice-versa).\n\nThe plots in this example compare ROC curves on the left side to corresponding\nDET curves on the right.\nThere is no particular reason why these classifiers have been chosen for the\nexample plot over other classifiers available in scikit-learn.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>- See :func:`sklearn.metrics.roc_curve` for further information about ROC\n curves.\n\n - See :func:`sklearn.metrics.detection_error_tradeoff_curve` for further\n information about DET curves.\n\n - This example is loosely based on\n `sphx_glr_auto_examples_classification_plot_classifier_comparison.py`\n example.</p></div>\n"
18+
"\n====================================\nDetection error tradeoff (DET) curve\n====================================\n\nIn this example, we compare receiver operating characteristic (ROC) and\ndetection error tradeoff (DET) curves for different classification algorithms\nfor the same classification task.\n\nDET curves are commonly plotted in normal deviate scale.\nTo achieve this `plot_det_curve` transforms the error rates as returned by the\n:func:`~sklearn.metrics.det_curve` and the axis scale using\n:func:`scipy.stats.norm`.\n\nThe point of this example is to demonstrate two properties of DET curves,\nnamely:\n\n1. It might be easier to visually assess the overall performance of different\n classification algorithms using DET curves over ROC curves.\n Due to the linear scale used for plotting ROC curves, different classifiers\n usually only differ in the top left corner of the graph and appear similar\n for a large part of the plot. On the other hand, because DET curves\n represent straight lines in normal deviate scale. As such, they tend to be\n distinguishable as a whole and the area of interest spans a large part of\n the plot.\n2. DET curves give the user direct feedback of the detection error tradeoff to\n aid in operating point analysis.\n The user can deduct directly from the DET-curve plot at which rate\n false-negative error rate will improve when willing to accept an increase in\n false-positive error rate (or vice-versa).\n\nThe plots in this example compare ROC curves on the left side to corresponding\nDET curves on the right.\nThere is no particular reason why these classifiers have been chosen for the\nexample plot over other classifiers available in scikit-learn.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>- See :func:`sklearn.metrics.roc_curve` for further information about ROC\n curves.\n\n - See :func:`sklearn.metrics.det_curve` for further information about\n DET curves.\n\n - This example is loosely based on\n `sphx_glr_auto_examples_classification_plot_classifier_comparison.py`\n example.</p></div>\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import matplotlib.pyplot as plt\n\nfrom sklearn.datasets import make_classification\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import detection_error_tradeoff_curve\nfrom sklearn.metrics import plot_roc_curve\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.svm import LinearSVC\n\nfrom scipy.stats import norm\n\nN_SAMPLES = 1000\n\nclassifiers = {\n \"Linear SVM\": make_pipeline(StandardScaler(), LinearSVC(C=0.025)),\n \"Random Forest\": RandomForestClassifier(\n max_depth=5, n_estimators=10, max_features=1\n ),\n}\n\nX, y = make_classification(\n n_samples=N_SAMPLES, n_features=2, n_redundant=0, n_informative=2,\n random_state=1, n_clusters_per_class=1)\n\nX_train, X_test, y_train, y_test = train_test_split(\n X, y, test_size=.4, random_state=0)\n\n# prepare plots\nfig, [ax_roc, ax_det] = plt.subplots(1, 2, figsize=(11, 5))\n\n# first prepare the ROC curve\nax_roc.set_title('Receiver Operating Characteristic (ROC) curves')\nax_roc.grid(linestyle='--')\n\n# second prepare the DET curve\nax_det.set_title('Detection Error Tradeoff (DET) curves')\nax_det.set_xlabel('False Positive Rate')\nax_det.set_ylabel('False Negative Rate')\nax_det.set_xlim(-3, 3)\nax_det.set_ylim(-3, 3)\nax_det.grid(linestyle='--')\n\n# customized ticks for DET curve plot to represent normal deviate scale\nticks = [0.001, 0.01, 0.05, 0.20, 0.5, 0.80, 0.95, 0.99, 0.999]\ntick_locs = norm.ppf(ticks)\ntick_lbls = [\n '{:.0%}'.format(s) if (100*s).is_integer() else '{:.1%}'.format(s)\n for s in ticks\n]\nplt.sca(ax_det)\nplt.xticks(tick_locs, tick_lbls)\nplt.yticks(tick_locs, tick_lbls)\n\n# iterate over classifiers\nfor name, clf in classifiers.items():\n clf.fit(X_train, y_train)\n\n if hasattr(clf, \"decision_function\"):\n y_score = clf.decision_function(X_test)\n else:\n y_score = clf.predict_proba(X_test)[:, 1]\n\n plot_roc_curve(clf, X_test, y_test, ax=ax_roc, name=name)\n det_fpr, det_fnr, _ = detection_error_tradeoff_curve(y_test, y_score)\n\n # transform errors into normal deviate scale\n ax_det.plot(norm.ppf(det_fpr), norm.ppf(det_fnr), label=name)\n\nplt.legend()\nplt.show()"
29+
"import matplotlib.pyplot as plt\n\nfrom sklearn.datasets import make_classification\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import plot_det_curve\nfrom sklearn.metrics import plot_roc_curve\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.svm import LinearSVC\n\nN_SAMPLES = 1000\n\nclassifiers = {\n \"Linear SVM\": make_pipeline(StandardScaler(), LinearSVC(C=0.025)),\n \"Random Forest\": RandomForestClassifier(\n max_depth=5, n_estimators=10, max_features=1\n ),\n}\n\nX, y = make_classification(\n n_samples=N_SAMPLES, n_features=2, n_redundant=0, n_informative=2,\n random_state=1, n_clusters_per_class=1)\n\nX_train, X_test, y_train, y_test = train_test_split(\n X, y, test_size=.4, random_state=0)\n\n# prepare plots\nfig, [ax_roc, ax_det] = plt.subplots(1, 2, figsize=(11, 5))\n\nfor name, clf in classifiers.items():\n clf.fit(X_train, y_train)\n\n plot_roc_curve(clf, X_test, y_test, ax=ax_roc, name=name)\n plot_det_curve(clf, X_test, y_test, ax=ax_det, name=name)\n\nax_roc.set_title('Receiver Operating Characteristic (ROC) curves')\nax_det.set_title('Detection Error Tradeoff (DET) curves')\n\nax_roc.grid(linestyle='--')\nax_det.grid(linestyle='--')\n\nplt.legend()\nplt.show()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/67703ae8c65716668dd87c31a24a069b/plot_det.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
for the same classification task.
99
1010
DET curves are commonly plotted in normal deviate scale.
11-
To achieve this we transform the error rates as returned by the
12-
:func:`~sklearn.metrics.detection_error_tradeoff_curve` function and the axis
13-
scale using :func:`scipy.stats.norm`.
11+
To achieve this `plot_det_curve` transforms the error rates as returned by the
12+
:func:`~sklearn.metrics.det_curve` and the axis scale using
13+
:func:`scipy.stats.norm`.
1414
1515
The point of this example is to demonstrate two properties of DET curves,
1616
namely:
@@ -39,8 +39,8 @@
3939
- See :func:`sklearn.metrics.roc_curve` for further information about ROC
4040
curves.
4141
42-
- See :func:`sklearn.metrics.detection_error_tradeoff_curve` for further
43-
information about DET curves.
42+
- See :func:`sklearn.metrics.det_curve` for further information about
43+
DET curves.
4444
4545
- This example is loosely based on
4646
:ref:`sphx_glr_auto_examples_classification_plot_classifier_comparison.py`
@@ -51,15 +51,13 @@
5151

5252
from sklearn.datasets import make_classification
5353
from sklearn.ensemble import RandomForestClassifier
54-
from sklearn.metrics import detection_error_tradeoff_curve
54+
from sklearn.metrics import plot_det_curve
5555
from sklearn.metrics import plot_roc_curve
5656
from sklearn.model_selection import train_test_split
5757
from sklearn.pipeline import make_pipeline
5858
from sklearn.preprocessing import StandardScaler
5959
from sklearn.svm import LinearSVC
6060

61-
from scipy.stats import norm
62-
6361
N_SAMPLES = 1000
6462

6563
classifiers = {
@@ -79,43 +77,17 @@
7977
# prepare plots
8078
fig, [ax_roc, ax_det] = plt.subplots(1, 2, figsize=(11, 5))
8179

82-
# first prepare the ROC curve
83-
ax_roc.set_title('Receiver Operating Characteristic (ROC) curves')
84-
ax_roc.grid(linestyle='--')
85-
86-
# second prepare the DET curve
87-
ax_det.set_title('Detection Error Tradeoff (DET) curves')
88-
ax_det.set_xlabel('False Positive Rate')
89-
ax_det.set_ylabel('False Negative Rate')
90-
ax_det.set_xlim(-3, 3)
91-
ax_det.set_ylim(-3, 3)
92-
ax_det.grid(linestyle='--')
93-
94-
# customized ticks for DET curve plot to represent normal deviate scale
95-
ticks = [0.001, 0.01, 0.05, 0.20, 0.5, 0.80, 0.95, 0.99, 0.999]
96-
tick_locs = norm.ppf(ticks)
97-
tick_lbls = [
98-
'{:.0%}'.format(s) if (100*s).is_integer() else '{:.1%}'.format(s)
99-
for s in ticks
100-
]
101-
plt.sca(ax_det)
102-
plt.xticks(tick_locs, tick_lbls)
103-
plt.yticks(tick_locs, tick_lbls)
104-
105-
# iterate over classifiers
10680
for name, clf in classifiers.items():
10781
clf.fit(X_train, y_train)
10882

109-
if hasattr(clf, "decision_function"):
110-
y_score = clf.decision_function(X_test)
111-
else:
112-
y_score = clf.predict_proba(X_test)[:, 1]
113-
11483
plot_roc_curve(clf, X_test, y_test, ax=ax_roc, name=name)
115-
det_fpr, det_fnr, _ = detection_error_tradeoff_curve(y_test, y_score)
84+
plot_det_curve(clf, X_test, y_test, ax=ax_det, name=name)
85+
86+
ax_roc.set_title('Receiver Operating Characteristic (ROC) curves')
87+
ax_det.set_title('Detection Error Tradeoff (DET) curves')
11688

117-
# transform errors into normal deviate scale
118-
ax_det.plot(norm.ppf(det_fpr), norm.ppf(det_fnr), label=name)
89+
ax_roc.grid(linestyle='--')
90+
ax_det.grid(linestyle='--')
11991

12092
plt.legend()
12193
plt.show()
Binary file not shown.

dev/_downloads/scikit-learn-docs.pdf

10.7 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
37 Bytes
37 Bytes
175 Bytes
175 Bytes

0 commit comments

Comments
 (0)