简体   繁体   中英

How can I export a Time Series model in R?

Is there a standard (or available) way to export a Time Series model in R? PMML would work, but when II try to use the pmml library, perhaps incorrectly, I get an error:

For example, my code looks similar to this:

require(fpp)
library(forecast)
library(pmml)
data <- ts(livestock, start = 1970, end = 2000,frequency=3)
model <- ses(data , h=10 )
export <- pmml(model)

And the error I get is:

Error in UseMethod("pmml") :   no applicable method for 'pmml' applied to an object of class "forecast"

Here is what I can tell:

When you use ses() , you're not creating a model; you're using a model to find a prediction (in particular, making a forecast via exponential smoothing for a time series). Your result is not a predictive model, but rather a particular prediction of a model for a particular data set. While I'm not that familiar with PMML, from what I can tell, it's not meant for the job you are trying to use it for.

If you want to export the time series and the result, I would say your best bet would be to just export a .csv file with the data; just about anything can read .csv 's. A ts object is nothing more than a glorified vector, so you can export the data and the times. Additionally, model is just a table with data. So try this:

write.csv(model, file="forecast.csv")

If you want to write the ts object, try one of the following:

write.csv(data, file="ts1.csv") # No dates for index
write.csv(cbind("time" = time(data), "val" = data), file = "ts2.csv") # Adds dates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM