0
$\begingroup$

I have a dataset in which the response variable is categorical, but represented by by a finite number of numeric classes (i.e., 7000,8900,3100,4000). When running a random forest model in R using the randomForest package - https://cran.r-project.org/web/packages/randomForest/randomForest.pdf, it states that for the response variable, y, "If a factor, classification is assumed, otherwise regression is assumed. If omitted, randomForest will run in unsupervised mode."

In my case, will the response vector be interpreted by R as a factor, or as numeric even though there are a discrete number of classes. If the latter, is there way to force it to interpret the response as categorical?

$\endgroup$

1 Answer 1

3
$\begingroup$

It depends on the type your data is saved in. A number can be represented as a string, integer, float and so on. You can set the type to a factor using as.factor(), or make it numeric using as.numeric(). This will define the type, which will determine the behavior of random forest.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.