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

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");
主站蜘蛛池模板: 永新县| 独山县| 华亭县| 佛教| 彭山县| 苏尼特右旗| 汾西县| 浦县| 科尔| 防城港市| 武清区| 铜鼓县| 绥江县| 东宁县| 宜黄县| 嘉祥县| 临漳县| 沙河市| 荃湾区| 虞城县| 马鞍山市| 广水市| 临沂市| 遂昌县| 大丰市| 宣城市| 新巴尔虎左旗| 连江县| 闻喜县| 三都| 上思县| 卫辉市| 安吉县| 朝阳市| 花莲县| 景洪市| 金乡县| 正定县| 疏附县| 固始县| 宁蒗|