This module contains the statistical forecasting initiation and management.
The base class for all forecastings is StatisticalForecast , to generate forecasts one of the following subclasses has to be used
|StatisticalForecast(env, input_data[, ...])||This is the abstract class for statistical forecasting.|
|DSHWForecast(env, input_data[, ...])||This forecast uses the double seasonal exponential smoothing method.|
|DayTypeForecast(env, input_data[, ...])||This forecast splits the demands into 7 weekdays and minimizes and forecasts each with the holt-winters multiplicative method.|
- class StatisticalForecast(env, input_data, samples_per_hour=1, start=None, try_cache=True, **kwargs)¶
This is the abstract class for statistical forecasting. Statistical forecasts use exponential smoothing methods to forecast timeseries into the future. These methods rely on the right parameters to make a realistic forecast. The parameters can be passed to the function, if they are omitted they are found by minimizing the MSE.
Forecastings are calculated after contruction of class and then whenever needed, which is set by forecast_update_interval.
- input_data (list) – list of consecutive values sampled in samples_per_hour
- start (datetime) – start date of input data
- samples_per_hour (int) – Number of samples per hour in input_data
- try_cache (boolean) – Read and Save forecasts to a cache on the file device to avoid unneccesary recomputation, is True by default.
- **kwargs – Any instance variable can be overwritten with a keyword from here, f.e. input_weeks = 14. Will be set before any data is processed. Only use, if you know what your doing.
- forecast_update_interval (int) – The time in seconds for how long forecasts stay valid. When this interval is passed, a new forecast is calculated.
- input_weeks (int) – only forecast with this many weeks of data, default are 12 weeks.
- output_weeks (int) – the forecast will cover this many weeks of future data,default are 8 weeks.
- demands ([,]) – the processed demands, depending on subclass this contains one or more series
Return the forecast at the (unix) timestamp.
Raise a IndexError if there is no forecast for the timestamp.
- process_inputdata(data, samples_per_hour, start)¶
Preprocess and return the input demands. Needed for the division into weekdays in DayTypeForecast.
Parameters: start (datetime) – the time of the first datapoint. Only the day is of interest.
Forecast and return the demands. The forecasting method depends on the subclass.
- append_values(data, start_date=None)¶
Pushes in new values and cuts off values at the beginning to keep input length. Will update the forecasts if needed.
- classmethod make_hourly(data, samples_per_hour)¶
aggregates data series to 1hourly data.
- data (list) – the series
- samples_per_hour (int) – number of samples per hour contained in data
list of 1hourly data
- classmethod MASE(training_series, testing_series, prediction_series)¶
Computes the MEAN-ABSOLUTE SCALED ERROR forecast error for univariate time series prediction.
See “Another look at measures of forecast accuracy”, Rob J Hyndman
- training_series (list) – the series used to train the model
- testing_series (list) – the test series to predict
- prediction_series (list) – the prediction of testing_series (same size as testing_series)
Internal Method Update the forecasts, if env.now is more than forecast_update_interval seconds ahead from last demand measurement
Internal Method Return a cached result. If try_cache = True, this will try to read from cache/cached_forecasts.cache. The results are only returned, if the timestamp of the forecast creation is not older than 24h. Else or if no cached file is available, None is returned.
Returns: list or None
- class DSHWForecast(env, input_data, samples_per_hour=1, start=None, try_cache=True, **kwargs)¶
This forecast uses the double seasonal exponential smoothing method. It often delivers better results than the DayTypeForecast.
- class DayTypeForecast(env, input_data, samples_per_hour=1, start=None, try_cache=True, **kwargs)¶
This forecast splits the demands into 7 weekdays and minimizes and forecasts each with the holt-winters multiplicative method.
See StatisticalForecast.forecast_demands(). This method uses processes, to speed up the calculation. This drives the cpu to full load for a short time.