Error using RandomForest

I am trying to use Random Forest to improve the classification to determine if it's profit or not.

ssdata_idx = createDataPartition(ssdata1$Profitable, p = 0.70, list = FALSE)
ssdata_trn = ssdata1[ssdata_idx, ] #Training
ssdata_tst = ssdata1[-ssdata_idx, ] #test
profit.f=randomForest(Profitable~Discount+Sales,subset = ssdata_trn,mtry=3,ntree=1000,importance=TRUE)

Error in xj[i] : invalid subscript type 'list'
I don't know why???


*Error in UseMethod("importance") : *

  • no applicable method for 'importance' applied to an object of class "rpart"*


*Error in varImpPlot(profit.f) : *

  • This function only works for objects of class `randomForest'*

confusionMatrix(predict.tree,as.factor(ssdata_tst$Profitable))emphasized text


Welcome to the RStudio community!

In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!