我试图使用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>)
答案 0 :(得分:0)
您可能有另一个包含impute
函数的包,它正在屏蔽mlr
一个
在我的机器上,e1071
和mlr
都有impute
功能
试试这个:
?impute
这应该显示你已经加载的许多pacakges的帮助
要专门使用mlr
包中的功能,请执行此操作
imp1 = mlr::impute(obj =train_1, target = "target",
classes = list(integer = imputeMedian(),factor = imputeMode()))
另请注意@ chinsoon12的评论中提到您需要将data=train_1
更改为obj=train_1
,或者只是完全删除作业并使用train_1