gpt4 book ai didi

machine-learning - na.fail.default 中的随机森林错误 : missing values in object

转载 作者:行者123 更新时间:2023-11-30 09:40:15 28 4
gpt4 key购买 nike

我正在运行一个 RF 模型,该模型对于大多数变量都没有错误;但是,当我包含一个变量:duration_in_program 和以下代码时:

```{r Random Forest Model}
## Run a Random Forest model
mod_rf <-
train(left_school ~ job_title
+ gender +
+ marital_status + age_at_enrollment + monthly_wage + educational_qualification + cityD + educational_qualification + cityC.
+ cityB +cityA + duration_in_program, # Equation (outcome and everything else)
data=train_data, # Training data
method = "ranger", # random forest (ranger is much faster than rf)
metric = "ROC", # area under the curve
trControl = control_conditions,
tuneGrid = tune_mtry
)
mod_rf

我收到以下错误:

Error in na.fail.default(list(left_welfare = c(1L, 2L, 2L, 2L, 2L, 2L, : missing values in object

最佳答案

假设 train() 来自插入符号,您可以使用 na.action 参数指定一个函数来处理 na。默认值为 na.fail。一个非常常见的就是 na.omit。 randomForest 库有 na.roughfix ,它将“按中位数/众数估算缺失值”。

mod_rf <-
train(left_school ~ job_title
+ gender +
+ marital_status + age_at_enrollment + monthly_wage + educational_qualification + cityD + educational_qualification + cityC.
+ cityB +cityA + duration_in_program, # Equation (outcome and everything else)
data=train_data, # Training data
method = "ranger", # random forest (ranger is much faster than rf)
metric = "ROC", # area under the curve
trControl = control_conditions,
tuneGrid = tune_mtry,
na.action = na.omit
)
mod_rf

关于machine-learning - na.fail.default 中的随机森林错误 : missing values in object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59257544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com