What does the Warning :The response has five or fewer unique values while building random forest mean



I am currently solving one classification problem using random forest algorithm in R .I am able to create the model, but it giving me warning I want to the reason.

randomtree=randomForest(Reverse ~ Circuit+Issue+Petitioner+Respondent+LowerCourt+Unconst,data=train,nodesize=25,ntree=200)

Warning message:
In randomForest.default(m, y, ...) :
  The response has five or fewer unique values.  Are you sure you want to do regression?


Hi @harry,

I must ask why you are using random forest for regression??I mean it can be done but have you tried linear regression and other simpler methods??
You can also consider using decision trees.
In random forests data is resampled from the the train set for as many trees as in the forest(default is 500 in R).So if you have so few values,it is not enough for the random forest to create unique trees.
Hope this helps!!


@harry, You need to convert the response variable(target) to factor if you want to perform classification. Since RF is a CART it builds a model basing on the type of the response variable.

In R, to tell RF to perform classification instead of regression try the following code before running a RF,

train$Reverse <- as.character(train$Reverse)
train$Reverse <- as.factor(train$Reverse)


@Nagesh, you are correct. It works.


thanks! it help me to resolve this problem!!