- 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");
推薦閱讀
- UNIX編程藝術
- CockroachDB權威指南
- Visual Basic 6.0程序設計計算機組裝與維修
- Java面向對象思想與程序設計
- Learning Flask Framework
- jQuery EasyUI網站開發實戰
- 機械工程師Python編程:入門、實戰與進階
- HTML5+CSS3+JavaScript Web開發案例教程(在線實訓版)
- Monitoring Elasticsearch
- Unity 5 for Android Essentials
- Serverless computing in Azure with .NET
- ElasticSearch Cookbook(Second Edition)
- Mastering Linux Security and Hardening
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- Learning D3.js 5 Mapping(Second Edition)