Tero
Tero

Reputation: 139

Predict (Random Forest): prob or vote not meaningful for regression

When I run the predict function, I get this error:

Error in predict.randomForest(fit, newdata = na.roughfix(csvTest[, -c(1:2,  : 
'prob' or 'vote' not meaningful for regression code here

This is the code:

fit <- foreach (ntree = rep (round(number_trees/nc), nc), 
            .combine = combine, .packages = 'randomForest') %dopar% randomForest(y=csv$mal,x=na.roughfix (csv[, c(1:2,4:5,8:13,17,19:20,22:29,ncol(csv))]), ntree = number_trees)
prob <- predict (fit, newdata = na.roughfix (csvTest[, -c(1:2,4:5,8:13,17,19:20,22:29,ncol(csvTest))]), type = 'prob')[, 2]

Can anyone help me to understand what it's the problem? Thanks

Upvotes: 1

Views: 5776

Answers (1)

Tero
Tero

Reputation: 139

I just solved it. It was because my target variable (csv$mal) was set to "numeric" by R by default, when it should be a "factor" one (0 or 1).

With numeric, random forest runs with type="regression", instead of type="classification".

Upvotes: 8

Related Questions