Explore Courses Blog Tutorials Interview Questions
0 votes
in Machine Learning by (19k points)

I would like to fit a random forest model, but when I call


cars$speed[1] <- NA # to simulate missing value

model <- randomForest(speed ~., data=cars)

I get the following error

Error in = c(NA, 4, 7, 7, 8, 9, 10, 10, 10,  : missing values in object

1 Answer

0 votes
by (33.1k points)

If you want to train a random forest with data having missing values, then maybe you have some misconceptions about training a model. 

Training a machine learning model means, we are giving input data to model so that a specific algorithm can draw a pattern from that pattern. If you train any machine learning model with missing data, then maybe you are doing it wrong.

You should pre-process your dataset if you’re having missing value. You can use an imputer to fill missing values. 

If you are having a really small data set (that’s not useful for machine learning), then you can set this parameter like this:

na.action = na.omit

Hope this answer helps you a bit.

Browse Categories