public List <DataStructures.TaxiFarePrediction> RunMultiplePredictions(int numberOfPredictions)
        {
            // Load data as input for predictions.
            IDataView inputDataForPredictions = context.Data.LoadFromTextFile <TaxiTrip>(_datasetFile, hasHeader: true, separatorChar: ',');

            Console.WriteLine("Predictions from saved model:");

            Console.WriteLine($"\n \n Test {numberOfPredictions} transactions, from the test datasource, that should be predicted as fraud (true):");

            var transactionList = new List <DataStructures.TaxiFarePrediction>();
            TaxiTripFarePredictionWithContribution prediction;

            DataStructures.TaxiFarePrediction explainedPrediction;

            context.Data.CreateEnumerable <TaxiTrip>(inputDataForPredictions, reuseRowObject: false)
            .Take(numberOfPredictions)
            .Select(testData => testData)
            .ToList()
            .ForEach(testData =>
            {
                testData.PrintToConsole();
                prediction          = predictionEngine.Predict(testData);
                explainedPrediction = new DataStructures.TaxiFarePrediction(prediction.FareAmount, prediction.GetFeatureContributions(model.GetOutputSchema(inputDataForPredictions.Schema)));
                transactionList.Add(explainedPrediction);
            });

            return(transactionList);
        }
示例#2
0
            public static PlotModel GetPlotModel(DataStructures.TaxiFarePrediction prediction)
            {
                var model = new PlotModel {
                    Title = "Taxi Fare Prediction Impact per Feature"
                };

                var barSeries = new BarSeries
                {
                    ItemsSource = new List <BarItem>(new[]
                    {
                        new BarItem {
                            Value = (prediction.Features[0].Value)
                        },
                        new BarItem {
                            Value = (prediction.Features[1].Value)
                        },
                        new BarItem {
                            Value = (prediction.Features[2].Value)
                        }
                    }),
                    LabelPlacement    = LabelPlacement.Inside,
                    LabelFormatString = "{0:.00}"
                };

                model.Series.Add(barSeries);

                model.Axes.Add(new CategoryAxis
                {
                    Position    = AxisPosition.Left,
                    Key         = "FeatureAxis",
                    ItemsSource = new[]
                    {
                        prediction.Features[0].Name,
                        prediction.Features[1].Name,
                        prediction.Features[2].Name
                    }
                });

                return(model);
            }