Comparing Machine Learning Algorithms

Stephen Franklin
Developing Data Products, Coursera, 27-07-14

Comparing Machine Learning Algorithms

This interactive Shiny application compares two machine learning algorithms to predict species of irises (from the iris dataset). The data is divided into two sets, one for training the algorithm and the other for testing it. The algorithm is run reactively upon any change in the two user controls.

shiny screenshot

Code excerpt from ui.R

This code shows how to implement user interactivity.

sidebarPanel(
            sliderInput("train_percent",
                        "Training Percentage:",
                        min = 0.10, max = 0.90, 
                        value = 0.20, step = 0.10),
            br(),
            radioButtons("method", "Model method:",
                         c("CART" = "rpart",
                           "Random Forest" = "rf")
            )
)

Code excerpt from server.R

The code snippet run here shows the prediction table of species of irises. A classification tree (rpart) was trained (using caret) on the iris dataset and the test data was then predicted.

    ### A reactive expression executes when the inputs change.
    outs <- reactive({interact(input$train_percent, input$method)})
    output$table.out <- renderTable({outs()$out.table})
##             
## pred         setosa versicolor virginica
##   setosa         35          0         0
##   versicolor      0         35         5
##   virginica       0          0        30

The interact() function actually calls several other functions which ultimately output the table above. (The entire code won't fit on this slide, but it was processed by Rstudio when the slidify document was knitted!)

Here's the complete code.

Documentation and Expansion