我正在尝试使用 mlr 库来估算缺失值。出现以下错误。
Error in impute(data = train_1, target = "target", classes = list(integer = imputeMedian(), :
unused argument (data = train_1)
这是代码
setcol <- c("age","workclass","fnlwgt","education",
"education-num","marital-status","occupation","relationship",
"race","sex","capital-gain","capital-loss","hours-per-week",
"native-country","target")
train = read.table("adult.data", header = FALSE, sep=','
,col.names = setcol, na.strings = c(" ?"),stringsAsFactors = F)
train_1=head(train)
imp1 = impute(data =train_1, target = "target",
classes = list(integer = imputeMedian(),factor = imputeMode()))
这是一个示例数据。它包含来自 head 命令的数据。
dput(head(train))
structure(list(age = c(39L, 50L, 38L, 53L, 28L, 37L), workclass = c(" State-gov",
" Self-emp-not-inc", " Private", " Private", " Private", " Private"
), fnlwgt = c(77516L, 83311L, 215646L, 234721L, 338409L, 284582L
), education = c(" Bachelors", " Bachelors", " HS-grad", " 11th",
" Bachelors", " Masters"), education.num = c(13L, 13L, 9L, 7L,
13L, 14L), marital.status = c(" Never-married", " Married-civ-spouse",
" Divorced", " Married-civ-spouse", " Married-civ-spouse", " Married-civ-spouse"
), occupation = c(" Adm-clerical", " Exec-managerial", " Handlers-cleaners",
" Handlers-cleaners", " Prof-specialty", " Exec-managerial"),
relationship = c(" Not-in-family", " Husband", " Not-in-family",
" Husband", " Wife", " Wife"), race = c(" White", " White",
" White", " Black", " Black", " White"), sex = c(" Male",
" Male", " Male", " Male", " Female", " Female"), capital.gain = c(2174L,
0L, 0L, 0L, 0L, 0L), capital.loss = c(0L, 0L, 0L, 0L, 0L,
0L), hours.per.week = c(40L, 13L, 40L, 40L, 40L, 40L), native.country = c(" United-States",
" United-States", " United-States", " United-States", " Cuba",
" United-States"), target = c(" <=50K", " <=50K", " <=50K",
" <=50K", " <=50K", " <=50K")), .Names = c("age", "workclass",
"fnlwgt", "education", "education.num", "marital.status", "occupation",
"relationship", "race", "sex", "capital.gain", "capital.loss",
"hours.per.week", "native.country", "target"), class = c("data.table",
"data.frame"), row.names = c(NA, -6L), .internal.selfref = <pointer: 0x0000000002550788>)