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

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");
主站蜘蛛池模板: 甘泉县| 巴彦县| 敦煌市| 北宁市| 临城县| 石嘴山市| 芮城县| 库伦旗| 康定县| 永嘉县| 故城县| 剑川县| 绵竹市| 宣城市| 吉隆县| 鹿泉市| 孟津县| 高尔夫| 黄浦区| 平昌县| 昔阳县| 稻城县| 娱乐| 广昌县| 田阳县| 天峻县| 维西| 永清县| 肇东市| 淳化县| 汉沽区| 乌苏市| 鹤庆县| 庆元县| 柳河县| 武川县| 佛坪县| 云南省| 三明市| 沙雅县| 晋江市|