public IActionResult Index(BillsViewModel bvm)
        {
            MLContext         mlContext = new MLContext(seed: 9997);
            BillsModelTrainer bmt       = new BillsModelTrainer();

            var data    = bmt.GetRawData(mlContext, "2018Bills.csv");
            var trainer = mlContext.MulticlassClassification.Trainers.NaiveBayes(labelColumnName: "Label", featureColumnName: "Features");
            var model   = bmt.TrainModel(mlContext, data, trainer);

            PredictionEngineBase <RawInput, Prediction> predictor = mlContext.Model.CreatePredictionEngine <RawInput, Prediction>(model);
            var outcome = predictor.Predict(new RawInput
            {
                Game                       = 0,
                Quarterback                = bvm.Quarterback,
                Location                   = bvm.Location.ToString(),
                NumberOfPointsScored       = bvm.NumberOfPointsScored,
                TopReceiver                = bvm.TopReceiver,
                TopRunner                  = bvm.TopRunner,
                NumberOfSacks              = 0,
                NumberOfDefensiveTurnovers = 0,
                MinutesPossession          = 0,
                Outcome                    = "WHO KNOWS?"
            });

            return(Content($"Under these conditions, the most likely outcome is a {outcome.Outcome.ToLower()}."));
        }
Ejemplo n.º 2
0
        public static IEnumerable <TPredict> Predict <TBase, TPredict>(this PredictionEngineBase <TBase, TPredict> engine, IEnumerable <TBase> testData) where TBase : class, new() where TPredict : class, new()
        {
            List <TPredict> predicts = new List <TPredict>();

            foreach (var data in testData)
            {
                predicts.Add(engine.Predict(data));
            }
            return(predicts);
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            mlContext = new MLContext(seed: 9997);
            bmt       = new BillsModelTrainer();

            var data  = bmt.GetRawData(mlContext, "Resources\\2018Bills.csv");
            var split = mlContext.Data.TrainTestSplit(data, testFraction: 0.25);

            trainer = mlContext.MulticlassClassification.Trainers.NaiveBayes(labelColumnName: "Label", featureColumnName: "Features");
            model   = bmt.TrainModel(mlContext, split.TrainSet, trainer);

            predictor = mlContext.Model.CreatePredictionEngine <RawInput, Prediction>(model);
        }
Ejemplo n.º 4
0
        private Dictionary <uint, FileTypes> GetClusterToMap(PredictionEngineBase <FileData, FileTypePrediction> predictionEngine)
        {
            var map = new Dictionary <uint, FileTypes>();

            var fileTypes = Enum.GetValues(typeof(FileTypes)).Cast <FileTypes>();

            foreach (var fileType in fileTypes)
            {
                var fileData   = new FileData(fileType);
                var prediction = predictionEngine.Predict(fileData);
                map.Add(prediction.PredictedClusterId, fileType);
            }

            return(map);
        }
Ejemplo n.º 5
0
 private string GenerateOutcome(PredictionEngineBase <RawInput, Prediction> pe)
 {
     return(pe.Predict(new RawInput
     {
         Game = 0,
         Quarterback = "Josh Allen",
         Location = "Home",
         NumberOfPointsScored = 17,
         TopReceiver = "Robert Foster",
         TopRunner = "Josh Allen",
         NumberOfSacks = 0,
         NumberOfDefensiveTurnovers = 0,
         MinutesPossession = 0,
         Outcome = "WHO KNOWS?"
     }).Outcome);
 }
Ejemplo n.º 6
0
 private static float GetPrediction(PredictionEngineBase <EmployeeDto, SalaryPrediction> predictionEngine, Employee employee)
 {
     return(predictionEngine.Predict(new EmployeeDto(employee)).Salary);
 }