Walter Verhoeven
Walter Verhoeven

Reputation: 4421

in Microsoft ML how does one configure a score and predict label output

We are evaluating ML.Net, release 0.6, I get frustrated with the error messages... My issue, perhaps some one know what I am doing wrong.

I have a class that we created for ML.Net, it has features and a label. in the learning Pipeline I add

var pipeline = new LearningPipeline() {
    new TextLoader(_trainingFile.FullName).CreateFrom<MyClass>(useHeader: true, separator: separator),
    new ColumnCopier(("Trend", "Label")),
    new Dictionarizer("Label"),
    new CategoricalOneHotVectorizer("Trend"),
    new ColumnConcatenator("Features,"col1","col2",... "Trend"),
    new StochasticDualCoordinateAscentClassifier()
    {
        Shuffle = false,
    },
    new PredictedLabelColumnOriginalValueConverter()
    {
            PredictedLabelColumn="PredictedLabel"
    }
};

My Predict class looks like this:

class MyPrediction
{
    [ColumnName("PredictedLabel")]
    public string PredictedLabels;

    [ColumnName("Score")]
    public float Scores;
}

The Trend column is a string with Enum labels. I run the training and it works well, not always predicting correct but when I add the score column I get an error.

Can't bind the IDataView column 'Score' of type 'Vec' to field or property 'Scores' of type 'System.Single'.

What do I need to do to get the predicted value and the score, anny suggestions are welcome.

Upvotes: 0

Views: 1170

Answers (1)

Zruty
Zruty

Reputation: 8667

To answer more broadly, any ML.NET trained model is an ITransformer. This means that it can Transform() an incoming dataset (the 'examples') into the output dataset (the 'predictions').

This capability can be referred to as 'batch prediction': once you have a whole dataset of examples, you can run the model on them all with one call to Transform().

In order to facilitate a 'example to example' prediction, we have added the PredictionFunction idiom. Here is a complete example.

You can 'request' any number of columns from the result of prediction: just add the corresponding fields to your 'prediction' class, and the PredictionFunction will populate them appropriately.

Upvotes: 1

Related Questions