Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Fitted Values chart - how to get values?

Dima1
7 - Meteor

Hi All

 

Could you pls advise how to get fitted values based on prediction of arima/ets model for input data? I dont need prediction, but only fitted using model. Thanks!

 

image.png

 

 

20 REPLIES 20
NeilR
Alteryx Alumni (Retired)

The following seems to be working for me for the ETS tool:

  1. hook up an R tool to the O output anchor of the ETS tool
  2. paste in the following R code into the R tool
the.model <- read.Alteryx("#1")
mod.obj <- unserializeObject(as.character(the.model$Object[1]))
model.fitted <- fitted(mod.obj)
write.Alteryx(data.frame(Fitted=as.matrix(model.fitted)), 1)

 

krishnapandey
7 - Meteor

Hi Neil,

 

I am trying to use same code for getting fitted values for ARIMA model ARIMA(1,0,1)(1,0,1)12 but i am getting error "Error: R (95): Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
".  any thoughts?

 

Thanks,

Kris

NeilR
Alteryx Alumni (Retired)

It's working for me. What Alteryx version are you on? Can you include the workflow and data that's giving you the error?

krishnapandey
7 - Meteor

Thanks Neil! It is working for me now.

I was using version 11.3 and had problems, upgraded to 2018.2 and it is working. 

Thanks

cwkoops
8 - Asteroid

Hi,

 

I'm using the TS Factory tools to get predictions on groups of data.  I'm interested in the next forecasted point, as well as the fitted values - similar to the need in the original post.  I am leveraging the R code Neil provided, however it doesn't appear to be giving fitted values for anything beyond the first group.  What would needs to be added / changed with the R code so the fitted values are listed by group? See attached workflow.  Thanks!

NeilR
Alteryx Alumni (Retired)

@cwkoops could you attach a package (Options->Export Workflow) rather than a workflow? The TS Factory tools aren't getting included.

cwkoops
8 - Asteroid

Hi Neil,

 

I attached the .yxzp.  Below is an example of the desired output from the R tool, if I allow multiple groups to flow into the TS Factory tools.  Thanks for taking a look. 

 

 

DesiredOutput.png

NeilR
Alteryx Alumni (Retired)

The TS Model Factory tool outputs each group as a separate model object in a new row. The second line of the original R code is only pulling from row 1:

mod.obj <- unserializeObject(as.character(the.model$Object[1]))

Changing that 1 to a 2 gets you the second group. You'll likely want to iterate across each row (for loop or something along those lines) to get a more robust solution.

cwkoops
8 - Asteroid

Thanks Neil.  I was playing around with those values, but nothing was obvious to me.  This seems to work with the for loop you mentioned.  

 

the.model <- read.Alteryx("#1", mode = "data.frame")
for(i in 1:nrow(the.model)){
mod.obj <- unserializeObject(as.character(the.model$Object[i]))
model.fitted <- fitted(mod.obj)
write.Alteryx(data.frame(Fitted=as.matrix(model.fitted)), 1)
}

 

So now I have the correct # of rows, but the 2nd column with the group identifier would be nice, but possibly not necessary as I could just append it to the original input data stream...if the # of rows is the same.  Any thoughts there?  

 

Labels