R блестящий показывает ошибку, когда я использую реактивный объект в функции прогнозирования - PullRequest
0 голосов
/ 28 февраля 2019

Я не могу найти, где это неправильно.Я думаю, что функция предсказания не работает должным образом, и она также показывает new_depression с соответствующими значениями, а затем в объекте ответов она показывает, что функции new_depression были указаны с типами, отличными от соответствия.Как это не работает, может быть, функция предиката не работает должным образом.Пожалуйста, помогите !!!

библиотека (блестящая)

    ui <- fluidPage(
      sidebarLayout(
        sidebarPanel( 
      radioButtons(inputId="first", label="a",  choices = list("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4),selected = 1),
                    radioButtons(inputId="second", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="third", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="fourth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="fifth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="sixth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="seventh", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="eighth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="ninth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="tenth", label="a", c("None" = 0,"Little" = 1,"Some" = 2,"Much" = 3,"Most" = 4)),
                    radioButtons(inputId="eleventh", label="a", c("Yes" = 1,"No" = 0)),
                    radioButtons(inputId="twelfth", label="a", c("Yes" = 1,"No" = 0)),
                    radioButtons(inputId="thirteenth", label="a", c("Yes" = 1,"No" = 0)),
                    radioButtons(inputId="fourteenth", label="a", c("Yes" = 1,"No" = 0)),
                    radioButtons(inputId="fifteenth", label="a", c("Yes" = 1,"No" = 0)),
                    radioButtons(inputId="sixteenth", label="a", c("Yes" = 1,"No" = 0)),
                    submitButton("Submit")),
      mainPanel(
                    tableOutput(outputId= "ans"),
                    uiOutput(outputId= "abc")

      ))
    )

    server <- function(input, output){ 

      new_depression <- reactive({ data.frame("ASadness"=input$first,
                                   "Loconcen"=input$second,
                                   "Asleep"=input$third,
                                   "Aappet"=input$fourth,
                                   "Loenergy"=input$fifth,
                                   "Foguilt"=input$sixth,
                                   "Asbehav"=input$seventh,
                                   "Sthough"=input$eighth,
                                   "Ppains"=input$ninth,
                                   "Eactivity"=input$tenth,
                                   "Wloss"=input$eleventh,
                                   "Ssupport"=input$twelfth,
                                   "Etdsthin"=input$thirteenth,
                                   "Dmaking"=input$fourteenth,
                                   "Fhopilln"=input$fifteenth,
                                   "Addiction"=input$sixteenth)
      })


        library(caret)
        depression_model <- read.csv("C:/Users/Project/web/depression_with_nd_p.csv" , header=TRUE , stringsAsFactors = F) 



        str(depression_model)
        head(depression_model )

        set.seed(3233)
        intrain <- createDataPartition(y = depression_model$Depression, p= 0.7, list = FALSE)
        training <- depression_model[intrain,]
        testing <- depression_model[-intrain,]

        dim(training)
        dim(testing)

        anyNA(depression_model)
        summary(depression_model)

        training[["Depression"]] = factor(training[["Depression"]])

        trctrl <- trainControl(method = "repeatedcv", number = 10, repeats = 3)
        set.seed(3233)

        svm_Linear <- train(Depression ~., data = training, method = "svmLinear",
                            trControl=trctrl,
                            preProcess = c("center", "scale"),
                            tuneLength = 10)

        svm_Linear
        summary(svm_Linear)

        test_pred <- predict(svm_Linear, newdata = testing)
        test_pred

        tab <- table(Predicted = test_pred, Actual = testing$Depression )
        tab

        1 - sum(diag(tab))/sum(tab)

        #I think the problem is here in new_depression
        answers <- reactive({
          predict(svm_Linear, newdata=new_depression())
        })

      #This works ok and it also shows the features of my dataset with the selected 
      #attributes I choose using radio buttons
      output$ans <- renderTable(new_depression())
      #Here it shows error that features of my dataset  were specified with 
      #different types from the fit
      output$abc <- renderUI({answers()})
    }


    shinyApp(ui, server)  

1 Ответ

0 голосов
/ 03 марта 2019

Я не думаю, что ваша проблема блестяще связана.Я получил эту ошибку при попытке запустить ваш код:

Warning: Error in : variables ‘ASadness’, ‘Loconcen’, ‘Asleep’, ‘Aappet’, ‘Loenergy’, ‘Foguilt’, ‘Asbehav’, ‘Sthough’, ‘Ppains’, ‘Eactivity’, ‘Wloss’, ‘Ssupport’, ‘Etdsthin’, ‘Dmaking’, ‘Fhopilln’, ‘Addiction’ were specified with different types from the fit

[Нет трассировки стека]

Это не похоже на блестящую ошибку.Я погуглил на эту ошибку, и вот первый результат поиска: Ошибка: переменные были указаны с разными типами от соответствия

В этом ответе кажется, что они утверждают, что использование "масштаба" может бытьвиновник.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...