Exemplo n.º 1
0
        private static void TestSinglePrediction(MLContext mL, ITransformer model)
        {
            var engine = mL.Model
                         .CreatePredictionEngine <TaxiTrip, TaxiTripFarePrediction>(model);

            var sample = new TaxiTrip
            {
                VendorId       = "VTS",
                RateCode       = "1",
                PassengerCount = 1,
                TripTime       = 1140,
                TripDistance   = 3.75f,
                PaymentType    = "CRD",
                FareAmount     = 0
            };

            var prediction = engine.Predict(sample);

            Console.WriteLine($"Predicted fare: {prediction.FareAmount:0.####}, actual fare: 15.5");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a single comment of test data.
        /// Predicts fare amount based on test data.
        /// Combines test data and predictions for reporting.
        /// Displays the predicted results.
        /// </summary>
        /// <param name="mlContext"></param>
        /// <param name="model"></param>
        public static void TestSinglePrediction(MLContext mlContext, ITransformer model)
        {
            var predictionFunction = mlContext.Model.CreatePredictionEngine <TaxiTrip, TaxiTripFarePrediction>(model);

            var taxiTripSample = new TaxiTrip()
            {
                VendorId       = "VTS",
                RateCode       = "1",
                PassengerCount = 1,
                TripTime       = 1140,
                TripDistance   = 3.75f,
                PaymentType    = "CRD",
                FareAmount     = 0 // To predict. Actual/observed = 15.5
            };

            var prediction = predictionFunction.Predict(taxiTripSample);

            Console.WriteLine($"**********************************************************************");
            Console.WriteLine($"Predicted fare: {prediction.FareAmount:0.####}, actual fare: 15.5");
            Console.WriteLine($"**********************************************************************");
        }