Comments (4)
If you are using the dev version you need to set the bake_dependant_roles
argument in the recipes blueprint to make sure that the ID variables are passed through. https://hardhat.tidymodels.org/dev/reference/default_recipe_blueprint.html#arguments
with
id_blueprint <- hardhat::default_recipe_blueprint(bake_dependent_roles = "ID")
library(tidymodels)
library(survival)
colon$sex <- ifelse(colon$sex==1,"male","female")
colon$obstruct <- ifelse(colon$obstruct ==1,"yes","no")
colon$perfor <- ifelse(colon$perfor ==1,"yes","no")
colon$adhere <- ifelse(colon$adhere ==1,"yes","no")
colon$status <- ifelse(colon$status ==1,"death","alive")
colon$node4 <- ifelse(colon$node4 ==1,"yes","no")
colon <- select(colon,id,age,rx,sex,age,obstruct,perfor,adhere,nodes,status)
colon <- na.omit(colon)
data_split<- initial_split(colon,
prop = 3/4,
strata = status)
train_data <- training(data_split)
test_data<- testing(data_split)
train_rec <-
recipe(status ~., data = train_data) %>%
update_role(id, new_role = "ID")%>%
step_zv(all_numeric(),-all_outcomes()) %>%
step_normalize(all_numeric(),-all_outcomes())%>%
step_novel(all_nominal(),-all_outcomes()) %>%
step_dummy(all_nominal(),-all_outcomes())
set.seed(100)
cv_folds <-
vfold_cv(train_data,
v = 5,
strata = status)
log_spec <- # your model specification
logistic_reg() %>% # model type
set_engine(engine = "glm") %>% # model engine
set_mode("classification") # model mode
id_blueprint <- hardhat::default_recipe_blueprint(bake_dependent_roles = "ID")
log_wflow <- # new workflow object
workflow() %>% # use workflow function
add_recipe(train_rec, blueprint = id_blueprint) %>% # use the new recipe
add_model(log_spec) # add your model spec
log_res <-
log_wflow %>%
fit_resamples(
resamples = cv_folds,
metrics = metric_set(
precision, f_meas,
accuracy, kap,
roc_auc, sens, spec),
control = control_resamples(
save_pred = TRUE)
)
#> ! Fold1: preprocessor 1/1, model 1/1 (predictions): prediction from a rank-defici...
#> ! Fold2: preprocessor 1/1, model 1/1 (predictions): prediction from a rank-defici...
#> ! Fold3: preprocessor 1/1, model 1/1 (predictions): prediction from a rank-defici...
#> ! Fold4: preprocessor 1/1, model 1/1 (predictions): prediction from a rank-defici...
#> ! Fold5: preprocessor 1/1, model 1/1 (predictions): prediction from a rank-defici...
log_res %>%
collect_notes() %>%
pluck("note") %>%
cat(sep = "\n")
#> prediction from a rank-deficient fit may be misleading
#> prediction from a rank-deficient fit may be misleading
#> prediction from a rank-deficient fit may be misleading
#> prediction from a rank-deficient fit may be misleading
#> prediction from a rank-deficient fit may be misleading
Created on 2022-05-18 by the reprex package (v2.0.1)
from hardhat.
This is exactly as expected. This is how it should have worked from the beginning and is required for case weights to work. The only role that forge()
looks for by default is the "predictor"
role.
If you really require the "ID"
role in the recipe then you should use bake_dependent_roles
as Emil suggested.
But I think that the user doesn't actually want id
to be involved in the recipe at all, so they should have used all_numeric_predictors()
and all_nominal_predictors()
, like this:
train_rec <-
recipe(status ~., data = train_data) %>%
update_role(id, new_role = "ID")%>%
step_zv(all_numeric_predictors()) %>%
step_normalize(all_numeric_predictors())%>%
step_novel(all_nominal_predictors()) %>%
step_dummy(all_nominal_predictors())
Then it works as expected
from hardhat.
Yes, -all_outcomes()
is definitely an anti-pattern.
from hardhat.
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.
from hardhat.
Related Issues (20)
- Release hardhat 1.0.0 HOT 1
- Error in out$extras$final(predictors_extras, outcomes_extras): argument "outcomes_extras" is missing, with no default HOT 15
- Release hardhat 1.1.0 HOT 2
- get_outcome_levels blueprint method? HOT 5
- Post recipes 1.0.0 upkeep HOT 1
- Release hardhat 1.2.0 HOT 1
- Pass through strings_as_factors arg HOT 3
- Problem with predicting on new data for character column HOT 5
- Problem with a formula with spaces in the name of a factor and indicators = "none" HOT 2
- `mold()` inconsistently preserves (with XY method) or ignores (with formula method) non-base vector classes HOT 2
- Do a pass over `validate_is()` with an eye towards performance HOT 1
- Avoid `as_tibble()` where possible HOT 2
- multi-outcomes support for `spruce_prob_multi` shall clarify input format for multiple `pred_levels` HOT 2
- Upkeep for hardhat HOT 1
- Regression in development version of hardhat when using sf objects HOT 3
- Release hardhat 1.3.0 HOT 1
- Dynamically calculate weights HOT 5
- Using a division on the left-hand side of a formula throws an "Interaction terms can't be specified on the LHS of `formula`" HOT 2
- importance weights not compatible with DALEXtra::model_profile HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hardhat.