I have the following code:
library(tidymodels)
library(tidyverse)
rps <- tribble( ~estado, ~comp_move, ~move,
"gana", "piedra", "papel",
"pierde", "papel", "piedra",
"pierde", "papel", "piedra",
"gana", "tijeras", "piedra",
"gana", "piedra", "papel",
"pierde", "tijeras", "papel",
"gana", "papel", "tijeras",
"gana", "piedra", "papel",
"pierde", "papel", "piedra",
"gana", "tijeras", "piedra",
"empate", "piedra", "piedra",
"pierde", "papel", "piedra",
"empate", "papel", "papel",
"gana", "tijeras", "piedra")
rps <- rps %>% mutate_if(is.character,factor)
rps.split <- initial_split(rps, prop = 0.75)
rps.rec <- recipe(estado ~ comp_move + move, rps) %>%
step_dummy(all_nominal(),-all_outcomes())
rps.rec.prep <- rps.rec %>% prep()
base.model <- rand_forest() %>%
set_engine("ranger") %>%
set_mode("classification")
last_fit(base.model, rps.rec, rps.split)
I have also tried to use workflows
wfl <- workflow() %>%
add_recipe(rps.rec) %>%
add_model(base.model)
last_fit(wfl, split = rps.split)
When using last_fit()
I get the following error:
`Error: `x` and `y` must have same types and lengths`
I have used kknn, decision_tree, random_forest and xgboost, all getting same erros. I am also getting the same error even when tuning parameters with tune_grid()
.
The thing is that when I use fit()
function everything works fine. I know it is because I am using the model wrong but, why am I getting that error? I am new to tidymodel package.
Thanks in advance.
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.15.5