# How to print classification report and confussion matrix?

**URL:** <https://community.wandb.ai/t/how-to-print-classification-report-and-confussion-matrix/6469>\
**Category:** W&B Help\
**Created:** [April 19, 2024, 7:24pm UTC](https://community.wandb.ai/t/how-to-print-classification-report-and-confussion-matrix/6469 "2024-04-19T19:24:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arslan-erdo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/arslan-erdo/32/1725_2.png) [@arslan-erdo](https://community.wandb.ai/u/arslan-erdo)\
**Post date:** [April 19, 2024, 7:24pm UTC](https://community.wandb.ai/t/how-to-print-classification-report-and-confussion-matrix/6469/1 "2024-04-19T19:24:54Z")

</div>

Hi,  
I am trying to implement confuson matrix and classification report after the test phase.  
However, both metrices is not appeared in the panel.  
In the charts section in my pannel, it says  
`Selected runs are not logging media for the key **classification_report** , but instead are logging values of type **string**.`

Any recommendation to print them ?

---

<div class="post-metadata">

**Author:** ![fmamberti-wandb](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fmamberti-wandb](https://community.wandb.ai/u/fmamberti-wandb)\
**Post date:** [April 25, 2024, 12:08pm UTC](https://community.wandb.ai/t/how-to-print-classification-report-and-confussion-matrix/6469/2 "2024-04-25T12:08:40Z")

</div>

Hi @arslan-erdo, thanks for reaching out with your question. You should be able to log the Confusion Matrix and the Classification Report adjusting the following snippet of code:

```python
import wandb
from sklearn.metrics import classification_report

entity = ""
project = ""

run = wandb.init(entity=entity, project=project)

true_labels = [0, 0, 0, 1, 2, 1, 0, 2, 1]
pred_labels = [0, 0, 0, 1, 1, 1, 2, 2, 2]
class_names = ["Class-0", "Class-1", "Class-2"]

report_columns = ["Class", "Precision", "Recall", "F1-score", "Support"]
class_report = classification_report(true_labels,pred_labels,target_names=class_names).splitlines()

report_table = []
for line in class_report[2:(len(class_names)+2)]:
    report_table.append(line.split())

run.log({
    "Confusion Matix": wandb.plot.confusion_matrix(y_true=true_labels, preds=pred_labels, class_names=class_names),
    "Classification Report": wandb.Table(data=report_table, columns=report_columns)
    })

```

You can see how this would look like in [this project](https://wandb.ai/fmamberti-wandb/classification-metrics?nw=nwuserfmambertiwandb).

Let me know if you have any questions on this.
