antoinecarme / pyaf

PyAF is an Open Source Python library for Automatic Time Series Forecasting built on top of popular pydata modules.
BSD 3-Clause "New" or "Revised" License
458 stars 73 forks source link

Bad plot for shaded area around prediction intervals in hourly data #216

Closed antoinecarme closed 2 years ago

antoinecarme commented 2 years ago

For an hourly dataset, the shaded area is not plotted correctly (should have been light blue).

Scripot : (same as demo.py with 'H' instead of 'D' for frequency)

import numpy as np
import pandas as pd

if __name__ == '__main__':
    # generate a hourly signal covering one year 2016 in a pandas dataframe
    N = 365
    np.random.seed(seed=1960)
    df_train = pd.DataFrame({"Date" : pd.date_range(start="2016-01-25", periods=N, freq='H'),
                             "Signal" : (np.arange(N)//40 + np.arange(N) % 21 + np.random.randn(N))})
    # print(df_train.head(N))

    import pyaf.ForecastEngine as autof
    # create a forecast engine. This is the main object handling all the operations
    lEngine = autof.cForecastEngine()

    # get the best time series model for predicting one week
    lEngine.train(iInputDS = df_train, iTime = 'Date', iSignal = 'Signal', iHorizon = 7);
    lEngine.getModelInfo() # => relative error 7% (MAPE)

    lEngine.standardPlots("outputs/bug_hourly_");

Plot :

image

antoinecarme commented 2 years ago

Fixed.

Culprit : https://github.com/antoinecarme/pyaf/blob/440d2059f4362d6d40f008a8d7a102d06d1b6c38/pyaf/TS/Plots.py#L130

Conversion to date format discards time (HH-MM-SS) data. Removed.

antoinecarme commented 2 years ago

New plot (after fix):

image