ML.NET CLI 生成了经过训练的模型和代码,因此现在可以按照以下步骤在 .NET 应用程序(例如,SentimentModel
控制台应用)中使用该模型:
consumeModelApp
目录。
cd SentimentModel
在任何代码编辑器中打开 Program.cs
然后检查代码。代码应如下所示:
using System;
namespace SentimentModel.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// Add input data
SentimentModel.ModelInput sampleData = new SentimentModel.ModelInput()
{
Col0 = @"Wow... Loved this place."
};
// Make a single prediction on the sample data and print results
var predictionResult = SentimentModel.Predict(sampleData);
Console.WriteLine("Using model to make single prediction -- Comparing actual Col1 with predicted Col1 from sample data...\n\n");
Console.WriteLine($"Col0: @{"Wow... Loved this place."}");
Console.WriteLine($"Col1: {1F}");
Console.WriteLine($"\n\nPredicted Col1: {predictionResult.PredictedLabel}\n\n");
Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
}
}
}
运行 SentimentModel.ConsoleApp
。可以通过在终端中运行以下命令来执行此操作(请确保你位于 SentimentModel
中):
dotnet run
输出应如下所示:
Using model to make single prediction -- Comparing actual Col1 with predicted Col1 from sample data...
Col0: Wow... Loved this place.
Col1: 1
Predicted Col1: 1
=============== End of process, hit any key to finish ===============