使用Shiny渲染confusionmatrix

时间:2016-06-10 17:03:05

标签: r shiny

获得3个预测模型并使用预测来使用每个模型预测来组成矩阵以填充列。

predictions.rda

target;ctree;gbm;svm

a;a;a;b

b;b;b;c

c;a;c;c

保存为 rda 文件,我尝试使用闪亮加载一些混淆矩阵。用户必须选择其中一个模型,页面必须从加载的模型矩阵中呈现输出。

ui.R

library(shiny)

shinyUI(fluidPage(

  titlePanel("MODELS"),

  sidebarLayout(
    sidebarPanel(

      selectInput(inputId = "model",
             label = "choose Model:",
            choices = c("Conditional Inference Tree" = "predictions$ctree",
                        "Gradient Boosting Machine" = "predictions$gbm",
                        "Suppor Vector Machine" = "predictions$svm"
                  ),
                  selected = "predictions$ctree")

       ),
    mainPanel(
      textOutput("matrix")
    )
  )
))

server.R

shinyServer(function(input, output) {

  require(caret)
  load(predictions.rda)

  output$matrix <- renderPrint({

# this line worked fine
# confusionMatrix(predictions$target,predictions$ctree)

#this line does not work
confusionMatrix(predictions$target,input$model)

  })

})

输出结果为:

  

错误:数据的级别不能超过参考值。

0 个答案:

没有答案