Skip to content

Commit

Permalink
docs(blog): add confusion matrix seaborn viz
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexSeek committed Nov 23, 2024
1 parent 746edcb commit fddc762
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/posts/classification-metrics-on-the-backend/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ cm = (
cm
```

We can plot the confusion matrix to visualize the results.

```{python}
import matplotlib.pyplot as plt
import seaborn as sns
data = cm.to_pyarrow().to_pydict()
plt.figure(figsize=(6, 4))
sns.heatmap(
[[data["TP"][0], data["FP"][0]], [data["FN"][0], data["TN"][0]]],
annot=True,
fmt="d",
cmap="Blues",
cbar=False,
xticklabels=["Predicted Positive", "Predicted Negative"],
yticklabels=["Actual Positive", "Actual Negative"],
)
plt.title("Confusion Matrix")
plt.show()
```

Now that we've built a confusion matrix, we're able to more easily calculate a few
common classification metrics.

Expand Down

0 comments on commit fddc762

Please sign in to comment.