Search code examples
c#artificial-intelligenceml.net

ML.NET Show which score relates to which label


With ML.Net I am using a classifier for text interpretation. The prediction has a score column as float[] and a predicted label. This works in that the highest score relates to the predicted label, but the other scores are just floats in no particular order. How do I know which score relates to which label? How can I see what the second highest weighted label?

For example, I get this back: 0.00005009 0.00893076 0.1274763 0.6209787 0.2425644

The 0.6 is my predicted label, but I also need to see which label the 0.24 is so I can see why it is confused.

Labels are text strings such as "Greeting" or "Joke" which were Dictionarized in the pipeline, so maybe that is why they aren't in the correct order?

Is there any way in ML.Net to link the two together? To show which score relates to which label?


Solution

  • You can get the labels corresponding to the scores using the following code:

    string[] scoreLabels;
    model.TryGetScoreLabelNames(out scoreLabels);
    

    Additional details can be found here and here.

    Note that this may change with the upcoming ML.NET 0.6 APIs. These APIs will expose the Schema directly and enable getting this information (along with other useful information). This might be similar to how TryGetScoreLabelNames works today.