I'm encountering some unexpected behavior when using rsquare() from the output of of crossv_loo(), but behavior is as expected with crossv_kfold(). All r-squared values are NA from leave-one-out, but are appropriate doubles from k-fold.
Reprex as follows -
library(modelr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(purrr)
my_iris_model <- function(input_data){
lm(Sepal.Length ~ ., data = input_data)
}
### WORKS
crossv_kfold(iris, k = 3) %>%
mutate(fitted_model = map(train, my_iris_model )) %>%
mutate(rsquare = map2_dbl(fitted_model, test, modelr::rsquare))
#> Warning: `as_data_frame()` is deprecated as of tibble 2.0.0.
#> Please use `as_tibble()` instead.
#> The signature and semantics have changed, see `?as_tibble`.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> # A tibble: 3 x 5
#> train test .id fitted_model rsquare
#> <named list> <named list> <chr> <named list> <dbl>
#> 1 <resample> <resample> 1 <lm> 0.867
#> 2 <resample> <resample> 2 <lm> 0.855
#> 3 <resample> <resample> 3 <lm> 0.838
### NA
crossv_loo(iris) %>%
mutate(fitted_model = map(train, my_iris_model )) %>%
mutate(rsquare = map2_dbl(fitted_model, test, modelr::rsquare))
#> # A tibble: 150 x 5
#> train test .id fitted_model rsquare
#> <named list> <named list> <int> <named list> <dbl>
#> 1 <resample> <resample> 1 <lm> NA
#> 2 <resample> <resample> 2 <lm> NA
#> 3 <resample> <resample> 3 <lm> NA
#> 4 <resample> <resample> 4 <lm> NA
#> 5 <resample> <resample> 5 <lm> NA
#> 6 <resample> <resample> 6 <lm> NA
#> 7 <resample> <resample> 7 <lm> NA
#> 8 <resample> <resample> 8 <lm> NA
#> 9 <resample> <resample> 9 <lm> NA
#> 10 <resample> <resample> 10 <lm> NA
#> # … with 140 more rows
Thanks for any insights or, if necessary, bug fixes..
Hi
modelr
team,I'm encountering some unexpected behavior when using
rsquare()
from the output of ofcrossv_loo()
, but behavior is as expected withcrossv_kfold()
. All r-squared values are NA from leave-one-out, but are appropriate doubles from k-fold.Reprex as follows -
Thanks for any insights or, if necessary, bug fixes..
Best, Stephanie
PS as needed,