我正在尝试使用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 Command的数据。
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>)
您可能有另一个包含impute
函数的软件包,它正在掩盖mlr
一个
在我的计算机上,我具有e1071
和mlr
的impute
功能
尝试以下操作: ?impute
这应该显示出与您加载尽可能多的Pacakge的帮助
专门使用mlr
软件包的功能,请执行此操作
imp1 = mlr::impute(obj =train_1, target = "target",
classes = list(integer = imputeMedian(),factor = imputeMode()))
另外,请注意 @chinsoon12的评论中提到的,您需要将data=train_1
更改为obj=train_1
或完全删除分配并使用train_1