sillasgonzaga / mafs

Multiple Automatic Forecast Selection
GNU General Public License v2.0
19 stars 5 forks source link

Eduardo Orlando #5

Closed EBOrlando closed 7 years ago

EBOrlando commented 7 years ago

Olá Sillas, conforme conversamos pelo LinkedIn segue código que estou executando e apresenta erro no momento de escolher qual o melhor modelo:

m4au<- read_delim("~/Sarima/m4au.csv",

visualização do dataframe

View (m4au)

convertendo o dataframe para série temporal

m4au <- ts(m4au[,2], start = c(2015,1), end = c(2017,5), frequency = 12) plot (m4au)

removendo possíveis linhas com valores NA

m4au <- na.omit(m4au)

carregando os principais pacotes

library(mafs) library(magrittr) library(forecast) library(ggplot2)

decompondo a série em: observado, tendencia, sazonalidade, aleatório

m4au %>% decompose %>% plot

ggmonthplot(m4au)

plot sazonal

ggseasonplot(m4au, year.labels = TRUE) + geom_point() + theme_bw()

selecionando qual melhor modelo de projeção considerando a medida MAPE como erro

output <- select_forecast(m4au, test_size = 6, horizon = 3, error = "MAPE")

estatisticas dos modelos

output$df_models

comparação do teste entre o observado e o forecastado com o best_forecast

output$df_comparison

projeção dada pelo best_forecast para o periodo h declarado

output$best_forecast

paramêtros com projeção do best_forecast

summary(output$best_forecast)

MEDINDO A MÉDIA DO ERRO REAL

x <- output$df_comparison

Calcular MAPE real

mape_real <- 100 * abs(x$forecasted - x$observed)/x$observed

mostrar mape mês a mês

mape_real mean(mape_real)

plot do gráfico com a projeção do tamanho do teste

gg_fit(m4au, 5, "tslm") + theme_bw() + theme(legend.position = "bottom")

sillasgonzaga commented 7 years ago

Eduardo, em qual linha o código retorna um erro?

EBOrlando commented 7 years ago

O erro ocorre ao chamar a função select_forecast

Em seg, 4 de set de 2017 às 21:51, Sillas Teixeira Gonzaga < notifications@github.com> escreveu:

Eduardo, em qual linha o código retorna um erro?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sillasgonzaga/mafs/issues/5#issuecomment-327044693, or mute the thread https://github.com/notifications/unsubscribe-auth/Aa0ros4u4NuarAoKNZPsq5RI16jlNI-Cks5sfJsXgaJpZM4PMPkW .

sillasgonzaga commented 7 years ago

Aqui rodou normalmente.:

m4au <- structure(c(6523, 6856, 7994, 7371, 7362, 6896, 6994, 6919, 6621, 6328, 5662, 5500, 6309, 5753, 5923, 5773, 5357, 5288, 5713, 5344, 5346, 5795, 5936, 5685, 9627, 8500, 9993, 10110, 10672, 11256, 12218), .Dim = c(31L, 1L), .Dimnames = list(NULL, "Volume"), .Tsp = c(2015, 2017.5, 12), class = "ts")

output <- select_forecast(m4au, test_size = 6, horizon = 3, error = "MAPE")
str(output)

Você poderia postar o output de devtools::session_info() depois de carregar o mafs?


> devtools::session_info()
Session info ----------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.1 (2017-06-30)
 system   x86_64, linux-gnu           
 ui       RStudio (1.0.143)           
 language (EN)                        
 collate  pt_BR.UTF-8                 
 tz       America/Sao_Paulo           
 date     2017-09-04                  

Packages --------------------------------------------------------------------------------------------------------------------------
 package        * version  date       source         
 base           * 3.4.1    2017-07-08 local          
 cmprsk           2.2-7    2014-06-17 CRAN (R 3.4.0) 
 codetools        0.2-15   2016-10-05 CRAN (R 3.3.1) 
 colorspace       1.3-2    2016-12-14 CRAN (R 3.4.0) 
 CombMSC          1.4.2    2012-10-29 CRAN (R 3.4.0) 
 compiler         3.4.1    2017-07-08 local          
 curl             2.8.1    2017-07-21 cran (@2.8.1)  
 datasets       * 3.4.1    2017-07-08 local          
 devtools         1.13.3   2017-08-02 cran (@1.13.3) 
 digest           0.6.12   2017-01-27 CRAN (R 3.4.0) 
 doParallel       1.0.10   2015-10-14 CRAN (R 3.4.0) 
 Epi              2.16     2017-06-30 CRAN (R 3.4.0) 
 etm              0.6-2    2014-12-09 CRAN (R 3.4.0) 
 foreach          1.4.3    2015-10-13 CRAN (R 3.4.0) 
 forecast         8.1      2017-06-17 CRAN (R 3.4.0) 
 forecastHybrid   1.0.8    2017-07-12 CRAN (R 3.4.0) 
 fracdiff         1.4-2    2012-12-02 CRAN (R 3.4.0) 
 ggplot2          2.2.1    2016-12-30 CRAN (R 3.4.0) 
 graphics       * 3.4.1    2017-07-08 local          
 grDevices      * 3.4.1    2017-07-08 local          
 grid             3.4.1    2017-07-08 local          
 gtable           0.2.0    2016-02-26 CRAN (R 3.4.0) 
 iterators        1.0.8    2015-10-13 CRAN (R 3.4.0) 
 lattice          0.20-35  2017-03-25 CRAN (R 3.3.3) 
 lazyeval         0.2.0    2016-06-12 CRAN (R 3.4.0) 
 lmtest           0.9-35   2017-02-11 CRAN (R 3.4.0) 
 mafs           * 0.0.2    2017-01-25 CRAN (R 3.4.0) 
 magrittr         1.5      2014-11-22 CRAN (R 3.4.0) 
 MASS             7.3-47   2017-04-21 CRAN (R 3.4.0) 
 Matrix           1.2-10   2017-04-28 CRAN (R 3.4.0) 
 memoise          1.1.0    2017-04-21 CRAN (R 3.4.0) 
 methods        * 3.4.1    2017-07-08 local          
 munsell          0.4.3    2016-02-13 CRAN (R 3.4.0) 
 nnet             7.3-12   2016-02-02 CRAN (R 3.4.0) 
 numDeriv         2016.8-1 2016-08-27 CRAN (R 3.4.0) 
 parallel         3.4.1    2017-07-08 local          
 plyr             1.8.4    2016-06-08 CRAN (R 3.4.0) 
 quadprog         1.5-5    2013-04-17 CRAN (R 3.4.0) 
 quantmod         0.4-10   2017-06-20 CRAN (R 3.4.0) 
 Rcpp             0.12.12  2017-07-15 cran (@0.12.12)
 rlang            0.1.2    2017-08-09 cran (@0.1.2)  
 rstudioapi       0.6      2016-06-27 CRAN (R 3.4.0) 
 scales           0.5.0    2017-08-24 cran (@0.5.0)  
 splines          3.4.1    2017-07-08 local          
 stats          * 3.4.1    2017-07-08 local          
 survival         2.41-3   2017-04-04 CRAN (R 3.4.0) 
 tibble           1.3.4    2017-08-22 cran (@1.3.4)  
 tictoc           1.0      2014-06-17 CRAN (R 3.4.0) 
 timeDate         3012.100 2015-01-23 CRAN (R 3.4.0) 
 tools            3.4.1    2017-07-08 local          
 tseries          0.10-42  2017-06-22 CRAN (R 3.4.0) 
 TTR              0.23-2   2017-07-11 CRAN (R 3.4.0) 
 utils          * 3.4.1    2017-07-08 local          
 withr            2.0.0    2017-07-28 cran (@2.0.0)  
 xts              0.10-0   2017-07-07 CRAN (R 3.4.0) 
 zoo              1.8-0    2017-04-12 CRAN (R 3.4.0) 

Adicionalmente, tente reinstalar o mafs.

EBOrlando commented 7 years ago

Segue:

Session info --------------------------------------------------------------- setting value
version R version 3.4.0 (2017-04-21) system x86_64, mingw32
ui RStudio (1.0.143)
language (EN)
collate Portuguese_Brazil.1252
tz America/Sao_Paulo
date 2017-09-05

Packages ------------------------------------------------------------------- package version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.1) base
3.4.0 2017-04-21 local
bindr 0.1 2016-11-13 CRAN (R 3.4.1) bindrcpp 0.2 2017-06-17 CRAN (R 3.4.1) cmprsk 2.2-7 2014-06-17 CRAN (R 3.4.1) codetools 0.2-15 2016-10-05 CRAN (R 3.4.0) colorspace 1.3-2 2016-12-14 CRAN (R 3.4.1) CombMSC 1.4.2 2012-10-29 CRAN (R 3.4.1) compiler 3.4.0 2017-04-21 local
curl 2.8.1 2017-07-21 CRAN (R 3.4.1) datasets 3.4.0 2017-04-21 local
devtools 1.13.3 2017-08-02 CRAN (R 3.4.1) digest 0.6.12 2017-01-27 CRAN (R 3.4.1) doParallel 1.0.10 2015-10-14 CRAN (R 3.4.1) dplyr 0.7.2 2017-07-20 CRAN (R 3.4.1) Epi 2.19 2017-08-09 CRAN (R 3.4.1) etm 0.6-2 2014-12-09 CRAN (R 3.4.1) foreach 1.4.3 2015-10-13 CRAN (R 3.4.1) forecast
8.1 2017-06-17 CRAN (R 3.4.1) forecastHybrid 1.1.9 2017-08-23 CRAN (R 3.4.1) fracdiff 1.4-2 2012-12-02 CRAN (R 3.4.1) ggplot2 2.2.1 2016-12-30 CRAN (R 3.4.1) ggseas 0.5.1 2016-10-12 CRAN (R 3.4.1) glue 1.1.1 2017-06-21 CRAN (R 3.4.1) graphics 3.4.0 2017-04-21 local
grDevices 3.4.0 2017-04-21 local
grid 3.4.0 2017-04-21 local
gtable 0.2.0 2016-02-26 CRAN (R 3.4.1) hms 0.3 2016-11-22 CRAN (R 3.4.1) iterators 1.0.8 2015-10-13 CRAN (R 3.4.1) labeling 0.3 2014-08-23 CRAN (R 3.4.1) lattice 0.20-35 2017-03-25 CRAN (R 3.4.0) lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.1) lmtest 0.9-35 2017-02-11 CRAN (R 3.4.1) mafs
0.0.2 2017-01-25 CRAN (R 3.4.1) magrittr 1.5 2014-11-22 CRAN (R 3.4.1) MASS 7.3-47 2017-02-26 CRAN (R 3.4.0) Matrix 1.2-9 2017-03-14 CRAN (R 3.4.0) memoise 1.1.0 2017-04-21 CRAN (R 3.4.1) methods 3.4.0 2017-04-21 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.1) nnet 7.3-12 2016-02-02 CRAN (R 3.4.0) numDeriv 2016.8-1 2016-08-27 CRAN (R 3.4.1) parallel 3.4.0 2017-04-21 local
pkgconfig 2.0.1 2017-03-21 CRAN (R 3.4.1) plyr 1.8.4 2016-06-08 CRAN (R 3.4.1) purrr 0.2.3 2017-08-02 CRAN (R 3.4.1) quadprog 1.5-5 2013-04-17 CRAN (R 3.4.1) quantmod 0.4-10 2017-06-20 CRAN (R 3.4.1) R6 2.2.2 2017-06-17 CRAN (R 3.4.1) Rcpp 0.12.12 2017-07-15 CRAN (R 3.4.1) readr 1.1.1 2017-05-16 CRAN (R 3.4.1) rlang 0.1.2 2017-08-09 CRAN (R 3.4.1) scales 0.5.0 2017-08-24 CRAN (R 3.4.1) seasonal 1.6.1 2017-05-02 CRAN (R 3.4.1) splines 3.4.0 2017-04-21 local
stats
3.4.0 2017-04-21 local
survival 2.41-3 2017-04-04 CRAN (R 3.4.0) tibble 1.3.4 2017-08-22 CRAN (R 3.4.1) tictoc 1.0 2014-06-17 CRAN (R 3.4.1) tidyr 0.7.0 2017-08-16 CRAN (R 3.4.1) tidyselect 0.1.1 2017-07-24 CRAN (R 3.4.1) timeDate 3012.100 2015-01-23 CRAN (R 3.4.1) tools 3.4.0 2017-04-21 local
tseries 0.10-42 2017-06-22 CRAN (R 3.4.1) TTR 0.23-2 2017-07-11 CRAN (R 3.4.1) utils * 3.4.0 2017-04-21 local
withr 2.0.0 2017-07-28 CRAN (R 3.4.1) x13binary 1.1.39-1 2017-05-04 CRAN (R 3.4.1) xts 0.10-0 2017-07-07 CRAN (R 3.4.1) zoo 1.8-0 2017-04-12 CRAN (R 3.4.1)

sillasgonzaga commented 7 years ago

A única diferença que eu vi foi na versão do pacote forecastHybrid, mas mesmo depois de eu ter atualizado o meu, a select_forecast() continua rodando sem problemas. Não sei dizer o que está acontecendo porque não consigo reproduzir seu erro.

EBOrlando commented 7 years ago

Tudo bem, sem problemas. Obrigado pela ajuda.

sillasgonzaga commented 7 years ago

Por nada! Se precisar de mais alguma coisa pode falar.