This repository is dedicated to the project of time series forecast, done in R langauge. The dataset used for the project is the Delhi daily climate data. Three modesl are used for forecasting, which are autoregressive–moving-average (ARMA), vector autoregression (VAR), and two neural network models, feedforward and long-short-term-memory.
To view this project, you can look at the HTML rendering of the Rmardkown file. However, since the project includes interactive plots, which are not presentable by clicking on the link, I suggest to clone the repository and then open the HTML file, with following command:
git clone [email protected]:berserkhmdvhb/WSSTATEC.git
The libraries required for this project is provided in the renv.lock
file. Either use renv when creating a project, or if you haven't, install the renv
library, load it, and then use the renv.lock
file (by copying it to project's directory) to install the requied packages. Please follow the following commands in the console:
install.packages("renv")
library(renv)
renv::restore()
For the LSTM model, as R doesn't have native tensorflow
and keras
libraries, a python virtual environment is connected to this project so as to use the LSTM model. To connect Rstudio to the virtual environment and incorporate required python libraries in the project, the manner partly explained in website of Tensorflow for R is followed. Some steps are missing website, so a comprehensive guideline is provided in the following:
- Install the tensorflow R package as follows:
install.packages("keras")
- Install
reticulate
library as follows:
install.packages("reticulate")
- Configure R with a Python installation it can use, like this:
library(reticulate)
path_to_python <- install_python()
virtualenv_create("r-reticulate", python = path_to_python)
Note that if you already have Python installed, you don’t need to call install_python()
and instead can just supply an absolute path to the Python executable.
So far the python virtual environment with the name r-reticulate
should have been created.
- Now we intend to install
keras
on the virtual environment.
library(keras)
install_keras(envname = "r-reticulate")
- Although by now the
r-reticulate
virtual environment contains the required python packages, yet the reticulate won't run Python from this environment and instead will load it from its default path defined in theRETICULATE_PYTHON
. The default path in Linux is/usr/bin/python3
. To overcome this, we should unset the variable.
Sys.unsetenv("RETICULATE_PYTHON")
use_virtualenv("~/.virtualenvs/r-reticulate")
- Now if we load the
keras
library, the Python packages are loaded from the virtual evnironment.