I am trying to impute missing values using mlr library. Getting following error.
Error in impute(data = train_1, target = "target", classes = list(integer = imputeMedian(), :
unused argument (data = train_1)
Here is the code
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()))
Here is a sample data. It contain data from 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>)
You probably have another package that contains a impute
function defined and it is masking the mlr
one
On my machine I have both e1071
and mlr
with the impute
function
Try this: ?impute
This should show help from as many pacakges as you have loaded
To use the function from the mlr
package specifically, do this
imp1 = mlr::impute(obj =train_1, target = "target",
classes = list(integer = imputeMedian(),factor = imputeMode()))
Also note as mentioned in the comments by @chinsoon12 that you need to change data=train_1
to obj=train_1
or just remove the assignment altogether and use train_1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.