dataset = read.csv('02_Boston_Regression.csv')
library(dplyr)
library(randomForest)
data_nomiss = dataset %>%
select( CRIM,ZN,INDUS,CHAS,NOX,RM,AGE,DIS,RAD,TAX,PTRATIO,B,LSTAT,MEDV) %>%
na.omit()
regressor_rf_t = randomForest(MEDV ~., data = data_nomiss, mtry = 6,
ntree = 755, nodesize = 9)
library(shiny)
library(shinythemes)
# Create the user interface (ui) where you will take the input and display the output
ui <- fluidPage(theme = shinytheme("cosmo"),
navbarPage(
"MEDV Prediction",
tabPanel("Navbar 1",
sidebarPanel(
tags$h3("Enter the details of the customer:"),
#radioButtons("CRIM", "CRIM: LESS THAN 0.5 PUT 0 OTHERWISE 1", choiceNames=c('1', '0'), choiceValues = c('1','0')),
selectInput("CRIM", "CRIM 0 - 0.5 ", c("0 - 0.5"=0,
"0.5 - 1"=1)),
#numericInput("Age", "Age Group 1 - 7", 1, min=1, max=7),
#sliderInput("ZN", "ZN 0-100", 1, 9, 1),
sliderInput('ZN','ZN', min = 0,max = 100,value = 50, step = 0.1),
sliderInput('INDUS','INDUS', min = 0, max = 30, value = 15, step = 0.01),
#sliderInput('CHAS','CHAS', min = 0, max = 1, value = 0.5, step = 0.0001),
selectInput("CHAS", "CHAS 0 - 0.5 ", c("0 - 0.5"=0,
"0.5 - 1"=1)),
sliderInput('NOX','NOX', min = 0, max = 10, value = 5, step = 0.0001),
sliderInput('RM','RM', min = 0, max = 100, value = 50, step = 0.00001),
sliderInput('AGE','AGE', min = 0, max = 100, value = 50, step = 0.001),
sliderInput('DIS','DIS', min = 0, max = 100, value = 50, step = 0.00001),
selectInput('RAD','RAD', c("1"=1,
"2"=2,
"3"=3,
"4"=4,
"5"=5,
"6"=6,
"7"=7,
"8"=8,
"24"=24,
"666"=666)),
sliderInput('TAX','TAX',min = 0, max = 1000, value = 500, step = 0.001),
sliderInput('PTRARIO','PTRARIO', min = 0, max = 25, value = 15, step = 0.001),
sliderInput('B','B', min = 0, max = 400, value = 200, step = 0.001),
sliderInput('LSTAT','LSTAT', min = 0, max = 40, value = 20, step = 0.0001),
#numericInput("Income", "Income Group 1 - 9", 1, min=1, max=9),
#numericInput("Tenure", "Tenure in No. of Years", 0),
actionButton("Predict", "Predict MEDV"),
HTML("<br> <br>"),
actionButton("ResetInputs", "Reset"),
), # sidebarPanel
mainPanel(
h1("Predicted Profit"),
h4("Using Random Forest"),
verbatimTextOutput("txtout"),
h4("The selected MEDV was"),
verbatimTextOutput("incoutput")
) # mainPanel
), # Navbar 1, tabPanel
tabPanel("Navbar 2", "This panel is left blank"),
tabPanel("Navbar 3", "This panel is left blank")
) # navbarPage
) # fluidPage
# Define server function
server <- function(input, output, session) {
data = reactive({
data.frame(CRIM = as.integer(input$CRIM),
ZN = as.numeric(input$ZN),
INDUS = input$INDUS,
CHAS = input$CHAS,
NOX = input$NOX,
RM = input$RM,
AGE = input$AGE,
DIS = input$DIS,
TAX = input$TAX,
PTRATIO = input$PTRARIO,
B = input$B,
RAD = input$RAD,
LSTAT = input$LSTAT,
)
})
observeEvent(input$Predict, {
output$txtout = renderText ({
predict(regressor_rf_t, data())
})
output$incoutput=renderText({
input$MEDV
})
})
observeEvent(input$ResetInputs, {
updateRadioButtons(session,"CRIM", selected='1')
updateRadioButtons(session,"CHAS", selected='1')
updateRadioButtons(session,"RAD", selected='1')
updateNumericInput(session, "ZN", value=1)
updateNumericInput(session, "INDUS", value=1)
updateNumericInput(session, "NOX", value=0)
updateNumericInput(session, "RM", value=0)
updateNumericInput(session, "AGE", value=0)
updateNumericInput(session, "DIS", value=0)
updateNumericInput(session, "TAX", value=0)
updateNumericInput(session, "PTRARIO", value=0)
updateNumericInput(session, "B", value=0)
updateNumericInput(session, "LSTAT", value=0)
output$txtout = renderText ({ })
})
}
# Create Shiny object
shinyApp(ui = ui, server = server)