0

我是 R 新手。我正在使用 Azure 机器学习工作室来尝试根据历史兑换情况预测何时兑换优惠券或优惠(营销促销)。这是我的数据。

在此处输入图像描述

这是我的 R 脚本。

#ARIMA Seasonal / ARIMA non-seasonal 
install.packages("forecast")
library(forecast)
# Map 1-based optional input ports to variables

dataset1 <- maml.mapInputPort(1) # class: data.frame
dataset2 <- maml.mapInputPort(2) # class: data.frame

######dataset1$RedeemedOn <- as.POSIXlt(dataset1$RedeemedOn, format="%m/%d/%Y %I:%M:%S %p")
######dataset2$RedeemedOn <- as.POSIXlt(dataset2$RedeemedOn, format="%m/%d/%Y %I:%M:%S %p")

dataset1$RedeemedOn <- as.Date(dataset1$RedeemedOn,  # Character vector to convert
             format= "%y/%m/%d")   

dataset2$RedeemedOn <- as.Date(dataset2$RedeemedOn,  # Character vector to convert
             format= "%y/%m/%d")   

#Enter the seasonality of the timeseries here
#For non-seasonal model use '1' as the seasonality
seasonality<-12
labels <- as.numeric(dataset1$OfferId)
timeseries <- ts(labels,frequency=seasonality)
model <- auto.arima(timeseries)
numPeriodsToForecast <- ceiling(max(dataset2$RedeemedOn)) - ceiling(max(dataset1$RedeemedOn))
#numPeriodsToForecast <- ceiling(max(dataset2$hour)) - ceiling(max(dataset1$hour))
numPeriodsToForecast <- max(numPeriodsToForecast, 0)
forecastedData <- forecast(model, h=numPeriodsToForecast)
forecastedData <- as.numeric(forecastedData$mean)

output <- data.frame(RedeemedOn=dataset2$RedeemedOn,forecast=forecastedData)
data.set <- output

# Select data.frame to be sent to the output Dataset port
maml.mapOutputPort("data.set");

这是错误。

错误 0063:在评估 R 脚本期间发生以下错误: ---------- 从 R 开始的错误消息 ---------- 0(非 NA)案例

我是否正确地做到了这一点?这会根据之前的 RedeemedOn 日期和时间预测未来的优惠/优惠券兑换吗?

编辑 1

#ARIMA Seasonal / ARIMA non-seasonal 
install.packages("forecast")
library(forecast)
# Map 1-based optional input ports to variables

dataset1 <- maml.mapInputPort(1) # class: data.frame
dataset2 <- maml.mapInputPort(2) # class: data.frame

dataset1$RedeemedOn <- as.POSIXct(dataset1$RedeemedOn, format="%d/%m/%Y")
dataset2$RedeemedOn <- as.POSIXct(dataset2$RedeemedOn, format="%d/%m/%Y")
#dataset1$RedeemedOn <- as.POSIXct(dataset1$RedeemedOn, format="%d/%m/%Y %I:%M:%S %p")
#dataset2$RedeemedOn <- as.POSIXct(dataset2$RedeemedOn, format="%d/%m/%Y %I:%M:%S %p")



#####dataset1$RedeemedOn <- as.Date(dataset1$RedeemedOn,  # Character vector to convert
             #####format= "%y/%m/%d")   

#####dataset2$RedeemedOn <- as.Date(dataset2$RedeemedOn,  # Character vector to convert
             #####format= "%y/%m/%d")   

#Enter the seasonality of the timeseries here
#For non-seasonal model use '1' as the seasonality
seasonality<-12
labels <- as.numeric(dataset1$OfferId)
timeseries <- ts(labels,frequency=seasonality)
model <- auto.arima(timeseries)
numPeriodsToForecast <- ceiling(max(dataset2$RedeemedOn)) - ceiling(max(dataset1$RedeemedOn))
#numPeriodsToForecast <- ceiling(max(dataset2$hour)) - ceiling(max(dataset1$hour))
numPeriodsToForecast <- max(numPeriodsToForecast, 0)
forecastedData <- forecast(model, h=numPeriodsToForecast)
forecastedData <- as.numeric(forecastedData$mean)

#output <- data.frame(RedeemedOn=dataset2$RedeemedOn,forecast=forecastedData)
output <- data.frame(date=format(dataset2$RedeemedOn, "%d/%m/%y"),forecast=forecastedData)
data.set <- output

# Select data.frame to be sent to the output Dataset port
maml.mapOutputPort("data.set");

任何帮助深表感谢。谢谢!

4

0 回答 0