# randomForest chooses regression instead of classification

I'm using the randomForest package in R and using the iris data, the random forest generated is a classification but when I use a dataset with around 700 features (the features are each pixel in a 28x28 pixel image) and the label column is named label, the randomForest generated is regression. I'm using the following line:

rf <- randomForest(label ~ ., data=train)


How come regression is used instead of classification? The data is read in through read.csv().

class(iris\$Species)

Most often this is because you did not tell R that label is a categorical variable. The read.csv function tries to guess what type to use for each column and if it looks like a numeric column then that is what it will use. You can check how R stores the variable using the str function. You can force read.csv to read the variable as a factor (or numeric, or ...) using the colClasses argument. Or you can change labels to a factor after reading it in using the factor function.
If this is not the case then we need more information about your data. The results from running str on your data frame would probably be useful.