I want to deal with NA values in my data but do not want to scale and center it so I simply do this:
preProcess(data, method = "knnImpute", k=10)
or this:
preProcess(data, method = "bagImpute")
However it automatically scales and centers data which seems intentional (states that in documentation). How do I avoid that and simply do imputation?
R Language caret Preprocessing Pre-processing in caret is done through the preProcess() function. Given a matrix or data frame type object x , preProcess() applies transformations on the training data which can then be applied to testing data. The heart of the preProcess() function is the method argument.
Caret is a one-stop solution for machine learning in R. The R package caret has a powerful train function that allows you to fit over 230 different models using one syntax. There are over 230 models included in the package including various tree-based models, neural nets, deep learning and much more.
You can't avoid scaling and centering your data when using method = "knnImpute"
, presumably because it does not usually make sense to use knn without doing so.
However, method = "bagImpute"
or method = "medianImpute"
will not scale and center the data unless you ask it to. For example:
mtcars[1, 1] <- NA
pc <- preProcess(data, method = "bagImpute")
head(predict(pc, mtcars))
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With