df2 = df.copy() df2=df2.rename(columns={"sdttm": "Date"}) columns = '''Date,pefmax,so2,co,o3,no2,temperaturec,windspeedms,precipitationpercent,vaporpressurehpa, dewpointtemperaturec,airpressurehpa,sealevelpressurehpa,groundtemperaturec,tmax,amax,tmin''' #amin,pmin,tmaxlesstmin,amaxlessamin,pmaxlesspmin''' cs = [c.strip() for c in columns.split(',')] df2=df2[cs] #df2.dtypes # In[6]: import pyaf.ForecastEngine as autof lEngine = autof.cForecastEngine() lExogenousData = (df2 , cs[2:6]) df3=df2["Date,pefmax".split(',')].copy() # In[ ]: lEngine.train(df3, 'Date' , 'pefmax', 12 , lExogenousData); # In[7]: import pyaf.ForecastEngine as autof lEngine_Without_Exogenous = autof.cForecastEngine() lEngine_Without_Exogenous.train(df3 , 'Date' , 'pefmax', 7);
def buildModel(iParallel=True): import pandas as pd import numpy as np import pyaf.ForecastEngine as autof import pyaf.Bench.TS_datasets as tsds import logging import logging.config # logging.config.fileConfig('logging.conf') logging.basicConfig(level=logging.INFO) b1 = tsds.load_airline_passengers() df = b1.mPastData df.head() lEngine = autof.cForecastEngine() lEngine H = b1.mHorizon # lEngine.mOptions.enable_slow_mode(); lEngine.mOptions.mEnableSeasonals = True lEngine.mOptions.mEnableCycles = True lEngine.mOptions.mDebugPerformance = True lEngine.mOptions.mParallelMode = iParallel lEngine.mOptions.set_active_autoregressions(['MLP', 'LSTM']) # lEngine.mOptions.mMaxAROrder = 2; lEngine.train(df, b1.mTimeVar, b1.mSignalVar, H) lEngine2 = pickleModel(lModel) lEngine2.getModelInfo() print(lEngine2.mSignalDecomposition.mTrPerfDetails.head()) lEngine2.mSignalDecomposition.mBestModel.mTimeInfo.mResolution lEngine2.standrdPlots(name="outputs/rnn_my_airline_passengers") dfapp_in = df.copy() dfapp_in.tail() # H = 12 dfapp_out = lEngine2.forecast(dfapp_in, H) dfapp_out.tail(2 * H) print("Forecast Columns ", dfapp_out.columns) lForecastColumnName = b1.mSignalVar + '_Forecast' Forecast_DF = dfapp_out[[ b1.mTimeVar, b1.mSignalVar, lForecastColumnName, lForecastColumnName + '_Lower_Bound', lForecastColumnName + '_Upper_Bound' ]] print(Forecast_DF.info()) print("Forecasts\n", Forecast_DF.tail(2 * H)) print("\n\n<ModelInfo>") print(lEngine2.to_json()) print("</ModelInfo>\n\n") print("\n\n<Forecast>") print(Forecast_DF.tail(2 * H).to_json(date_format='iso')) print("</Forecast>\n\n")
return df1; b1 = tsds.load_ozone() df = b1.mPastData NH = 400 df1 = replicate(df, NH); df1.head() #df.tail(10) #df[:-10].tail() #df[:-10:-1] #df.describe() lEngine = autof.cForecastEngine() lEngine H = NH // 4; # lEngine.mOptions.enable_slow_mode(); lEngine.mOptions.mDebug = True; lEngine.mOptions.mDebugPerformance = True; lEngine.mOptions.mParallelMode = False lEngine.train(df1 , b1.mTimeVar , b1.mSignalVar, H); lEngine.getModelInfo(); print(lEngine.mSignalDecomposition.mTrPerfDetails.head()); lEngine.mSignalDecomposition.mBestModel.mTimeInfo.mResolution lEngine.standardPlots("outputs/my_long_ozone_series_");
def buildModel(iParallel=True): import pandas as pd import numpy as np import pyaf.ForecastEngine as autof import pyaf.Bench.TS_datasets as tsds import logging import logging.config # logging.config.fileConfig('logging.conf') logging.basicConfig(level=logging.INFO) # get_ipython().magic('matplotlib inline') b1 = tsds.load_ozone() df = b1.mPastData # df.tail(10) # df[:-10].tail() # df[:-10:-1] # df.describe() lEngine = autof.cForecastEngine() lEngine H = b1.mHorizon # lEngine.mOptions.enable_slow_mode(); lEngine.mOptions.mDebugPerformance = True lEngine.mOptions.mParallelMode = iParallel lEngine.mOptions.set_active_autoregressions(['MLP', 'LSTM']) lEngine.train(df, b1.mTimeVar, b1.mSignalVar, H) lEngine2 = pickleModel(lEngine) lEngine2.getModelInfo() print(lEngine2.mSignalDecomposition.mTrPerfDetails.head()) lEngine2.mSignalDecomposition.mBestModel.mTimeInfo.mResolution lEngine2.standrdPlots("outputs/my_rnn_ozone") dfapp_in = df.copy() dfapp_in.tail() # H = 12 dfapp_out = lEngine2.forecast(dfapp_in, H) # dfapp_out.to_csv("outputs/rnn_ozone_apply_out.csv") dfapp_out.tail(2 * H) print("Forecast Columns ", dfapp_out.columns) Forecast_DF = dfapp_out[[ b1.mTimeVar, b1.mSignalVar, b1.mSignalVar + '_Forecast' ]] print(Forecast_DF.info()) print("Forecasts\n", Forecast_DF.tail(H)) print("\n\n<ModelInfo>") print(lEngine2.to_json()) print("</ModelInfo>\n\n") print("\n\n<Forecast>") print(Forecast_DF.tail(2 * H).to_json(date_format='iso')) print("</Forecast>\n\n")