官术网_书友最值得收藏!

The Predictor class

There are a couple of changes in this class to handle the employment prediction scenario:

  1. 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;
}
  1. 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);
  1. 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));
  1. 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");
主站蜘蛛池模板: 康马县| 西乌珠穆沁旗| 曲周县| 西丰县| 尤溪县| 淮安市| 濉溪县| 涡阳县| 逊克县| 内江市| 吉安市| 和硕县| 许昌县| 云和县| 金堂县| 开鲁县| 阳朔县| 崇礼县| 明溪县| 上蔡县| 横山县| 五原县| 泰兴市| 通城县| 洛隆县| 兴山县| 登封市| 巴林右旗| 荔波县| 纳雍县| 内黄县| 孟津县| 景德镇市| 莱西市| 开封市| 涿州市| 罗甸县| 浦江县| 柘荣县| 湘西| 镇远县|