2016-11-25 4 views
2

R 엔진을 사용하여 예측 실험을 만듭니다. 내 데이터 소스 피벗, 따라서 행별로 전달해야합니다. 출력은 단일 행 예측과 잘 맞습니다. 그러나 여러 행을 채울 때 첫 번째 레코드에 대해서만 단일 행 출력을 제공합니다. 다음과 같이 내가 루프 내 결과를 시도하고Azure ML 배치 실행 - 단일 출력

:

# Map 1-based optional input ports to variables 
dataset1 <- maml.mapInputPort(1) # class: data.frame 

library(forecast) 
library(reshape) 
library(dplyr) 
library(zoo) 
#exclude non required columns 
my.ds <- dataset1[, -c(4,5,6)] 
# set the CIs we want to use here, so we can reuse this vector 
cis <- c(80, 95) 

for (i in 1:nrow(my.ds)) { 
my.start <- my.ds[i,c(3)] 
my.product <- my.ds[i, "Product"] 
my.location <- my.ds[i, "Location"] 
my.result <- melt(my.ds[i,], id = c("Product","Location")) 
my.ts <- ts(my.result$value, frequency=52, start=c(my.start,1)) 
# generate the forecast using those ci levels 
f <- forecast(na.interp(my.ts), h=52, level=cis) 
# make a data frame containing the forecast information, including the index 
z <- as.data.frame(cbind(seq(1:52), 
         f$mean, 
         Reduce(cbind, lapply(seq_along(cis), function(i) cbind(f$lower[,i], f$upper[,i]))))) 
# give the columns better names 
names(z) <- c("index", "mean", paste(rep(c("lower", "upper"), times = length(cis)), rep(cis, each = 2), sep = ".")) 
# manipulate the results as you describe 
zw <- z %>% 
# keep only the variable you want and its index 
mutate(sssf = upper.95 - mean) %>% 
select(index, mean, sssf) %>% 
# add product and location info 
mutate(product = my.product, 
     location = my.location) %>% 
# rearrange columns so it's easier to read 
select(product, location, index, mean, sssf) 
zw <- melt(zw, id.vars = c("product", "location", "index"), measure.vars = c("mean","sssf")) 
data.set <- cast(zw, product + location ~ index + variable, value = "value") 
# Select data.frame to be sent to the output Dataset port 
maml.mapOutputPort("data.set"); 
} 

이 내 실험의 디자인 : experiment

는 그리고 이것은 샘플 input는 모습입니다 같은 :

Sample input

실험에서 다운로드 한 Excel 테스트 통합 문서를 사용하여 테스트하고 있습니다. ite.

{ 
... 
ds <- cast(zw, product + location ~ index + variable, value = "value") 
data.set <- rbind(data.set, ds) 
} 
# Select data.frame to be sent to the output Dataset port 
maml.mapOutputPort("data.set"); 

I는 루프 밖에 다음 행과 출력을 병합한다 :

답변

1

는 I 문제를 파악.