How to remove the missing value of object in random forest

r
random_forest

#1

I am doing a problem of classification using random forest but when I create the model of random forest it gives me error which says missing value in object.
head of train data


m1<-randomForest(as.factor(Survived)~.,data=train)
Error in na.fail.default(list(as.factor(Survived) = c(1L, 2L, 2L, 2L, :
missing values in object


#2

Hello @hinduja1234,

One of the requirements that the data must satisfy before running a random forest is that there must not be any missing values in the data.So you can either use the package rpart which can handle missing values or do one among these 3 things:
1.If there are a few records containing missing values you can drop them from the data set.
2.If it is continuous variable then you can predict the values.
3.Use the na.roughfix,rfImpute functions in the random forest package itself to impute the missing values.
Hope this helps!