GithubHelp home page GithubHelp logo

rstudio-conf-2020 / time-series-forecasting Goto Github PK

View Code? Open in Web Editor NEW
222.0 17.0 132.0 115.64 MB

License: Creative Commons Attribution Share Alike 4.0 International

TeX 16.06% R 83.37% Makefile 0.56%

time-series-forecasting's Introduction

Tidy Time Series and Forecasting in R

rstudio::conf 2020

by Rob J Hyndman

๐Ÿ—“๏ธ 27-28 January 2020 โฐ 09:00 - 17:00 ๐Ÿจ Imperial B (Ballroom Level) โœ๏ธ rstd.io/conf

๐Ÿ‘ช Community space


Overview

It is becoming increasingly common for organizations to collect huge amounts of data over time, and existing time series analysis tools are not always suitable to handle the scale, frequency and structure of the data collected. In this workshop, we will look at some new packages and methods that have been developed to handle the analysis of large collections of time series.

On day 1, we will look at the tsibble data structure for flexibly managing collections of related time series. We will look at how to do data wrangling, data visualizations and exploratory data analysis. We will explore feature-based methods to explore time series data in high dimensions. A similar feature-based approach can be used to identify anomalous time series within a collection of time series, or to cluster or classify time series. Primary packages for day 1 will be tsibble, lubridate and feasts (along with the tidyverse of course).

Day 2 will be about forecasting. We will look at some classical time series models and how they are automated in the fable package. We will look at creating ensemble forecasts and hybrid forecasts, as well as some new forecasting methods that have performed well in large-scale forecasting competitions. Finally, we will look at forecast reconciliation, allowing millions of time series to be forecast in a relatively short time while accounting for constraints on how the series are related.

Learning objectives

Attendees will learn:

  1. How to wrangle time series data with familiar tidy tools.
  2. How to compute time series features and visualize large collections of time series.
  3. How to select a good forecasting algorithm for your time series.
  4. How to ensure forecasts of a large collection of time series are coherent.

Is this course for me?

This course will be appropriate for you if you answer yes to these questions:

  1. Do you already use the tidyverse packages in R such as dplyr, tidyr, tibble and ggplot2?
  2. Do you need to analyse large collections of related time series?
  3. Would you like to learn how to use some new tidy tools for time series analysis including visualization, decomposition and forecasting?

Prework

Attendees are expected to have R and RStudio installed on their own computers, along with the following packages and their dependencies.

install.packages(c("tidyverse","fpp3","GGally","sugrrants"))

Schedule

Time Activity
09:00 - 10:30 Session 1
10:30 - 11:00 Coffee break
11:00 - 12:30 Session 2
12:30 - 13:30 Lunch break
13:30 - 15:00 Session 3
15:00 - 15:30 Coffee break
15:30 - 17:00 Session 4

Slides

Day 1

  1. Background
  2. Introduction to tsibbles
  3. Time series graphics
  4. Transformations
  5. Seasonality and trends
  6. Time series features

Day 2

  1. Introduction to forecasting
  2. Exponential smoothing
  3. ARIMA models
  4. Dynamic regression
  5. Hierarchical forecasting

Textbook

Instructor

Rob J Hyndman is Professor of Statistics and Head of the Department of Econometrics and Business Statistics at Monash University. From 2005 to 2018 he was Editor-in-Chief of the International Journal of Forecasting and a Director of the International Institute of Forecasters. Rob is the author of over 150 research papers and 5 books in statistical science. In 2007, he received the Moran medal from the Australian Academy of Science for his contributions to statistical research, especially in the area of statistical forecasting. For over 30 years, Rob has maintained an active consulting practice, assisting hundreds of companies and organizations around the world. He has won awards for his research, teaching, consulting and graduate supervision.

He has coauthored about 40 R packages, many of which are on CRAN. He is best known for the forecast package. This workshop will be based around a suite of new packages he has been developing to do time series analysis and forecasting using tidy principles.


This work is licensed under a Creative Commons Attribution 4.0 International License.

time-series-forecasting's People

Contributors

mine-cetinkaya-rundel avatar mitchelloharawild avatar robjhyndman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

time-series-forecasting's Issues

How to Forecast Daily time series data using R ?

I had data from 1st jan 2020 to 31st dec 2020. I have to forecast it for nextyear i.e, 1st jan 2021 to 31st dec 2021.
Using the ARIMA model for forecasting got forecasted points as below. But I would like to get the points corresponding to day as 1st jan 2021 not like 2021.0021 as shown below. And suggest any other best method to forecast daily data.

Input:

Date Data
1/1/2020 147066
1/2/2020 59850
1/3/2020 60166
1/4/2020 20273
1/5/2020 166577
1/6/2020 57629
1/7/2020 50974
1/8/2020 53122
1/9/2020 75639
1/10/2020 51705
1/11/2020 19389
1/12/2020 33566
1/13/2020 58759
1/14/2020 63462
1/15/2020 131582
1/16/2020 124749
1/17/2020 45090
1/18/2020 18678
1/19/2020 19167
1/20/2020 262251
1/21/2020 76637
1/22/2020 45754
1/23/2020 50580
1/24/2020 44655
1/25/2020 24645
1/26/2020 84294
1/27/2020 48365
1/28/2020 47998
1/29/2020 49123
1/30/2020 87312
1/31/2020 63287
2/1/2020 149463
2/2/2020 24460
2/3/2020 64500
2/4/2020 48250
2/5/2020 186274
2/6/2020 45210
2/7/2020 44898
2/8/2020 23836
2/9/2020 46089
2/10/2020 60875
2/11/2020 46063
2/12/2020 55578
2/13/2020 59496
2/14/2020 49173
2/15/2020 30474
2/16/2020 15472
2/17/2020 58502
2/18/2020 111990
2/19/2020 135940
2/20/2020 201198
2/21/2020 49497
2/22/2020 21158
2/23/2020 23555
2/24/2020 48559
2/25/2020 49984
2/26/2020 111560
2/27/2020 50044
2/28/2020 64995
2/29/2020 51083
3/1/2020 151229
3/2/2020 62876
3/3/2020 61260
3/4/2020 48123
3/5/2020 190471
3/6/2020 45043
3/7/2020 20795
3/8/2020 28315
3/9/2020 77523
3/10/2020 58159
3/11/2020 47395
3/12/2020 59635
3/13/2020 47636
3/14/2020 20240
3/15/2020 43008
3/16/2020 67633
3/17/2020 64285
3/18/2020 82462
3/19/2020 129412
3/20/2020 189083
3/21/2020 20762
3/22/2020 23342
3/23/2020 45992
3/24/2020 40555
3/25/2020 43409
3/26/2020 102471
3/27/2020 43446
3/28/2020 23211
3/29/2020 16727
3/30/2020 55652
3/31/2020 55557
4/1/2020 182078
4/2/2020 50299
4/3/2020 53609
4/4/2020 20900
4/5/2020 168210
4/6/2020 50997
4/7/2020 43996
4/8/2020 47673
4/9/2020 75915
4/10/2020 45595
4/11/2020 17621
4/12/2020 30657
4/13/2020 54110
4/14/2020 62350
4/15/2020 80868
4/16/2020 95267
4/17/2020 44600
4/18/2020 20156
4/19/2020 113512
4/20/2020 215589
4/21/2020 46804
4/22/2020 43131
4/23/2020 53192
4/24/2020 42365
4/25/2020 24650
4/26/2020 90092
4/27/2020 57752
4/28/2020 65542
4/29/2020 127334
4/30/2020 86453
5/1/2020 187090
5/2/2020 25120
5/3/2020 32763
5/4/2020 56475
5/5/2020 192286
5/6/2020 45438
5/7/2020 47892
5/8/2020 47976
5/9/2020 42368
5/10/2020 32087
5/11/2020 51726
5/12/2020 53068
5/13/2020 46524
5/14/2020 59868
5/15/2020 60363
5/16/2020 20488
5/17/2020 40129
5/18/2020 85703
5/19/2020 122119
5/20/2020 199290
5/21/2020 42773
5/22/2020 42679
5/23/2020 22750
5/24/2020 15560
5/25/2020 32606
5/26/2020 112392
5/27/2020 47409
5/28/2020 50319
5/29/2020 54198
5/30/2020 31921
5/31/2020 25705
6/1/2020 192401
6/2/2020 54330
6/3/2020 56471
6/4/2020 50622
6/5/2020 186657
6/6/2020 19821
6/7/2020 24441
6/8/2020 56974
6/9/2020 70455
6/10/2020 55864
6/11/2020 50829
6/12/2020 49864
6/13/2020 19208
6/14/2020 28567
6/15/2020 72854
6/16/2020 58871
6/17/2020 65268
6/18/2020 106794
6/19/2020 40660
6/20/2020 170340
6/21/2020 76242
6/22/2020 50996
6/23/2020 49036
6/24/2020 44413
6/25/2020 54892
6/26/2020 110668
6/27/2020 24229
6/28/2020 22396
6/29/2020 50783
6/30/2020 76521
7/1/2020 197520
7/2/2020 49662
7/3/2020 40002
7/4/2020 16597
7/5/2020 171065
7/6/2020 63412
7/7/2020 54906
7/8/2020 57113
7/9/2020 79646
7/10/2020 56296
7/11/2020 21419
7/12/2020 38419
7/13/2020 63717
7/14/2020 69842
7/15/2020 83631
7/16/2020 107375
7/17/2020 46591
7/18/2020 20410
7/19/2020 127204
7/20/2020 226128
7/21/2020 51765
7/22/2020 48971
7/23/2020 56225
7/24/2020 47348
7/25/2020 31648
7/26/2020 91207
7/27/2020 56451
7/28/2020 55893
7/29/2020 61156
7/30/2020 102587
7/31/2020 61780
8/1/2020 158647
8/2/2020 27953
8/3/2020 71816
8/4/2020 53988
8/5/2020 192018
8/6/2020 49887
8/7/2020 46367
8/8/2020 25461
8/9/2020 47538
8/10/2020 64670
8/11/2020 50160
8/12/2020 55324
8/13/2020 61299
8/14/2020 50716
8/15/2020 28399
8/16/2020 37757
8/17/2020 78375
8/18/2020 89222
8/19/2020 132254
8/20/2020 204333
8/21/2020 44620
8/22/2020 20828
8/23/2020 21579
8/24/2020 49954
8/25/2020 58065
8/26/2020 111042
8/27/2020 47203
8/28/2020 52111
8/29/2020 20283
8/30/2020 29826
8/31/2020 64518
9/1/2020 195437
9/2/2020 53588
9/3/2020 64077
9/4/2020 48060
9/5/2020 162385
9/6/2020 15730
9/7/2020 28289
9/8/2020 61829
9/9/2020 77105
9/10/2020 66984
9/11/2020 44326
9/12/2020 26914
9/13/2020 26905
9/14/2020 63628
9/15/2020 75224
9/16/2020 66779
9/17/2020 116278
9/18/2020 46236
9/19/2020 19777
9/20/2020 246273
9/21/2020 56409
9/22/2020 46335
9/23/2020 44553
9/24/2020 46273
9/25/2020 59703
9/26/2020 88080
9/27/2020 22401
9/28/2020 54964
9/29/2020 49632
9/30/2020 77797
10/1/2020 203090
10/2/2020 57524
10/3/2020 32400
10/4/2020 28623
10/5/2020 208642
10/6/2020 52883
10/7/2020 50603
10/8/2020 61617
10/9/2020 67601
10/10/2020 31550
10/11/2020 17141
10/12/2020 53051
10/13/2020 71005
10/14/2020 67803
10/15/2020 94461
10/16/2020 47068
10/17/2020 21273
10/18/2020 74941
10/19/2020 161766
10/20/2020 214441
10/21/2020 49944
10/22/2020 48876
10/23/2020 46241
10/24/2020 21420
10/25/2020 37258
10/26/2020 119099
10/27/2020 51471
10/28/2020 57383
10/29/2020 81282
10/30/2020 65851
10/31/2020 27832
11/1/2020 172870
11/2/2020 69680
11/3/2020 65131
11/4/2020 50743
11/5/2020 195423
11/6/2020 47931
11/7/2020 20411
11/8/2020 31166
11/9/2020 80681
11/10/2020 55975
11/11/2020 44767
11/12/2020 70740
11/13/2020 55214
11/14/2020 27041
11/15/2020 44829
11/16/2020 72506
11/17/2020 74123
11/18/2020 92028
11/19/2020 137294
11/20/2020 210740
11/21/2020 24551
11/22/2020 27608
11/23/2020 53779
11/24/2020 51280
11/25/2020 58860
11/26/2020 88730
11/27/2020 40049
11/28/2020 29224
11/29/2020 24123
11/30/2020 95647
12/1/2020 209962
12/2/2020 64368
12/3/2020 73783
12/4/2020 57757
12/5/2020 167630
12/6/2020 29977
12/7/2020 61988
12/8/2020 61860
12/9/2020 80764
12/10/2020 72496
12/11/2020 53194
12/12/2020 31865
12/13/2020 32981
12/14/2020 72064
12/15/2020 86977
12/16/2020 76722
12/17/2020 125206
12/18/2020 58990
12/19/2020 25574
12/20/2020 253838
12/21/2020 65194
12/22/2020 51897
12/23/2020 51495
12/24/2020 35467
12/25/2020 29471
12/26/2020 92382
12/27/2020 27307
12/28/2020 74560
12/29/2020 62177
12/30/2020 81735
12/31/2020 85819

I had took the above data as a dataframe and forecasted
model <- ts(df$data,start = c(2020,1),frequency = 365.25)
auto.arima(model)
forecast(auto.arima(model),h=60) # First forecasted for next 60 days

output:
Screenshot from 2021-06-07 11-57-19

Not compiling

Using CRAN version of tsibble and latest github versions of fable, feasts, fabletools.

Quitting from lines 196-205 (6-fable.Rmd) 
Error: No common type for `..1` <interval> and `..2` <double>.
<error/vctrs_error_incompatible_type>
No common type for `..1` <interval> and `..2` <double>.

Unnest of fable failed

Hi,

I tried to knit the rmd from the materials folder.
I encountered an error in "6-fable.Rmd" file on line 352.
To reproduce the error the reprex is below.

What concerns me is unnest() of a fable does not work anymore.
I tried to unnest the columns and it also failed.

library(tidyverse)
library(fpp3)
#> -- Attaching packages ----------------------------------------------------- fpp3 0.3 --
#> v lubridate   1.7.9     v feasts      0.1.4
#> v tsibble     0.9.2     v fable       0.2.1
#> v tsibbledata 0.2.0
#> -- Conflicts -------------------------------------------------------- fpp3_conflicts --
#> x lubridate::date()   masks base::date()
#> x dplyr::filter()     masks stats::filter()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag()        masks stats::lag()

brick_fit <-  aus_production %>%
  filter(!is.na(Bricks)) %>%
  model(
    `Seasonal_naive` = SNAIVE(Bricks),
    `Naive` = NAIVE(Bricks),
    Drift = RW(Bricks ~ drift()),
    Mean = MEAN(Bricks)
  )

brick_fit
#> # A mable: 1 x 4
#>   Seasonal_naive   Naive         Drift    Mean
#>          <model> <model>       <model> <model>
#> 1       <SNAIVE> <NAIVE> <RW w/ drift>  <MEAN>

brick_fc <- brick_fit %>%
  forecast(h = "5 years")

print(brick_fc, n = 4)
#> # A fable: 80 x 4 [1Q]
#> # Key:     .model [4]
#>   .model         Quarter       Bricks .mean
#>   <chr>            <qtr>       <dist> <dbl>
#> 1 Seasonal_naive 2005 Q3 N(428, 2336)   428
#> 2 Seasonal_naive 2005 Q4 N(397, 2336)   397
#> 3 Seasonal_naive 2006 Q1 N(355, 2336)   355
#> 4 Seasonal_naive 2006 Q2 N(435, 2336)   435
#> # ... with 76 more rows

brick_fc %>% hilo(level=c(50,75)) %>% unnest()
#> Warning: `cols` is now required when using unnest().
#> Please use `cols = c(Bricks, `50%`, `75%`)`
#> Error: Input must be list of vectors

Created on 2020-08-25 by the reprex package (v0.3.0)

Herman

Check slides

Please go through slides to check for errors, especially in R code.

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.