public void Run() { base.Prepare(segment); var trainer = new Trainer(base.MLContext, base.DataLoader, horizon); var evaluator = new Evaluator(base.MLContext, base.DataLoader, trainer); var forecaster = new Forecaster(base.MLContext, trainer); //UI var grid = new Grid(90); //General info grid.PrintLine(); grid.PrintRow("Mean Absolute Error", evaluator.MAE.ToString("F3")); grid.PrintRow("Root Mean Squared Error", evaluator.RMSE.ToString("F3")); grid.PrintLine(); //Evaluation results var testData = base.DataLoader.TestData; var predictions = forecaster.Predict(); var forecastOutput = base.MLContext.Data.CreateEnumerable <ModelInput>(testData, reuseRowObject: false) .Take(horizon) .Select((ModelInput model, int index) => { var date = model.Date; var actualTemps = model.LandAverageTemperature; var lowerEstimate = predictions.LowerBoundLandAverageTemperature[index]; var estimate = predictions.ForecastedLandAverageTemperature[index]; var upperEstimate = predictions.UpperBoundLandAverageTemperature[index]; return(new List <string> { date.ToShortDateString(), "Yellow|" + actualTemps.ToString("F3"), "Yellow|" + estimate.ToString("F3"), lowerEstimate.ToString("F3"), upperEstimate.ToString("F3") }); }); grid.PrintLine(); grid.PrintRow("Date", "Yellow|Actual", "Yellow|Forecase", "Lower", "Upper"); grid.PrintLine(); // Output predictions foreach (var prediction in forecastOutput) { grid.PrintRow(prediction.ToArray()); grid.PrintLine(); } }
public void Run(int year, int month) { var predictionForIndex = ((year - segment.Year) * 12) + month; var trainer = new Trainer(base.MLContext, base.DataLoader, predictionForIndex); var forecaster = new Forecaster(base.MLContext, trainer); //UI var grid = new Grid(90); //Results var predictions = forecaster.Predict(predictionForIndex); grid.PrintLine(); //grid.PrintRow("Date", "Yellow|Forecase", "Lower", "Upper"); //grid.PrintLine(); grid.PrintRow( DateTime.Parse(year + "-" + month + "-1").ToShortDateString(), "Yellow|" + predictions.ForecastedLandAverageTemperature[predictionForIndex - 1].ToString("F3"), predictions.LowerBoundLandAverageTemperature[predictionForIndex - 1].ToString("F3"), predictions.UpperBoundLandAverageTemperature[predictionForIndex - 1].ToString("F3") ); }