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

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");
主站蜘蛛池模板: 伽师县| 屏山县| 昌图县| 金平| 金溪县| 沂南县| 察隅县| 龙里县| 普定县| 平顶山市| 保靖县| 开远市| 宾阳县| 利辛县| 开原市| 绥德县| 新蔡县| 上栗县| 双江| 襄城县| 舟山市| 延吉市| 名山县| 潞城市| 天门市| 泰州市| 乌恰县| 乌鲁木齐市| 隆化县| 阳西县| 云龙县| 麦盖提县| 信阳市| 云阳县| 伊吾县| 彰武县| 定南县| 洛浦县| 和硕县| 湖北省| 怀集县|