# ConfusionMatrix display in VSCode when there are ~ 16 categories

**URL:** <https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763>\
**Category:** Machine Learning\
**Created:** [August 13, 2023, 5:46am UTC](https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763 "2023-08-13T05:46:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [August 13, 2023, 5:46am UTC](https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763/1 "2023-08-13T05:46:42Z")

</div>

When trying to display small confusion matrix for example for 4 categories classifier I get:

```julia
             ┌───────────────────────────────────────────────────────┐
              │ Ground Truth │
┌─────────────┼─────────────┬─────────────┬─────────────┬─────────────┤
│ Predicted │ a │ b │ c │ d │
├─────────────┼─────────────┼─────────────┼─────────────┼─────────────┤
│ a │ 1 │ 0 │ 0 │ 0 │
├─────────────┼─────────────┼─────────────┼─────────────┼─────────────┤
│ b │ 0 │ 2 │ 0 │ 0 │
├─────────────┼─────────────┼─────────────┼─────────────┼─────────────┤
│ c │ 0 │ 0 │ 1 │ 1 │
├─────────────┼─────────────┼─────────────┼─────────────┼─────────────┤
│ d │ 0 │ 0 │ 1 │ 0 │
└─────────────┴─────────────┴─────────────┴─────────────┴─────────────┘

```

However if there 16 classes classifier I lose all formatting, no row & column names are display and some of the rows are skipped:

```julia
16×16 Matrix{Int64}:
 2204 124 23 2 4 0 3 25 22 23 5 28 75 54 35 3
  133 1702 120 15 11 0 1 2 4 5 2 22 50 26 39 3
   12 80 792 34 41 3 1 2 0 0 0 9 22 5 23 3
    1 1 27 144 10 0 0 0 0 0 0 0 1 0 1 0
    2 11 20 12 305 6 0 1 0 0 0 1 1 1 3 3
    0 0 0 0 2 38 0 0 0 0 0 0 1 0 0 0
    ⋮ ⋮ ⋮ ⋮
   12 1 0 0 1 0 12 19 12 3 1451 290 63 6 5 0
   56 37 11 0 0 0 15 73 42 19 357 4537 608 47 52 2
  106 89 21 0 2 0 2 10 25 5 74 589 4314 200 181 3
   40 24 7 1 0 0 0 4 3 1 3 38 114 1242 68 7
   18 42 18 2 2 0 0 4 8 1 4 27 101 39 784 30
    2 2 2 0 0 0 0 0 0 0 0 4 3 4 20 97
type or paste code here

```

How do I enforce the nice display on the bigger 16X16 matrix ?

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [August 13, 2023, 8:57pm UTC](https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763/2 "2023-08-13T20:57:23Z")

</div>

So, I’m assuming this is a reference to the `confmat` function provided by MLJ.jl (through MLJBase.jl).

If the pretty display is too wide, the display [falls back](https://github.com/JuliaAI/MLJBase.jl/blob/7cea92964d93b2b351abe395963d637aa655fb91/src/measures/confusion_matrix.jl#L171) to showing only the matrix. You can access the labels like this:

```julia
julia> y = Char.(97:107);

ulia> m = confmat(y, y)
┌ Warning: The classes are un-ordered,
│ using order: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'].
│ To suppress this warning, consider coercing to OrderedFactor.
└ @ MLJBase ~/.julia/packages/MLJBase/0rn2V/src/measures/confusion_matrix.jl:122
11×11 Matrix{Int64}:
 1 0 0 0 0 0 0 0 0 0 0
 0 1 0 0 0 0 0 0 0 0 0
 0 0 1 0 0 0 0 0 0 0 0
 0 0 0 1 0 0 0 0 0 0 0
 0 0 0 0 1 0 0 0 0 0 0
 0 0 0 0 0 1 0 0 0 0 0
 0 0 0 0 0 0 1 0 0 0 0
 0 0 0 0 0 0 0 1 0 0 0
 0 0 0 0 0 0 0 0 1 0 0
 0 0 0 0 0 0 0 0 0 1 0
 0 0 0 0 0 0 0 0 0 0 1

julia> m.labels
11-element Vector{String}:
 "a"
 "b"
 "c"
 "d"
 "e"
 "f"
 "g"
 "h"
 "i"
 "j"
 "k"

```

You can get the raw matrix with `m.mat`.

---

<div class="post-metadata">

**Author:** ![roeya](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@roeya](https://discourse.julialang.org/u/roeya)\
**Post date:** [August 14, 2023, 6:48am UTC](https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763/3 "2023-08-14T06:48:51Z")

</div>

After looking at the source code it seems that column width is hard code to 13 chars, I have created a pool request with a dynamic column width calculation so the display will be fine:  
The required screen size in my case was 239 chars however with dynamic calculation it is only 91 chars.

So now it will be easier to use.

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [August 16, 2023, 9:34pm UTC](https://discourse.julialang.org/t/confusionmatrix-display-in-vscode-when-there-are-16-categories/102763/4 "2023-08-16T21:34:16Z")

</div>

Thank you! This PR has been merged and a new release of MLJBase will be tagged shortly.
