練習:在 .NET 主控台應用程式中取用模型
您花了一些時間定型模型,並使用評估計量來選取最適合您資料的模型。 現在是時候在公司的裝置上進行預測時使用。 在本單元中,您會建立主控台應用程式來接受新的資料,並使用您的模型來預測裝置是否會失敗。
將主控台應用程式新增至解決方案
在 [Model Builder] 畫面的 [取用] 步驟中:
- 針對主控台應用程式範本選取 [新增至解決方案]。
- 在 [新增範例主控台應用程式] 對話方塊中,輸入名稱 PredictiveMaintenanceConsole。
- 選取 [新增至解決方案]。
幾秒鐘之後,新的 .NET 主控台應用程式就會新增至您的解決方案。
執行您的應用程式
在 Visual Studio 方案總管中,以滑鼠右鍵按一下 PredictiveMaintenanceConsole 專案。
選取 [設定為啟始專案]。
啟動您的應用程式。
主控台視窗隨即開啟,並產生如下輸出文字:
Using model to make single prediction -- Comparing actual Machine_failure with predicted Machine_failure from sample data... Product_ID: M14860 Type: M Air_temperature: 298.1 Process_temperature: 308.6 Rotational_speed: 1551 Torque: 42.8 Tool_wear: 0 Machine_failure: 0 Predicted Machine_failure: 0 =============== End of process, hit any key to finish ===============
提示
在此示範中,預設硬式編碼資料範例是用來執行應用程式並進行預測。 在實際環境中,您想要從檔案或主控台取得輸入,並針對該資料進行預測。
恭喜! 您已使用 ML.NET 和 Model Builder,取用機器學習模型。