当我们想将 R 中的随机森林函数应用于超过 53 个类别的预测器时,解决方案是什么?
> RandomForestPrediction=function(alpha){
+ d = sort(sample(nrow(MPS), nrow(MPS)*alpha))
+ train<-MPS[d,]
+ test<-MPS[-d,]
+ myNtree=1000
+ myMtry=5
+ myImportance=TRUE
+ mod2 = randomForest(factor(m.Decision)~.,data=train,tree=myNtree,mtry=myMtry,importance=myImportance)
+ fitted=predict(mod2,test,type="response")
+ return(table(fitted,test$m.Decision))
+ }
> RandomForestPrediction(0.7)
Error in randomForest.default(m, y, ...) :
Can not handle categorical predictors with more than 53 categories.