ML.NET 教學課程 - 10 分鐘入門
使用您的模型
ML.NET CLI 已為您產生經過訓練的模型和程式碼,因此您現在可以按照以下步驟在 .NET 應用程式 (例如,SentimentModel
主控台應用程式) 中使用該模型:
- 在命令列中,瀏覽至
consumeModelApp
目錄。Terminalcd SentimentModel
-
在任何程式碼編輯器中開啟
Program.cs
,並檢查程式碼。程式碼應如下所示:Program.csusing 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
目錄中):Terminaldotnet run
輸出看起來應該像這樣:
TerminalUsing model to make single prediction -- Comparing actual Col1 with predicted Col1 from sample data... Col0: Wow... Loved this place. Col1: 1 Class Score ----- ----- 1 0.9651076 0 0.034892436 =============== End of process, hit any key to finish ===============