Exemplo n.º 1
0
        private static void TestMultiplePredictions(MLContext mlContext)
        {
            ITransformer trainedModel = mlContext.Model.Load(modelPath, out var modelInputSchema);

            // Create prediction engine related to the loaded trained model
            var predEngine = mlContext.Model.CreatePredictionEngine <EmployeeSalary, EmployeeSalaryPrediction>(trainedModel);

            for (float i = 0; i < 15; i = i + 0.5f)
            {
                var taxiTripSample = new EmployeeSalary()
                {
                    YearsExperience = i,
                    Salary          = 0
                };

                var resultprediction = predEngine.Predict(taxiTripSample);
                Console.WriteLine(resultprediction.Salary);
            }
        }
Exemplo n.º 2
0
        private static void TestSinglePrediction(MLContext mlContext, float yearsExperience)
        {
            var taxiTripSample = new EmployeeSalary()
            {
                YearsExperience = yearsExperience,
                Salary          = 0
            };

            ITransformer trainedModel = mlContext.Model.Load(modelPath, out var modelInputSchema);

            // Create prediction engine related to the loaded trained model
            var predEngine = mlContext.Model.CreatePredictionEngine <EmployeeSalary, EmployeeSalaryPrediction>(trainedModel);

            //Score
            var resultprediction = predEngine.Predict(taxiTripSample);

            ///

            Console.WriteLine($"**********************************************************************");
            Console.WriteLine($"Predicted salary: {resultprediction.Salary:0.####}");
            Console.WriteLine($"**********************************************************************");
        }