Package: ts-rnn
Time_Series_Prediction_RNNRequirementsts_rnn requires the following to run:Python3.7.3+InstallationFrom pipYou could install the latest version from PyPi:pipinstallts-rnnFrom GithubYou could install the latest version directly from Github:pipinstallhttps://github.com/LevPerla/Time_Series_Prediction_RNN/archive/master.zipFrom sourceDownload the source code by cloning the repository or by pressing'Download ZIP'on this page.Install by navigating to the proper directory and running:pythonsetup.pyinstallExampleExampleDocumentationThe full documentation haven't ready yet. I hope, it will show later.Getting startedTo import TS_RNN model runfromts_rnn.modelimportTS_RNNFirst of all, we need to set architecture of RNN in config in the way like this:rnn_arch={"layers":[["LSTM",{"units":64,"return_sequences":False,"kernel_initializer":"glorot_uniform","activation":"linear"}],["Dropout",{"rate":0.2}],["Dense",{"activation":"linear"}]]}WARNING:Last RNN block need to gave return_sequences: False, another - TrueTo set the architecture of RNN you can use some of this blocks:# LSTM block["LSTM",{Keraslayerparams}],["GRU",{Keraslayerparams}],["SimpleRNN",{Keraslayerparams}],["Bidirectional",{Keraslayerparams}],["Dropout",{Keraslayerparams}],["Dense",{Keraslayerparams}]TS_RNN class has 7 attributes:n_lags - length of the input vector;horizon - length of prediction horizon;rnn_arch - description of the model's parameters in Python dictionary format;strategy - prediction strategy: "Direct", "Recursive", "MiMo", "DirRec", "DirMo"tuner - tupe of Keras.tuner: "RandomSearch", "BayesianOptimization", "Hyperband"tuner_hp - keras_tuner.HyperParameters classn_step_out - length of the output vector (Need to define only for DirMo strategy);loss - Keras loss to train model;optimizer - Keras optimizer to train model.n_features - number of time series in the input (only for factors forecasting);save_dir - dir to save logsYou can set model this way:model=TS_RNN(rnn_arch=rnn_arch,# dict with model architecturen_lags=12,# length of the input vectorhorizon=TEST_LEN,# length of prediction horizonstrategy="MiMo",# Prediction strategy from "Direct", "Recursive", "MiMo", "DirRec", "DirMo"loss="mae",# Keras lossoptimizer="adam",# Keras optimizern_features=X_train.shape[1]# also you need to define this if use factors)TS_RNN supports 5 methods:fit - train the neural network;predict - predict by the neural network by input;forecast - predict by the neural network by last train values;summary - print NNs architecturesave - save model files to dictFITmy_callbacks=[callbacks.EarlyStopping(patience=30,monitor='val_loss')]model.fit(factors_train=factors_val,# pd.DataFrame with factors time seriestarget_train=target_val,# pd.DataFrame or pd.Series with target time seriesfactors_val=factors_val,# pd.DataFrame with factors time seriestarget_val=target_val,# pd.DataFrame or pd.Series with target time seriesepochs=100,# num epoch to trainbatch_size=12,# batch_sizecallbacks=my_callbacks,# Keras callbackssave_dir="../your_folder",# folder to image saveverbose=2)# verbosePREDICTpredicted=model.predict(factors=factors_to_pred,target=target_to_pred,prediction_len=len(y_test))FORECASTpredicted=model.forecast(prediction_len=HORIZON)SUMMARYmodel.summary()SAVEmodel.save(model_name='tsrnn_model',save_dir='path')Also you may load TS_RNN model from folderfromts_rnn.modelimportload_ts_rnnmodel=load_ts_rnn(os.path.join('path','tsrnn_model'))Simple example of usage:Info: For better performance use MinMaxScaler and Deseasonalizer before fittingfromsklearn.model_selectionimporttrain_test_splitfromts_rnn.modelimportTS_RNNimportpandasaspdHORIZON=12data_url="https://raw.githubusercontent.com/LevPerla/Time_Series_Prediction_RNN/master/data/series_g.csv"target=pd.read_csv(data_url,sep=";").series_gtarget_train,target_test=train_test_split(target,test_size=HORIZON,shuffle=False)model=TS_RNN(n_lags=12,horizon=HORIZON)model.fit(target_train=target_train,target_val=target_test,epochs=40,batch_size=12,verbose=1)model.summary()predicted=model.predict(target=target_train[-model.n_lags:],prediction_len=HORIZON)