Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export a Time Series model in R?

Tags:

r

pmml

Is there a standard (or available) way to export a Time Series model in R? PMML would work, but when I I 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"
like image 434
yoganathan k Avatar asked Mar 04 '15 05:03

yoganathan k


1 Answers

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
like image 184
cgmil Avatar answered Oct 01 '22 16:10

cgmil