Skip to content

Commit 23b745c

Browse files
committed
Pushing the docs to dev/ for branch: main, commit b7f3fd6887c56138a21a9151105694945a5f5377
1 parent 7500bd1 commit 23b745c

File tree

1,195 files changed

+4346
-4184
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,195 files changed

+4346
-4184
lines changed
Binary file not shown.

dev/_downloads/1a55101a8e49ab5d3213dadb31332045/plot_digits_classification.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,27 @@
102102
print(f"Confusion matrix:\n{disp.confusion_matrix}")
103103

104104
plt.show()
105+
106+
###############################################################################
107+
# If the results from evaluating a classifier are stored in the form of a
108+
# :ref:`confusion matrix <confusion_matrix>` and not in terms of `y_true` and
109+
# `y_pred`, one can still build a :func:`~sklearn.metrics.classification_report`
110+
# as follows:
111+
112+
113+
# The ground truth and predicted lists
114+
y_true = []
115+
y_pred = []
116+
cm = disp.confusion_matrix
117+
118+
# For each cell in the confusion matrix, add the corresponding ground truths
119+
# and predictions to the lists
120+
for gt in range(len(cm)):
121+
for pred in range(len(cm)):
122+
y_true += [gt] * cm[gt][pred]
123+
y_pred += [pred] * cm[gt][pred]
124+
125+
print(
126+
"Classification report rebuilt from confusion matrix:\n"
127+
f"{metrics.classification_report(y_true, y_pred)}\n"
128+
)
Binary file not shown.

dev/_downloads/eb87d6211b2c0a7c2dc460a9e28b1f6a/plot_digits_classification.ipynb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@
118118
"source": [
119119
"disp = metrics.ConfusionMatrixDisplay.from_predictions(y_test, predicted)\ndisp.figure_.suptitle(\"Confusion Matrix\")\nprint(f\"Confusion matrix:\\n{disp.confusion_matrix}\")\n\nplt.show()"
120120
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"metadata": {},
125+
"source": [
126+
"If the results from evaluating a classifier are stored in the form of a\n`confusion matrix <confusion_matrix>` and not in terms of `y_true` and\n`y_pred`, one can still build a :func:`~sklearn.metrics.classification_report`\nas follows:\n\n"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {
133+
"collapsed": false
134+
},
135+
"outputs": [],
136+
"source": [
137+
"# The ground truth and predicted lists\ny_true = []\ny_pred = []\ncm = disp.confusion_matrix\n\n# For each cell in the confusion matrix, add the corresponding ground truths\n# and predictions to the lists\nfor gt in range(len(cm)):\n for pred in range(len(cm)):\n y_true += [gt] * cm[gt][pred]\n y_pred += [pred] * cm[gt][pred]\n\nprint(\n \"Classification report rebuilt from confusion matrix:\\n\"\n f\"{metrics.classification_report(y_true, y_pred)}\\n\"\n)"
138+
]
121139
}
122140
],
123141
"metadata": {

dev/_downloads/scikit-learn-docs.zip

-15.2 KB
Binary file not shown.
11 Bytes
6 Bytes
2.91 KB
1.1 KB
10 Bytes

0 commit comments

Comments
 (0)