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)
profit.f
Error in xj[i] : invalid subscript type 'list'
I don't know why???
importance(profit.f)
*Error in UseMethod("importance") : *
no applicable method for 'importance' applied to an object of class "rpart"*
varImpPlot(profit.f)
*Error in varImpPlot(profit.f) : *
This function only works for objects of class `randomForest'*
predict.tree=predict(profit.f,ssdata_tst,type="class")
confusionMatrix(predict.tree,as.factor(ssdata_tst$Profitable))emphasized text
Hi,
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:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
Good luck!
PJ
system
Closed
December 13, 2021, 10:19pm
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.