# Confusion matrix not generating "Custom chart" entry

**URL:** <https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181>\
**Category:** W&B Help\
**Tags:** wandb\
**Created:** [September 25, 2022, 6:38am UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181 "2022-09-25T06:38:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbirch](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@tbirch](https://community.wandb.ai/u/tbirch)\
**Post date:** [September 25, 2022, 6:38am UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/1 "2022-09-25T06:38:12Z")

</div>

I’m using the following code (based on `wandb.plot.confusion_matrix` because I accumulate my own confusion matrix per step using `tf.math.confusion_matrix`) to log a confusion matrix:

```auto
 data = []
 for i in range(n_classes):
     for j in range(n_classes):
         data.append([class_names[i], class_names[j], value[i, j]])

 fields = {
     "Actual": "Actual",
     "Predicted": "Predicted",
     "nPredictions": "nPredictions",
 }
 return wandb.plot_table(
     "wandb/confusion_matrix/v1",
     wandb.Table(columns=["Actual", "Predicted", "nPredictions"], data=data),
     fields,
     {"title": title},
 )

```

On one run I did get the custom chart, but the “Actual” labels (on the Y-axis) were horribly laid out so I tweaked the code to generate different labels and now I don’t see the custom chart. I tried to create my own custom chart cloning the settings from the other confusion matrix, but the “OK” button is grayed out.

Are there some extra checks somewhere that decide whether or not to generate a confusion matrix report?

 ![Screen Shot 2022-09-25 at 4.30.45 pm](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/d/d5db4d0f7e4bcecf7a79828175f915f107ddd53b.png)  
 ![Screen Shot 2022-09-25 at 4.34.29 pm](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/0/074387bfc030623568325ce892dc4c2921eb1d2d.jpeg)

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [September 29, 2022, 9:24am UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/2 "2022-09-29T09:24:10Z")

</div>

Hi @tbirch, thank you for reporting this, and sorry for the delay in this response. I am following up with you here after our discussion in the Support chat.

I have looked into the wandb-summary.json and the summary metrics between the two Runs. It appears that the variables conf\_mat\_table and conf\_mat\_norm\_table were not logged in the case where the confusion matrix isn’t generated. The Vega spec and the code snippet above are correct, but the button is greyed out because it can’t query the data. I am wondering if you had overwritten the Run, or did this experiment run a single time?

The artifacts seem to be properly logged in both cases and you can get them to your Workspace using a Weave expression such as:  
project(“entity”, “project-name\_”).artifact(“run-runid-conf\_mat\_norm\_table”).membershipForAlias(“v19”).artifactVersion.file(“conf\_mat\_norm\_table.table.json”)

Would you be interested in the option to download the data, generate the chart externally and then log it to this Run?

---

<div class="post-metadata">

**Author:** ![tbirch](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@tbirch](https://community.wandb.ai/u/tbirch)\
**Post date:** [September 29, 2022, 10:25am UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/3 "2022-09-29T10:25:10Z")

</div>

I’d like to just know the correct code to log a “wandb/confusion\_matrix/v1” given a NxN matrix of values and N labels. I don’t care about the data for these runs, I was just doing them to test confusion matrix.

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [October 11, 2022, 10:09pm UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/4 "2022-10-11T22:09:47Z")

</div>

Hi @tbirch apologies for the late reply here, [this](https://colab.research.google.com/github/wandb/examples/blob/master/colabs/wandb-log/Log_a_Confusion_Matrix_with_W%26B.ipynb#scrollTo=6NZJwm8OE7Qw) is a working Colab that demonstrates how to log confusion matrices from your code. A minimal code example would be something like the following:

```auto
        vals = np.random.uniform(size=(10, 5))
        probs = np.exp(vals)/np.sum(np.exp(vals), keepdims=True, axis=1)
        y_true = np.random.randint(0, 5, size=(10))
        labels = ["Cat", "Dog", "Bird", "Fish", "Horse"]
        wandb.log({'confusion_matrix': wandb.plot.confusion_matrix(probs, y_true=y_true, class_names=labels)})

```

Please let me know if that would help, or if you still have issues or further questions about this.

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [October 17, 2022, 10:35am UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/5 "2022-10-17T10:35:14Z")

</div>

Hi @tbirch I wanted to follow up on this request, did the above Colab solve this? and would there be any further questions to help you with? thanks!

---

<div class="post-metadata">

**Author:** ![thanos-wandb](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@thanos-wandb](https://community.wandb.ai/u/thanos-wandb)\
**Post date:** [October 20, 2022, 12:53pm UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/6 "2022-10-20T12:53:03Z")

</div>

Hi @tbirch since we haven’t heard back from you, I am going to close this ticket for now. If you still experience any issues, please let us know and we will keep investigating.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [December 19, 2022, 12:53pm UTC](https://community.wandb.ai/t/confusion-matrix-not-generating-custom-chart-entry/3181/7 "2022-12-19T12:53:36Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
