2

I'm trying to run my Shiny App locally in RStudio but I always get this error message:

> shinyApp(ui, server)

Listening on http://127.0.0.1:5603
Error: sample_fraction too small, no observations sampled. Ranger will EXIT now.
Warning: Error in predict.ranger.forest: User interrupt or internal error.

The dataset I used for the model is not small (17k observations). I'm using Ranger engine for Random Forest and have followed Ranger's documentation by explicity adding sample.fraction's default of 1 for sampling with replacement and 0.632 for sampling without replacement but none of these 2 pairs of settings works. Higher value than 1 also results to error when tuning.

I'm not sure though whether I'm making these settings in the right place of my code below:

## Step 3: Fit (Choosing Algorithms) ====

RF <- 
  rand_forest() %>% 
  set_args(trees = tune(), 
           mtry = tune(),
           min_n = tune()
  ) %>% 
  set_engine("ranger",
             importance = "permutation",
             replace = TRUE,
             sample.fraction = 1) %>%  
  set_mode("regression") 

I've also tried using sample_fraction instead of sample.fraction but I still got the same error.

I would appreciate any guidance on where I might look next.

TomR
  • 81
  • 7
  • I would try to have it work outside of shiny, then integrate it in the dashboard – HubertL Dec 16 '22 at 00:29
  • If you mean bypass Shiny altogether, I can't. I have to make it work within Shiny as a requirement for my capstone project. – TomR Dec 16 '22 at 00:49
  • it's usually easier to proceed by small steps, just to know if the issue is caused by the processing part or the shiny part – HubertL Dec 16 '22 at 01:46
  • 1
    Thanks Hubert, you got me thinking. I was sure the it was predicting OK without Shiny so I broke down the server and ui functions and the root cause was a misspelled input feature name in the server function. Thanks for the suggestion. – TomR Dec 16 '22 at 14:59

1 Answers1

1

I finally found the issue by breaking down the Shiny codes from bare bones structure and rebuilt them piece by piece. The chunk that reproduced the error was input$kpi_ball_control which had a missing "l".

output$valuation_prediction <- 
    renderValueBox({
      
      prediction <- 
        #model %>% 
        predict(
          model,
          tibble(
            "age" = as.numeric(input$age),
            "height_cm" = as.numeric(input$height_cm),
            "weight_kg" = as.numeric(input$weight_kg),
            "wage_euro" = as.numeric(input$wage_euro),
            "preferred_foot" = as.factor(input$preferred_foot),
            "release_clause_euro" = as.numeric(input$release_clause_euro),
            "kpi_goal_scoring" = as.numeric(input$kpi_goal_scoring),
            "kpi_short_passing" = as.numeric(input$kpi_short_passing),
            "kpi_dribbling" = as.numeric(input$kpi_dribbling),
            "kpi_long_passing" = as.numeric(input$kpi_long_passing),
            "kpi_ball_control" = as.numeric(input$kpi_ball_control),  # <-- the culprit
            "kpi_sprint_speed" = as.numeric(input$kpi_sprint_speed),
            "kpi_stamina" = as.numeric(input$kpi_stamina),
            "kpi_composure" = as.numeric(input$kpi_composure)

      
TomR
  • 81
  • 7