Skip to content

Confusion Matrix Representation / Return Value #19012

Open
@shubhamdo

Description

@shubhamdo

Describe the workflow you want to enable

An enhancement to the output of confusion matrix function, better representing the true and predicted values for multilevel classes.

  • i.e. Current Representation with code:
    from sklearn.metrics import confusion_matrix
    y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
    y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
    confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
    Output:
    array([[2, 0, 0],
    [0, 0, 1],
    [1, 0, 2]])

Describe your proposed solution

When you have multiple levels you can have difficulty reading the ndarray, associating the levels with the True and Predicted values.

Proposed solution should look similar to the table below, providing better readability of the confusion matrix.

    Predicted Value  
  Levels ant bird cat
True ant 2 0 0
Value bird 0 0 1
  cat 1 0 2

Possible Solutions:

  1. Provide a parameter to prettyprint the matrix. printMatrix [type:bool]
  2. Include another parameter to return ndarray, index as true_values, columns as predicted_values
    For example:
    cm = confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
    index=["true:ant", "true:bird", "true:cat"]
    columns=["pred:ant", "pred:bird", "pred:cat"]
    return cm, index, columns
    Which can be easily converted into a dataframe for further use

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions