mitchelloharawild / fable.prophet

fable extension for the prophet forecasting procedure
https://pkg.mitchelloharawild.com/fable.prophet
55 stars 8 forks source link

origin must be supplied #16

Closed nergiszaim closed 4 years ago

nergiszaim commented 4 years ago

Monthly prophet model produces 'origin' must supplied when change points are inputted:


> x <- TSstudio::ts_to_prophet(AirPassengers)
> x1 <- x %>% dplyr::mutate(index = tsibble::yearmonth(ds)) %>% tsibble::as_tsibble(index = index) %>% dplyr::select(index, y)
> head(x1)
# A tsibble: 6 x 2 [1M]
     index     y
     <mth> <dbl>
1 1949 Jan   112
2 1949 Feb   118
3 1949 Mar   132
4 1949 Apr   129
5 1949 May   121
6 1949 Jun   135
> md <- x1 %>% model(mdl_prophet = fable.prophet::prophet(y ~ growth("linear", changepoints = 3) ))
Warning message:
1 error encountered for mdl_prophet
[1] 'origin' must be supplied
mitchelloharawild commented 4 years ago

Perhaps your looking for n_changepoints instead of changepoints? This confusing error is coming from the prophet package, so improving the error should happen there.

library(tsibble)
library(fable.prophet)
#> Loading required package: Rcpp
#> Loading required package: fabletools
x1 <- as_tsibble(AirPassengers)
md <- x1 %>% model(mdl_prophet = fable.prophet::prophet(value ~ growth("linear", n_changepoints = 3)))
#> Warning in .local(object, ...): non-zero return code in optimizing
#> Optimization terminated abnormally. Falling back to Newton optimizer.
md
#> # A mable: 1 x 1
#>   mdl_prophet
#>   <model>    
#> 1 <prophet>

Created on 2019-12-11 by the reprex package (v0.3.0)

nergiszaim commented 4 years ago

Seems like that is not the issue... As you can see the fit and residuals provide NA's

 md <- x1 %>% model(mdl_prophet = fable.prophet::prophet(value ~ growth("linear", n_changepoints = 3)))
Optimization terminated abnormally. Falling back to Newton optimizer.
Warning messages:
1: In .local(object, ...) : non-zero return code in optimizing
2: 1 error encountered for mdl_prophet
[1] c++ exception (unknown reason)

>     md %>%
        augment()
# A tsibble: 144 x 5 [1M]
# Key:       .model [1]
   .model         index value .fitted .resid
   <chr>          <mth> <dbl>   <dbl>  <dbl>
 1 mdl_prophet 1949 Jan   112      NA     NA
 2 mdl_prophet 1949 Feb   118      NA     NA
 3 mdl_prophet 1949 Mar   132      NA     NA
 4 mdl_prophet 1949 Apr   129      NA     NA
 5 mdl_prophet 1949 May   121      NA     NA
 6 mdl_prophet 1949 Jun   135      NA     NA
 7 mdl_prophet 1949 Jul   148      NA     NA
 8 mdl_prophet 1949 Aug   148      NA     NA
 9 mdl_prophet 1949 Sep   136      NA     NA
10 mdl_prophet 1949 Oct   119      NA     NA
11 mdl_prophet 1949 Nov   104      NA     NA
12 mdl_prophet 1949 Dec   118      NA     NA
13 mdl_prophet 1950 Jan   115      NA     NA
14 mdl_prophet 1950 Feb   126      NA     NA
15 mdl_prophet 1950 Mar   141      NA     NA
16 mdl_prophet 1950 Apr   135      NA     NA
17 mdl_prophet 1950 May   125      NA     NA
18 mdl_prophet 1950 Jun   149      NA     NA
19 mdl_prophet 1950 Jul   170      NA     NA
20 mdl_prophet 1950 Aug   170      NA     NA
21 mdl_prophet 1950 Sep   158      NA     NA
22 mdl_prophet 1950 Oct   133      NA     NA
23 mdl_prophet 1950 Nov   114      NA     NA
24 mdl_prophet 1950 Dec   140      NA     NA
25 mdl_prophet 1951 Jan   145      NA     NA
26 mdl_prophet 1951 Feb   150      NA     NA
mitchelloharawild commented 4 years ago

I am unable to reproduce this issue, could you provide your sessionInfo()?

library(tsibble)
library(fable.prophet)
#> Loading required package: Rcpp
#> Loading required package: fabletools
x1 <- as_tsibble(AirPassengers)
md <- x1 %>% model(mdl_prophet = fable.prophet::prophet(value ~ growth("linear", n_changepoints = 3)))
#> Warning in .local(object, ...): non-zero return code in optimizing
#> Optimization terminated abnormally. Falling back to Newton optimizer.
augment(md)
#> # A tsibble: 144 x 5 [1M]
#> # Key:       .model [1]
#>    .model         index value .fitted .resid
#>    <chr>          <mth> <dbl>   <dbl>  <dbl>
#>  1 mdl_prophet 1949 Jan   112    97.2 14.8  
#>  2 mdl_prophet 1949 Feb   118    99.7 18.3  
#>  3 mdl_prophet 1949 Mar   132   102.  30.0  
#>  4 mdl_prophet 1949 Apr   129   104.  24.5  
#>  5 mdl_prophet 1949 May   121   107.  14.1  
#>  6 mdl_prophet 1949 Jun   135   109.  25.6  
#>  7 mdl_prophet 1949 Jul   148   112.  36.1  
#>  8 mdl_prophet 1949 Aug   148   114.  33.6  
#>  9 mdl_prophet 1949 Sep   136   117.  19.1  
#> 10 mdl_prophet 1949 Oct   119   119.  -0.334
#> # … with 134 more rows

Created on 2019-12-12 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.1 (2019-07-05) #> os Ubuntu 18.04.3 LTS #> system x86_64, linux-gnu #> ui X11 #> language en_AU:en #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2019-12-12 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> anytime 0.3.6 2019-08-29 [1] CRAN (R 3.6.1) #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> callr 3.3.2 2019-09-22 [1] CRAN (R 3.6.1) #> cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.1) #> codetools 0.2-16 2018-12-24 [4] CRAN (R 3.5.2) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1) #> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.1) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1) #> dplyr 0.8.3 2019-07-04 [1] CRAN (R 3.6.1) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1) #> extraDistr 1.8.11 2019-06-10 [1] CRAN (R 3.6.1) #> fable.prophet * 0.1.0 2019-12-11 [1] local #> fabletools * 0.1.1 2019-09-16 [1] CRAN (R 3.6.1) #> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.1) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1) #> generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.1) #> ggplot2 3.2.1 2019-08-10 [1] CRAN (R 3.6.1) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1) #> gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.1) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.1) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.1) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.1) #> lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1) #> loo 2.1.0 2019-03-13 [1] CRAN (R 3.6.1) #> lubridate 1.7.4 2018-04-11 [1] CRAN (R 3.6.1) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1) #> matrixStats 0.55.0 2019-09-07 [1] CRAN (R 3.6.1) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.1) #> pillar 1.4.2 2019-06-29 [1] CRAN (R 3.6.1) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.1) #> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.1) #> prophet 0.5 2019-05-14 [1] CRAN (R 3.6.1) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.1) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp * 1.0.3 2019-11-08 [1] CRAN (R 3.6.1) #> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.1) #> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.1) #> rmarkdown 1.18 2019-11-27 [1] CRAN (R 3.6.1) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1) #> rstan 2.19.2 2019-07-09 [1] CRAN (R 3.6.1) #> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1) #> StanHeaders 2.19.0 2019-09-07 [1] CRAN (R 3.6.1) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.1) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1) #> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.1) #> tidyr 1.0.0 2019-09-11 [1] CRAN (R 3.6.1) #> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.1) #> tsibble * 0.8.5 2019-11-03 [1] CRAN (R 3.6.1) #> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.1) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.1) #> vctrs 0.2.0 2019-07-05 [1] CRAN (R 3.6.1) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.1) #> zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.1) #> #> [1] /home/mitchell/R/x86_64-pc-linux-gnu-library/3.6 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library ```
nergiszaim commented 4 years ago

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] prophet_0.5         rlang_0.4.2         lubridate_1.7.4     tsibbledata_0.1.0  
 [5] fable.prophet_0.1.0 Rcpp_1.0.3          dplyr_0.8.3         tsibble_0.8.5      
 [9] fable_0.1.0         fabletools_0.1.1   

loaded via a namespace (and not attached):
 [1] matrixStats_0.55.0 xts_0.11-2         httr_1.4.0         rprojroot_1.3-2    rstan_2.19.2      
 [6] tools_3.6.1        backports_1.1.5    utf8_1.1.4         R6_2.4.1           lazyeval_0.2.2    
[11] colorspace_1.4-1   withr_2.1.2        tidyselect_0.2.5   gridExtra_2.3      prettyunits_1.0.2 
[16] processx_3.4.1     curl_3.3           compiler_3.6.1     cli_2.0.0          users_0.0.0.9000  
[21] desc_1.2.0         plotly_4.9.0       labeling_0.3       scales_1.1.0       readr_1.3.1       
[26] callr_3.4.0        stringr_1.4.0      digest_0.6.23      StanHeaders_2.19.0 extraDistr_1.8.11 
[31] pkgconfig_2.0.3    htmltools_0.4.0    htmlwidgets_1.5.1  rstudioapi_0.10    shiny_1.3.2       
[36] farver_2.0.1       generics_0.0.2     zoo_1.8-6          jsonlite_1.6       crosstalk_1.0.0   
[41] inline_0.3.15      magrittr_1.5       loo_2.1.0          munsell_0.5.0      fansi_0.4.0       
[46] lifecycle_0.1.0    stringi_1.4.3      yaml_2.2.0         pkgbuild_1.0.6     plyr_1.8.5        
[51] grid_3.6.1         parallel_3.6.1     promises_1.0.1     crayon_1.3.4       lattice_0.20-38   
[56] hms_0.5.0          zeallot_0.1.0      anytime_0.3.6      ps_1.3.0           pillar_1.4.2      
[61] TSstudio_0.1.5     codetools_0.2-16   stats4_3.6.1       pkgload_1.0.2      glue_1.3.1        
[66] packrat_0.5.0      data.table_1.12.2  remotes_2.1.0      vctrs_0.2.0        httpuv_1.5.1      
[71] testthat_2.1.1     gtable_0.3.0       purrr_0.3.3        tidyr_1.0.0        assertthat_0.2.1  
[76] ggplot2_3.2.1      mime_0.7           xtable_1.8-4       later_0.8.0        viridisLite_0.3.0 
[81] tibble_2.1.3       ellipsis_0.3.0  
mitchelloharawild commented 4 years ago

This feels like an issue with prophet, could you try:

library(tsibble)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:tsibble':
#> 
#>     id
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
x1 <- as_tsibble(AirPassengers)
x2 <- rename(x1, ds = index, y = value)
mdl <- prophet::prophet(x2, n.changepoints = 3, yearly.seasonality = FALSE)
#> Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
#> Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
#> Warning in .local(object, ...): non-zero return code in optimizing
#> Optimization terminated abnormally. Falling back to Newton optimizer.
predict(mdl, x2)$yhat
#>   [1]  97.16361  99.68116 101.95508 104.47263 106.90897 109.42653 111.86287
#>   [8] 114.38042 116.89797 119.33431 121.85186 124.28820 126.80576 129.32331
#>  [15] 131.59723 134.11478 136.55112 139.06867 141.50501 144.02256 146.54012
#>  [22] 148.97646 151.49401 153.93035 156.44790 158.96545 161.23937 163.75692
#>  [29] 166.19326 168.71082 171.14716 173.66471 176.18226 178.61860 181.13615
#>  [36] 183.57250 186.09005 188.60760 190.96273 193.48269 195.92136 198.44132
#>  [43] 200.87999 203.39995 205.91991 208.35858 210.87854 213.31721 215.83717
#>  [50] 218.35713 220.63322 223.15318 225.59185 228.11181 230.55048 233.07044
#>  [57] 235.59040 238.02907 240.54903 242.98770 245.50766 248.02762 250.30371
#>  [64] 252.82367 255.26234 257.78230 260.22097 262.74093 265.26089 267.69956
#>  [71] 270.21952 272.65819 275.17815 277.69811 279.97420 282.49416 284.93283
#>  [78] 287.86383 290.70028 293.63128 296.56228 299.39873 302.32973 305.16618
#>  [85] 308.09718 311.02818 313.77008 316.70108 319.53753 322.46853 325.30498
#>  [92] 328.23598 331.16698 334.00343 336.93443 339.77088 342.70188 345.63288
#>  [99] 348.28023 351.21123 354.04768 356.97868 359.81513 362.74613 365.67713
#> [106] 368.51358 371.44458 374.28103 377.21203 380.14303 382.79038 385.72138
#> [113] 388.55783 391.48883 394.32528 397.25628 400.18728 403.02373 405.95473
#> [120] 408.79118 411.72218 414.65318 417.30053 420.23153 423.06798 425.99898
#> [127] 428.83543 431.76643 434.69743 437.53388 440.46488 443.30133 446.23233
#> [134] 449.16333 451.90523 454.83623 457.67268 460.60368 463.44013 466.37113
#> [141] 469.30212 472.13858 475.06957 477.90602

Created on 2019-12-16 by the reprex package (v0.2.1)

nergiszaim commented 4 years ago

yes... seems like it is...


> library(tsibble)
> library(dplyr)
> x1 <- as_tsibble(AirPassengers)
> x2 <- rename(x1, ds = index, y = value)
> mdl <- prophet::prophet(x2, n.changepoints = 3, yearly.seasonality = FALSE)
Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
Optimization terminated abnormally. Falling back to Newton optimizer.
Error in sampler$call_sampler(c(args, dotlist)) : 
  c++ exception (unknown reason)
In addition: Warning message:
In .local(object, ...) : non-zero return code in optimizing
> predict(mdl, x2)$yhat
Error in predict(mdl, x2) : object 'mdl' not found
> ```
mitchelloharawild commented 4 years ago

Okay, closing this one as it is not an issue with this package. You can open up another issue in the prophet repository and reference this one.