0

我正在尝试使用 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>)
4

1 回答 1

1

您可能有另一个包,其中包含impute 定义的函数,并且它正在屏蔽该mlr函数

在我的机器上,我既有功能e1071又有mlr功能impute

试试这个: ?impute 这应该显示你加载的尽可能多的包的帮助

要专门使用mlr包中的功能,请执行此操作

imp1 = mlr::impute(obj =train_1, target = "target",
          classes = list(integer = imputeMedian(),factor = imputeMode()))

另请注意,正如@chinsoon12 的评论中提到的,您需要更改data=train_1obj=train_1完全删除分配并使用train_1

于 2018-02-24T00:46:51.490 回答