- 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");
推薦閱讀
- 計算思維與算法入門
- Learning ArcGIS Pro 2
- JavaScript+jQuery網頁特效設計任務驅動教程(第2版)
- YARN Essentials
- Python數據可視化之Matplotlib與Pyecharts實戰
- JavaScript 程序設計案例教程
- Swift語言實戰精講
- 區塊鏈技術進階與實戰(第2版)
- Serverless Web Applications with React and Firebase
- 一步一步跟我學Scratch3.0案例
- HTML+CSS+JavaScript網頁制作:從入門到精通(第4版)
- Appcelerator Titanium:Patterns and Best Practices
- Learning C++ by Creating Games with UE4
- jQuery Mobile Web Development Essentials(Second Edition)
- Getting Started with JUCE