繁体   English   中英

错误:step_impute_linear() 使用的数据没有任何行的插补值都完整

[英]Error: The data used by step_impute_linear() did not have any rows where the imputation values were all complete

我正在使用配方 function 并在使用配方 function 中的 step_impute_linear() 来估算 NA 时出现错误。 请注意 step_impute_median 或 step_impute_mean 工作没有问题。 如果我使用: step_impute_linear(all_predictors()) 或 step_impute_linear(all_numeric(),.) 等也没关系。这些组合都不起作用。 也不是其他方法,如: step_impute_knn(all_nominal(),impute_with = all_predictors(),-has_role("ID")) 也失败了。

我还检查了数据,并非所有行都包含缺失数据,也不是所有列都包含缺失数据。

dt_rec <- recipe(
  OFFER_STATUS~ ., data = dt_training) %>% 
  # 1. Define Role
  update_role(MO_ID, new_role = "ID") %>% 
  update_role(SO_ID, new_role = "ID") %>% 
  # turn dates into decimals
  step_mutate_at(where(is.Date), fn = decimal_date) %>% 
  # impute all numeric columns with their median
  # 2. Impute
  # step_impute_median(all_numeric(),-has_role("ID"))%>%
  step_impute_linear(all_numeric(),impute_with = .,-has_role("ID"))
  # ignoring novel factors
  # 3. Handle factor levels
  step_novel(all_predictors(), -all_numeric())  %>%
  # impute all other nominal (character + factor) columns with the value "none"
  step_unknown(all_nominal(), new_level = "none") %>% 
  step_string2factor(all_nominal(), -all_outcomes(), -has_role("ID")) %>% 
  # remove constant columns
  step_zv(all_predictors()) %>% 
  # 4. Discretize
  # remove variables that have a high correlation with each other
  # as this will lead to multicollinearity
  step_corr(all_numeric(), threshold = 0.99) %>% 
  # normalization --> centering and scaling numeric variables
  # mean = 0 and Sd = 1
  step_normalize(all_numeric()) %>%
  # 5. Dummy variables
  # creating dummary variables for nominal predictors
  step_dummy(all_nominal(), -all_outcomes())
# 6. Normalization
# 7. Multivariate transformation
step_pca(all_numeric_predictors())

dt_rec

dt_rec %>% summary()

当您使用function 之类的step_impute_linear()时,您是在说“将我的变量的值与其他变量一起计算”。 如果其中一些其他变量缺少数据,则 model 将无法成功拟合。 如果您有一组变量,例如xyz ,它们都有一些缺失的数据并且您想使用彼此进行估算,我建议您:

  • 使用仅取决于该变量的方法来估算一个或多个变量(例如x ),例如使用中位数或类似方法
  • 仅使用现在已完成且没有缺失数据的预测变量来估算其他变量(例如基于x估算yz

如果您尝试为一组相互使用的变量拟合一整套线性模型,这是行不通的,所有这些变量都缺少数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM