R 输入为灰色的朴素贝叶斯

R 输入为灰色的朴素贝叶斯,r,input,shiny,predict,naivebayes,R,Input,Shiny,Predict,Naivebayes,我正在用NaiveBayes分类器制作一个闪亮的应用程序,但是当我执行它时,我有以下错误: [在此处输入图像描述][1] 代码是: library(shiny) library(shinydashboard) library(e1071) #Cargar datos d <- read.csv("C:/Users/jerez/OneDrive/Escritorio/UAL/NB.csv", sep = ";", header = TRUE) #da

我正在用NaiveBayes分类器制作一个闪亮的应用程序,但是当我执行它时,我有以下错误: [在此处输入图像描述][1]

代码是:

library(shiny)
library(shinydashboard)
library(e1071)

#Cargar datos
d <- read.csv("C:/Users/jerez/OneDrive/Escritorio/UAL/NB.csv", sep = ";", header = TRUE)
#data(datos)
daf <- as.data.frame(d)


# Define UI 
ui <- fluidPage(

    # Application title
    titlePanel("Clasificador Naive Bayes"),

    # Sidebar 
    sidebarPanel(
      h4("Clase"),
      selectInput(inputId = "clase",label = "Clase", multiple = FALSE, choices = daf$Tipo),
      h4("Atributos de los mensajes"),
      selectInput(inputId = "usuario", label = "Recibido de", multiple = FALSE, choices = daf$Usuario),
      selectInput(inputId = "fecha", label = "Mes de creacion", multiple = FALSE, choices =daf$Fecha)
        ),

        # Show a plot of the generated distribution
    mainPanel(
      p("Probabilidad a posteriori de que el mensaje sea clasificado del tipo seleccionado:"),
      verbatimTextOutput("prediccion"),
      br(),
      p("Clasificacion"),
      plotOutput("Grafico"),
      p("Looking for the problem:"),
      verbatimTextOutput("prueba")
    )
    
)

# Define server 
server <- function(input, output) {
    
    runMode <- reactive({naiveBayes(daf[input$clase] ~., data = d)}) 
    output$prueba <- renderPrint({naiveBayes( daf[input$clase]~., data = d)})
    
    output$Grafico <- renderPlot({
     
      dat <- daf[daf$Usuario == input$usuario & daf$Fecha == input$fecha, 3]
      mod <- runMode()
      grafbarr <- barplot(dat, beside = T, horiz = T, 
                          main = "Clasificacion del mensaje",
                          xlab = "tipo de mensaje",
                          ylab = "mensajes",
                          col = c("blue", "yellow"),
                          legend = c("Si pertenece a la categoria", "No pertenece a la categoria"))
    
    })
    
    output$prediccion <- renderPrint({
      mod1 <- runMode()
      prob <- predict(mod1, daf[daf$Tipo == input$clase & daf$Usuario == input$usuario & daf$Fecha == input$fecha, 1:3])
    })
}
库(闪亮)
图书馆(shinydashboard)
图书馆(e1071)
#卡加达托斯酒店

d我发现三个潜在问题

  • 在您的数据截图中,Usuario的首字母大写,但在子集中,您使用的是daf$Usuario,首字母小写-您能检查这是否正确吗

  • 以下行存在问题:


  • dat你好!谢谢你的回答:)我试图在Usuario和Fecha列中分类Tipo类的类型。例如,我选择Promotiones中的分类器,并根据Usuario和Fecha的值,得到promotion类型中的预测值是或否。我希望你能理解。再次感谢你的帮助!好的,让我看看我是否得到了:您想将usuario和fecha作为输入,并预测具有选定属性的元素是否具有选定的类?不确定该方法,但关于Shiny,我会说:>mod1 Argh,nevermind,我将其编辑到我的主要答案中。如果我这样做,我会得到以下错误“Warning:error in[.data.frame:undefined columns selected”,我不知道为什么:(
    mod
    
    dat <- daf[daf$usuario == input$Usuario & daf$Fecha == input$fecha,]