0 votes
1 view
in Machine Learning by (13.5k points)

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

library(randomForest)

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

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

I get the following error

Error in na.fail.default(list(speed = 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...