-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type checks fail uninformatively when outcome has "label"
attribute
#1060
Comments
Ah, this was an interesting one. Thanks for the issue! I'm able to reproduce just passing a linear regression specification to library(tidyverse)
library(tidymodels)
library(WDI)
df_methane <-
WDI(indicator = "EN.ATM.METH.KT.CE",
extra = TRUE) %>%
as_tibble() %>%
janitor::clean_names() %>%
drop_na() %>%
rename(methane = en_atm_meth_kt_ce)
is.vector(df_methane$methane)
#> [1] FALSE It's not a vector because attr(df_methane$methane, "label")
#> [1] "Methane emissions (kt of CO2 equivalent)" Thus: df_mod <-
df_methane %>%
filter(region != "Aggregates",
income != "Not classified") %>%
mutate(latitude = latitude %>% as.numeric(),
longitude = longitude %>% as.numeric(),
income = income %>% as_factor(),
region = region %>% as_factor()) %>%
select(region, income, longitude,latitude, methane)
set.seed(12345)
df_split <- initial_split(df_mod,
prop = 0.8,
strata = "income")
df_train <- training(df_split)
df_test <- testing(df_split)
set.seed(12345)
df_fold <-
vfold_cv(df_train,
strata = income,
repeats = 5)
res <-
tune_grid(
linear_reg(),
methane ~ .,
df_fold
)
#> Warning: No tuning parameters have been detected, performance will be evaluated
#> using the resamples with no tuning. Did you want to [tune()] parameters?
#> → A | error: `y` should be one of the following classes: 'data.frame', 'matrix', 'factor', 'Surv'
#> There were issues with some computations A: x1 Your solution is to remove the label attribute: # remove the label attribute ---------------------------------------------
attr(df_methane$methane, "label") <- NULL
df_mod <-
df_methane %>%
filter(region != "Aggregates",
income != "Not classified") %>%
mutate(latitude = latitude %>% as.numeric(),
longitude = longitude %>% as.numeric(),
income = income %>% as_factor(),
region = region %>% as_factor()) %>%
select(region, income, longitude,latitude, methane)
set.seed(12345)
df_split <- initial_split(df_mod,
prop = 0.8,
strata = "income")
df_train <- training(df_split)
df_test <- testing(df_split)
set.seed(12345)
df_fold <-
vfold_cv(df_train,
strata = income,
repeats = 5)
res <-
tune_grid(
linear_reg(),
methane ~ .,
df_fold
)
#> Warning: No tuning parameters have been detected, performance will be evaluated
#> using the resamples with no tuning. Did you want to [tune()] parameters? Created on 2024-02-02 with reprex v2.1.0 I'm going to move this to parsnip, where the issue originates. |
"label"
attribute
The offending lines: Lines 414 to 417 in 8ccf1be
|
Here's a more minimal reprex: library(parsnip)
fit_xy(
linear_reg(),
data.frame(x = 1:5),
y = data.frame(structure(rnorm(5), label = "hi"))
)
#> Error in `inher()`:
#> ! `y` should be one of the following classes: 'data.frame', 'matrix', 'factor', 'Surv' Created on 2024-02-02 with reprex v2.1.0 |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
The text was updated successfully, but these errors were encountered: