Git Product home page Git Product logo

xavierkamp / tsforecastr Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 64.86 MB

R package consisting of functions and tools to facilitate the use of traditional time series and machine learning models to generate forecasts on univariate or multvariate data. Different backtesting scenarios are available to identify the best performing models.

License: GNU General Public License v3.0

R 100.00%
time-series-forecasting backtesting machine-learning univariate-data multivariate-data keras-lstm h2o-automl arima-model stl-model ets-model

tsforecastr's Introduction

lifecycle Travis build status Codecov test coverage

Time Series Forecasting

This project involves developing a forecasting engine which can apply traditional time series models (e.g. ARIMA, ETS, STL) and machine learning models (e.g. AutoML-h2o, LSTM-keras) on univariate and multivariate time series. The idea is to facilitate forecast accuracy testing of these methods using different backtesting approaches. The forecasting procedures are designed to handle different case studies such as demand forecasting, inventory projections and possibly financial forecasting. As the procedures are based on 'xts' data types, a variety of data frequencies (e.g. yearly, monthly, daily) can be tested.

All codes are written in R.

Acknowledgements

The main source of inspiration for this project is the TSstudio package which offers excellent powerful tools for dealing with time series data. However, at the time of this writing (January 2020), TSstudio does not provide a solution for testing newer types of machine learning algorithms such as the AutoML method from h2o or Long Short-term Memory Networks with keras. This project hopes to provide a possible solution to this interesting challenge and enable simple performance comparisons between traditional and machine learning models.

Getting Started

Prerequisites

Install R: https://cloud.r-project.org/

Install RStudio: https://rstudio.com/products/rstudio/download/

For Windows, also install Rtools: https://cran.r-project.org/bin/windows/Rtools/

Install

install.packages("devtools")
library("devtools")
devtools::install_github("xavierkamp/tsForecastR")

Note:

When installing this package, in order to use the LSTM model you will be required to have Python and Tensorflow (version <= 1.14) installed on your machine. Please note that currently the forecasting procedure does not support Tensorflow 2.0.

To check the tensorflow version:

tensorflow::tf_config()

To install tensorflow:

install.packages("tensorflow")
tensorflow::install_tensorflow(version = 1.14)

When installing packages, in order to successfully install or update packages, you may be required to restart the R session and repeat the installation process.

Dependencies

List of main dependencies:

  • bsts
  • doParallel
  • dplyr
  • foreach
  • forecast
  • h2o
  • imputeTS
  • lubridate
  • magrittr
  • parallel
  • plotly
  • purrr
  • stats
  • stringr
  • tibble
  • timeSeries
  • timetk
  • utils
  • xts
  • zoo

Optional dependencies:

  • keras
  • tensorflow
  • testthat
  • covr

Functions

Part 1: Statistical Models

generate_fc - Function which enables the user to select different forecasting models from traditional time series models (e.g. ARIMA, ETS, STL) to machine learning algorithms (e.g. LSTM, AutoML). Results can be stored either as a tsForecastR object (default) or in text files.

Example:

library(datasets)
library(tsForecastR)

fc <- generate_fc(AirPassengers, fc_horizon = 12,
                  model_names = c("ets", "snaive",
                                  "stl", "nnetar",
                                  "lstm_keras",
                                  "automl_h2o"))

For more details:

help(generate_fc)
?generate_fc

Similar functions:

  • generate_fc_arima
  • generate_fc_automl_h2o
  • generate_fc_bsts
  • generate_fc_ets
  • generate_fc_lstm_keras - (available only if tensorflow requirements are met)
  • generate_fc_nnetar
  • generate_fc_snaive
  • generate_fc_stl
  • generate_fc_tbats

Part 2: Analysis

save_as_df - Function which transforms a tsForecastR object or selected text files into a data.frame object which can then be integrated in user-defined analyses.

Example:

library(datasets)
library(tsForecastR)
# Generate forecasts on twelve periods
fc <- generate_fc(AirPassengers,
                  fc_horizon = 12)
df <- save_as_df(fc)
print(df)

Note:

The above listed functions are all based on a sequential processing approach. To enable parallel processing, please refer to the parTsForecastR package which is built on top of this package.

tsforecastr's People

Contributors

xavierkamp avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

zhnathaniellee

tsforecastr's Issues

Tensorflow 2.0 incompatibility in LSTM procedure

Command incompatible with tf2.0
image

Seed setting is important for reproducibility and GPU disabling. Parallel processing of time series requires to disable GPU and use only 1 CPU per time series processed.

Furthermore, the above command probably causes timeouts when the session cannot be properly initiated. An alternative must be found.

Appveyor Checks for Win OS keep failing

After having updated the Appveyor yml file, the server now is responsive and starts checks. However, it keeps failing because it cannot find the package dependencies.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.