1

In fable's ARIMA function, we have the option to see all models that are evaluated with the trace = TRUE option. (Example below.) This output just prints to the console.

Is there any place that this model evaluation history is getting saved or is there any way to save the printed console output?

library(dplyr)
library(fable)
library(tsibble)
library(tsibbledata)

df <- aus_livestock |> 
    filter(Animal == 'Pigs', State == 'Queensland')

fcst <- df |>
    model(arima = ARIMA(Count, trace = TRUE))

# Prints all models tried, but only saves final selected model:
# Model specification       Selection metric
# ARIMA(2,1,2)(1,0,1)[12]+c Inf
# ARIMA(0,1,0)(0,0,0)[12]+c 21811.280078
# ARIMA(1,1,0)(1,0,0)[12]+c 21524.227259
# ARIMA(0,1,1)(0,0,1)[12]+c 21470.955343
# Search iteration complete: Current best fit is  0 1 1 0 0 1 1 
# ARIMA(0,1,1)(0,0,0)[12]+c 21562.904816
# ARIMA(0,1,0)(0,0,1)[12]+c 21710.467789
# ARIMA(0,1,1)(0,0,1)[12]   21469.103988
# Search iteration complete: Current best fit is  0 1 1 0 0 1 0 
# ...
# ...
# ...
bbgatch
  • 61
  • 5
  • One option would be to use `capture <- capture.output(fcst <- df |> model(arima = ARIMA(Count, trace = TRUE)))` from https://stackoverflow.com/questions/48118977/capture-the-printed-output-from-a-function-but-still-return-its-value-in-r. But then you would have to parse through the text output. – bbgatch Dec 04 '21 at 15:57
  • Why not just write it to a `file` with `capture.output` i.e. `capture.output(fcst <- df |> model(arima = ARIMA(Count, trace = TRUE)), file = file.path(getwd(), 'arimaout.text'))` and then go over the output – akrun Dec 04 '21 at 18:03

1 Answers1

1

There are some options to read the output

  1. Write the output of capture.output to a file
capture.output(fcst <- df |>
        model(arima = ARIMA(Count, trace = TRUE)), 
       file = file.path(getwd(),  'arimaout.text'))
  1. May also use a package (logger) to write it to a log file
library(logger)
log_formatter(formatter_glue)
 t <- tempfile()
 log_appender(appender_file(t))
 log_info('{capture.output(fcst <- df |> model(arima = ARIMA(Count, trace = TRUE)))}') 
 log_appender()

-read the log file

readLines(t) |> 
     head()
[1] "INFO [2021-12-04 12:20:58] Model specification\t\tSelection metric"                       
[2] "INFO [2021-12-04 12:20:58] ARIMA(2,1,2)(1,0,1)[12]+c\tInf"                                
[3] "INFO [2021-12-04 12:20:58] ARIMA(0,1,0)(0,0,0)[12]+c\t21811.280078"                       
[4] "INFO [2021-12-04 12:20:58] ARIMA(1,1,0)(1,0,0)[12]+c\t21524.227259"                       
[5] "INFO [2021-12-04 12:20:58] ARIMA(0,1,1)(0,0,1)[12]+c\t21470.955343"                       
[6] "INFO [2021-12-04 12:20:58] Search iteration complete: Current best fit is  0 1 1 0 0 1 1 "

unlink if temporary file

unlink(t)
akrun
  • 874,273
  • 37
  • 540
  • 662