r - ROC curve error in randomForest -
i trying create roc curve off below. error states error in prediction(bc_rf_predict_prob, bc_test$class) : number of cross-validation runs must equal predictions , labels.
library(mlbench) #has breast cancer dataset in library(caret) data(breastcancer) #two class model bc_changed<-breastcancer[2:11] #removes variables not used #create train , test/holdout samples (works fine) set.seed(59) bc_rand <- bc_changed[order(runif(699)), ] #699 observations bc_rand <- sample(1:699, 499) bc_train <- bc_changed[ bc_rand,] bc_test <- bc_changed[-bc_rand,] #random forest decision tree (works fine) library(caret) library(randomforest) set.seed(59) bc_rf <- randomforest(class ~.,data=bc_train, ntree=500,na.action = na.omit, importance=true) #roc library(rocr) actual <- bc_test$class bc_rf_predict_prob<-predict(bc_rf, type="prob", bc_test) bc.pred = prediction(bc_rf_predict_prob,bc_test$class) #not work- error
error-error in prediction(bc_rf_predict_prob, bc_test$class) : number of cross-validation runs must equal predictions , labels.
i think coming fact when the:
bc_rf_predict_prob<-predict(bc_rf, type="prob", bc_test)
i matrix result 2 columns benign , list of probabilities , second column of malignant , list of probabilities. logic tells me should have vector of probabilities.
according page 9 of rocr library documentation, prediction
function has 2 required inputs, predictions
, labels
, must have same dimensions.
in case of matrix or data frame, cross-validation runs must have same length.
since str(bc_rf_predict_prob) > [1] matrix [1:200, 1:2]
, means str(bc_test$class)
should have matching dimension.
it sounds want first column vector of bc_rf_predict_prob
, can't without looking @ data.
Comments
Post a Comment