ConfusionMatrix display in VSCode when there are ~ 16 categories

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

             ┌───────────────────────────────────────────────────────┐
              │                     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:

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 ?

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 to showing only the matrix. You can access the labels like this:

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.

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.

1 Like

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