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.

1

There are 1 best solutions below

0
On

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)