Example #1
0
        // given a file, x attr, y attr, date delimiter, has time boolean, how many values to include in the model, how many to predict,
        // whether the data should be reversed to have the dates increasing, and the significance level for the stationarity test,
        // the predicted values, the actual values, and the MAE, RMSE, and MAPE errors.
        public static void forecasttest(string file, string outfile, string xattr, char delimiter, bool hastime, bool change, double split, bool reverse, double siglevel, bool log)
        {
            var data = GetData(file, xattr, hastime).Select(a => TimeSeriesWrapper.getDataObject(a, change));

            if (reverse)
            {
                data = data.Reverse();
            }

            var splitData = DivideData(data.ToArray(), split);

            TimeSeriesWrapper ts = new TimeSeriesWrapper();

            ARMAModel model = ts.buildARMAModel(splitData.Item1.ToArray(), siglevel, -1, log: log);

            List <DateTime> futureTimes = splitData.Item2.Select(a => a.Date).ToList();

            TimeSeries mergedtimeseries = ts.predictARMA(futureTimes, model);

            var points = GetPoints(mergedtimeseries, splitData);

            ChartPoints(file.Split('/').Last(), points.Item1, points.Item2);

            double[] errresults = TimeSeriesWrapper.evaluatePrediction(mergedtimeseries, splitData.Item2, outfile);
            Console.WriteLine("Mean absolute error (MAE): " + errresults[0]);
            Console.WriteLine("Root mean squared error (RMSE): " + errresults[1]);
            Console.WriteLine("Mean absolute percentage error (MAPE): " + errresults[2]);
        }
Example #2
0
        // given a file, x attr, y attr, date delimiter, has time boolean, how many values to include in the model, how many to predict,
        // whether the data should be reversed to have the dates increasing, and the significance level for the stationarity test,
        // the predicted values, the actual values, and the MAE, RMSE, and MAPE errors.
        public void forecasttest(string file, string outfile, string xattr, char delimiter, bool hastime, bool change, double inmodel, double numpredict, bool reverse, double siglevel, bool log)
        {
            CSVReader reader = new CSVReader();

            string[] headers = reader.getHeaders(file, ',');
            int      xindex  = -1;

            for (int j = 0; j < headers.Length; j++)
            {
                if (String.Compare(headers[j], xattr) == 0)
                {
                    xindex = j;
                }
            }
            List <String[]> data = new List <String[]>();

            data = reader.getData(xindex, 0, file, ',', hastime);
            if (numpredict < 1)
            {
                numpredict = (int)(data.Count * numpredict);
            }
            if (inmodel < 1)
            {
                inmodel = (int)(data.Count * inmodel);
            }
            int trainnum = (int)inmodel;

            Console.WriteLine("Model will contain " + trainnum.ToString() + " events.");
            List <double>     predicted = new List <double>();
            TimeSeriesWrapper ts        = new TimeSeriesWrapper();

            DataObject[] series = new DataObject[1];
            if (reverse)
            {
                data.Reverse();
                series = ts.getSeries(data, trainnum, change);
            }
            else
            {
                series = ts.getSeries(data, trainnum, change);
            }
            ARMAModel model = ts.beginARMAProcess(series, siglevel, -1, log: log);

            DataObject[]    Y           = series;
            List <DateTime> futureTimes = new List <DateTime>();
            int             totaldata   = trainnum + (int)numpredict;
            DateTime        last        = ((TimeSeries)model.TheData).GetLastTime();

            Console.WriteLine(last.ToString());
            DataObject[] yactual = ts.getSeries(data, (int)numpredict, change, start: trainnum);
            for (int t = 0; t < yactual.Length; ++t)
            {
                futureTimes.Add(yactual[t].Date);
            }
            var mergedtimeseries = ts.predictARMA(futureTimes, model);

            double[] errresults = TimeSeriesWrapper.evaluatePrediction(mergedtimeseries, yactual, futureTimes, outfile, trainnum);
            Console.WriteLine("Mean absolute error (MAE): " + errresults[0].ToString());
            Console.WriteLine("Root mean squared error (RMSE): " + errresults[1].ToString());
            Console.WriteLine("Mean absolute percentage error (MAPE): " + errresults[2].ToString());
        }