Caret 的 train.recipe 似乎没有应用配方程序来删除 NA,随后交叉验证失败

Caret's train.recipe seems to not apply recipe procedure to remove NAs and subsequently cross-validation fails

caret 包似乎没有应用配方程序来删除 NA 以进行交叉验证。我想我忽略了一些东西...

iris_dt <- as.data.table(iris)
iris_dt[3:5,':='(Petal.Length=NA)]
control <- trainControl(method='cv',number=2,allowParallel = T)
rec <- recipe(Petal.Length ~ Sepal.Width,iris_dt) %>% step_naomit(all_outcomes(),all_predictors())
train(rec,iris_dt,method='lm',trControl = control)

Error in quantile.default(y, probs = seq(0, 1, length = cuts)) : missing values and NaN's not allowed if 'na.rm' is FALSE

当回归量为 NA 时它也不起作用,但会给出不同的错误消息。当数据准备好并烘焙并传递到 train(.) 的 x/y 接口时,它就可以工作了。

非常感谢任何提示。

配方工作正常,但重采样是在使用配方之前创建的。您应该在调用 train 或使用公式方法

之前删除它们
> iris_dt <- as.data.table(iris)
> iris_dt[3:5,':='(Petal.Length=NA)]
> control <- trainControl(method='cv',number=2,allowParallel = T)
> rec <- recipe(Petal.Length ~ Sepal.Width,iris_dt) %>% step_naomit(all_outcomes(),all_predictors())
> train(Petal.Length ~ Sepal.Width,iris_dt,method='lm',trControl = control, na.action = na.omit)
Linear Regression 

150 samples
  1 predictor

No pre-processing
Resampling: Cross-Validated (2 fold) 
Summary of sample sizes: 74, 73 
Resampling results:

  RMSE      Rsquared   MAE     
  1.610659  0.1885815  1.363651

Tuning parameter 'intercept' was held constant at a value of TRUE