Use of randomforest() for classification in R?

牧云@^-^@ 提交于 2019-12-05 01:33:45

So the issue is actually quite simple. It turns out my training data was an atomic vector. So it first had to be converted as a data frame. So I needed to add the following line:

training <- as.data.frame(training)

Problem solved!

First, your coercion to a factor is not working because of syntax errors. Second, you should always use indexing when specifying a RF model. Here are changes in your code that should make it work.

    training <- sapply(training.temp,as.numeric)
      training[,"Class"] <- as.factor(training[,"Class"])

    training_rf <- randomForest(x=training[,1:(ncol(training)-1)], y=training[,"Class"], 
                                importance=TRUE, do.trace=100)

# You can also coerce to a factor directly in the model statement
    training_rf <- randomForest(x=training[,1:(ncol(training)-1)], y=as.factor(training[,"Class"]), 
                                importance=TRUE, do.trace=100)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!