在fable的ARIMA函式中,我們可以選擇查看使用該trace = TRUE選項評估的所有模型。(下面的例子。)這個輸出只是列印到控制臺。
是否有任何地方可以保存此模型評估歷史記錄,或者有什么方法可以保存列印的控制臺輸出?
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
# ...
# ...
# ...
uj5u.com熱心網友回復:
有一些選項可以讀取輸出
- 將輸出寫入
capture.outputafile
capture.output(fcst <- df |>
model(arima = ARIMA(Count, trace = TRUE)),
file = file.path(getwd(), 'arimaout.text'))
- 也可以使用包 (
logger) 將其寫入日志檔案
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()
- 讀取日志檔案
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 如果臨時檔案
unlink(t)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/373008.html
上一篇:有沒有辦法上傳多個檔案,其中一個檔案包含他們在Shiny中的名字?
下一篇:R中的資料集操作
