I am trying to develop an application in such a way that the end user uploads the test data and he can model it with a click of a action button.
Behind the action button, I would like to have my steps on preprocessing the data, like imputing the missing values, changing the data type, and predicting the test result.
I have already created an UI and server based code , for uploading the file from external environment.
I am struck how I could integrate it to my R model with these procedures.
Below is my R code and Server code I have tried so far.
Server code:
shinyServer(function(input,output){
# file$datapath -> gives the path of the file
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
})
output$filedf <- renderTable({
if(is.null(data())){return ()}
input$file
})
output$sum <- renderTable({
if(is.null(data())){return ()}
summary(data())
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$tb <- renderUI({
if(is.null(data()))
h5("Powered by", tags$img(src='RStudio-Ball.png', heigth=200, width=200))
else
tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
})
and my R codes that i have done so far for imputation and random forest.
claim[,c(2:12,16:22,25,30,31,33,32,34)] <- lapply(claim[,c(2:12,16:22,25,30,31,33,32,34)], as.numeric)
claim[,c(1, 13:15)] <- lapply(claim[,c(1, 13:15)], as.Date, format = "%d.%m.%Y")
Missing value imputation
mice_impute = mice(New,m=5, method='rf')
Imputed_data <- mice::complete(mice_impute, 3)
Random Forest Model.
Imputed_data$claim.Qty.Accepted <- factor(Imputed_data$claim.Qty.Accepted, exclude = "")
summary(Imputed_data$claim.Qty.Accepted)
train <- Imputed_data[1:3325,]
validate <- Imputed_data[3326:3801,]
test <- Imputed_data[3801:4750,]
names(original)
fit <- randomForest(claim.Qty.Accepted~., data=train, na.action=na.exclude)
print(fit)
p1 <- predict(fit, train)
caret::confusionMatrix(p1, train$claim.Qty.Accepted)
p2 <- predict(fit, validate)
caret::confusionMatrix(p2, validate$claim.Qty.Accepted)
p3 <- predict(fit, test)
caret::confusionMatrix(p3, test$claim.Qty.Accepted)
Step by step procedure that could guide me will also be helpful.