ML.NET Tutorial - Get started in 10 minutes

Generate code

After training is completed, four files are automatically added as code-behind to the SentimentModel.mbconfig:

  • SentimentModel.consumption.cs: This file contains the model input and output classes and a Predict method that can be used for model consumption.
  • SentimentModel.evaluate.cs: This file contains a CalculatePFI method that uses the Permutation Feature Importance (PFI) technique to evaluate which features contribute most to the model predictions.
  • SentimentModel.mlnet: This file is the trained ML.NET model, which is a serialized zip file.
  • SentimentModel.training.cs: This file contains the code to understand the importance input columns have on your model predictions.

Visual Studio Solution Explorer

In the Consume step in Model Builder, a code snippet is provided which creates sample input for the model and uses the model to make a prediction on that input.

Model Builder also offers Project templates that you can optionally add to your solution. There are two project templates (a console app and a web API), both which consume the trained model.

Model Builder's Consume Window'

The ML.NET CLI adds both the machine learning model and the code for training and consuming the model, which includes the following:

  • A new directory called SentimentModel is created containing a .NET console app that includes the following files:
    • Program.cs: This file contains code to run the model.
    • SentimentModel.consumption.cs: This file contains the model input and output classes and a Predict method that can be used for model consumption.
    • SentimentModel.mbconfig: This file is a JSON file that keeps track of the configurations and results from your training.
    • SentimentModel.training.cs: This file contains the training pipeline (data transforms, algorithm, and algorithm parameters) used to train the final model.
    • SentimentModel.zip: This file is the trained ML.NET model, which is a serialized zip file.

To try the model, you can run the console app to predict the sentiment of a single statement with the model.

Continue