1

using the function classification_report from scikit-learn you get information about important metrics like Accuracy, Precission, Recall, F1 Score (micro and macro) of a Model. The function receives as input arguments the vector with the true labels and a vector with the predicted labels to calculate the metrics. Is there a function which calculates the identical metrics as classification_report when an already existing confusion matrix is used as input argument like:

[[3955   62  610]
 [ 319 2982  117]
 [ 584   52 1439]]

For certain reasons, the vectors with the true and predicted labels can no longer be traced. The possible function is needed for an automated calculation of the metrics of several confusion matrices.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
CarstenWE
  • 31
  • 5
  • [here is the code for that function](https://github.com/scikit-learn/scikit-learn/blob/b7d01716216042dda9663f1732d8419e62858a1e/sklearn/metrics/_classification.py#L2185). It looks like it doesn't operate on the confusion matrix, but on the data and predictions directly. – Him Aug 10 '22 at 15:23
  • Thanks for the code.Yes, exactly on true labels and estimated labels as input. However, I need a function with the confusion matrix as input if such a function exists at all. – CarstenWE Aug 10 '22 at 15:31
  • 1
    I suspect you'll have to roll your own. Many of the sklearn functions operate on the data because it is more flexible - for example, you can weight data points. [here is another](https://github.com/NREL/TEAM-TDM/blob/13580917683e79292c8a1b7506399e87682fe459/src/ml_battery/stacked_estimators.py#L22) classifier reporting tool. Some of these scores operate directly on the confusion matrix. You might need to compute things like precision and recall by hand though. But, it's just arithmetic at this point... – Him Aug 10 '22 at 15:40

0 Answers0