- Hands-On Machine Learning with ML.NET
- Jarred Capellman
- 158字
- 2021-06-24 16:43:33
The Predictor class
There are a couple of changes in this class to handle the employment prediction scenario:
- First, validate that the input file exists before making a prediction on it:
if (!File.Exists(inputDataFile))
{
Console.WriteLine($"Failed to find input data at {inputDataFile}");
return;
}
- The other change is in the prediction call itself. As you probably guessed, the TSrc and TDst arguments need to be adjusted to utilize both of the new classes we created, EmploymentHistory and EmploymentHistoryPrediction:
var predictionEngine = MlContext.Model.CreatePredictionEngine<EmploymentHistory, EmploymentHistoryPrediction>(mlModel);
- Given that we are no longer simply passing in the string and building an object on the fly, we need to first read in the file as text. We then deserialize the JSON into our EmploymentHistory object:
var json = File.ReadAllText(inputDataFile);
var prediction = predictionEngine.Predict(JsonConvert.DeserializeObject<EmploymentHistory>(json));
- Lastly, we need to adjust the output of our prediction to match our new EmploymentHistoryPrediction properties:
Console.WriteLine(
$"Based on input json:{System.Environment.NewLine}" +
$"{json}{System.Environment.NewLine}" +
$"The employee is predicted to work {prediction.DurationInMonths:#.##} months");
推薦閱讀
- Python概率統計
- JavaScript高效圖形編程
- 深入淺出RxJS
- Python面向對象編程:構建游戲和GUI
- 批調度與網絡問題的組合算法
- Python機器學習算法: 原理、實現與案例
- Java Web開發就該這樣學
- Advanced Express Web Application Development
- Unity 2018 Shaders and Effects Cookbook
- Internet of Things with ESP8266
- Scratch趣味編程:陪孩子像搭積木一樣學編程
- Go語言開發實戰(慕課版)
- Building Dynamics CRM 2015 Dashboards with Power BI
- Python語言科研繪圖與學術圖表繪制從入門到精通
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通