Cat
09/03/2020
In order to classify different species of Iris, we have created a tool which takes the Petal length and width as inputs and will return the predicted species.
The model is was trained on 70% of the data, and tested on the remaining 30%. The next tab displays a chart of the data split by species type.
The server code for the app is detailed below
options(shiny.sanitize.errors = FALSE)
require(caret)
require(e1071)
shinyServer(function(input,output) {
output$modelPred <- reactive({
set.seed(13579)
data <- datasets::iris
trainFlag <- createDataPartition(y = iris$Species, p=0.7, list = FALSE)
train <- data[trainFlag,]
test <- data[-trainFlag,]
model <- train(Species ~ Petal.Width + Petal.Length,method = "rpart", data= train)
widthNew <- input$sliderWidth
lengthNew <- input$sliderLength
newData <- data.frame(widthNew,lengthNew)
names(newData) <- c("Petal.Width","Petal.Length")
predict(model,newData)
})
})The Shiny App can be found here https://caffles90.shinyapps.io/ShinyApp_DDP/
The user simply needs to input the Petal Length and Width using the sliders and click ‘Go!’ The predicted species will return on the main screen.