简体   繁体   中英

Output Prediction Model from Execute R Script Module in Azure ML

I'm doing an experiment to predict energy demand using 3 types of machine learning method which is ANN-MLP, SVM RBF and k-NN. I'm utilizing the Execute R Script module to run the R code. My questions is how to output the executed model, so that the model can be used to predict in another dataset. Basically I have 2 datasets - June dataset and July dataset. The prediction model is created using June data set, and I wanted to test July dataset using the model.

predictor <- maml.mapInputPort(1) 
datafull <- maml.mapInputPort(2) 

library(caret)

#data splitting
datasplit <- createDataPartition(y = predictor$demand, p = 0.7, list = FALSE)
datatrain <- predictor[datasplit,] 
datatest <- predictor[-datasplit,] 

#repeated cv, 10 cross validation
ctrl <- trainControl(method="repeatedcv", repeats =5)
knnFit <- train(demand ~ ., data = datatrain, method = "knn", trControl = ctrl, preProcess = c("center", "scale"), tuneLength = 20)
knnFit
plot(knnFit)

#Prediction
datapredict <- predict(knnFit, predictor)

plot(datafull$cdate, datafull$demand, xlab = "Time", ylab = "Demand", col = "#0441d9")
lines(datafull$cdate, datafull$demand, xlab = "Time", ylab = "Demand", col = "#0441d9")
lines(datafull$cdate, datapredict, xlab = "Time", ylab = "Demand", col = "#cc0000")

Right now the code only output the original dataset with a new column consist of the predicted value.

datafull$data.predict <- datapredict 
str(datafull)

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

You can convert you experiment to a predictive experiment. Then the model is saved and you can use predictive experiement to have any data evaluated you want.

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