Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 895
craig Avatar asked Mar 05 '23 07:03

craig


1 Answers

For newer versions this one will do the trick as TryGetScoreLabelNames has been removed:

    var scoreEntries = GetSlotNames(predictor.OutputSchema, "Score");

    ...

    private static List<string> GetSlotNames(DataViewSchema schema, string name)
    {
        var column = schema.GetColumnOrNull(name);

        var slotNames = new VBuffer<ReadOnlyMemory<char>>();
        column.Value.GetSlotNames(ref slotNames);
        var names = new string[slotNames.Length];
        var num = 0;
        foreach (var denseValue in slotNames.DenseValues())
        {
            names[num++] = denseValue.ToString();
        }

        return names.ToList();
    }

(Source: http://www.programmersought.com/article/3762753756/)

Of course this needs more error handling etc.

like image 134
Samuel Avatar answered Mar 18 '23 11:03

Samuel