Splunk Search

Convert long table to confusion matrix

ebarnhill
Engager

I am looking to create a confusion matrix out of a tabled query of the form

[query] | table unchanged true pred

Where, due to circumstances upstream from me, unchanged is the result if the prediction was correct, true is the ground truth if the prediction was wrong and pred is the prediction if the prediction is wrong. Example tabular output, assuming categories are A, B, C:

unchanged | true | pred

A |

B |

  | A | B

  | C | A

etc.

 

I would like to accumulate the counts into a confusion matrix. So let's say the classifier categories are A, B, C. The table should count the matches from "unchanged" along the diagonal and put "pred" and "true" into the appropriate off-diagonal. Example table:

pred:   A   B   C

true:

A       12  6   1

B        6   20  2

C        2   3   30

If you are familiar with confusion matrices you will have the idea. How can I generate such a summary table?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Would something like this work for you?

| makeresults
| eval _raw="unchanged,true,pred
A,,
B,,
,A,B
,C,A
A,,
C,,
,C,B
,C,A
B,,
B,,
,A,C
,C,B
A,,
A,,
,A,C
,B,C"
| multikv forceheader=1
| table unchanged true pred



| eval predicted=coalesce(unchanged,pred)
| eval actual=coalesce(true,unchanged)
| stats count by predicted actual
| xyseries actual predicted count

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Would something like this work for you?

| makeresults
| eval _raw="unchanged,true,pred
A,,
B,,
,A,B
,C,A
A,,
C,,
,C,B
,C,A
B,,
B,,
,A,C
,C,B
A,,
A,,
,A,C
,B,C"
| multikv forceheader=1
| table unchanged true pred



| eval predicted=coalesce(unchanged,pred)
| eval actual=coalesce(true,unchanged)
| stats count by predicted actual
| xyseries actual predicted count
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...