- Hands-On Machine Learning with ML.NET
- Jarred Capellman
- 121字
- 2021-06-24 16:43:34
The Predictor class
The Predictor class, much like what was changed in the linear regression example, is simply modified to support the new model and return the classification:
- We begin by passing in the two new classes, FileInput and FilePrediction, to the CreatePredictionEngine method:
var predictionEngine = MlContext.Model.CreatePredictionEngine<FileInput, FilePrediction>(mlModel);
- Next, we create the FileInput object, setting the Strings property with the return value of the GetStrings method we wrote earlier:
var prediction = predictionEngine.Predict(new FileInput
{
Strings = GetStrings(File.ReadAllBytes(inputDataFile))
});
- Finally, we update the output call to the Console object with our file classification and probability:
Console.WriteLine(
$"Based on the file ({inputDataFile}) the file is classified as {(prediction.IsMalicious ? "malicious" : "benign")}" +
$" at a confidence level of {prediction.Probability:P0}");
推薦閱讀
- 大學計算機基礎(第二版)
- Hyper-V 2016 Best Practices
- Getting started with Google Guava
- 企業級Java EE架構設計精深實踐
- AngularJS深度剖析與最佳實踐
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- Java Web程序設計任務教程
- Elasticsearch Server(Third Edition)
- Terraform:多云、混合云環境下實現基礎設施即代碼(第2版)
- Laravel Application Development Blueprints
- Mudbox 2013 Cookbook
- IPython Interactive Computing and Visualization Cookbook
- Python預測分析與機器學習
- Spring Boot 3:入門與應用實戰
- 算法訓練營:海量圖解+競賽刷題(入門篇)