I have a set of x, y data I'm using to build a random forest. The x data is a vector of values that includes some NAs. So I use rfImpute
to handle the missing data and create a random forest. Now I have a new unseen observation x (with an NA) and I want to predict y. How do I impute the missing value so that I may use the random forest that I have already grown? The rfImpute
function seems to require x and y. I only have x for prediction purposes.
My question is similar (but different) to this question. And for example, I can use the same iris dataset. If I've correctly interpreted the code in the answer to the question I reference, the code iris.na[148, , drop=FALSE]
in the statement iris.na2 = rbind(iris.imputed, iris.na[148, , drop=FALSE])
represents the new data which includes the Species
(the Y value). In my problem I would not know the Species
—I want to use the random forest to predict that. I would have the 4 independent variables, but some might be NA
for a given row. To continue the analogy, imagine I have 3 of the 4 variables (one is missing). I want to impute that value. Then I want to predict the species which I do not know.
In response to gung's comment that I should add an illustration, let me put it in terms of the iris data set. Imagine I have the following data on a flower. I know it's Sepal.Length
, Sepal.Width
, Petal.Length
, but not the Petal.Width
. I'd like to impute the Petal.Width
and then use those 4 values within a RF model to predict the Species
.