我正在尝试用以下方法制作一个随机森林
movies.rf <- randomForest(Infl.Adj.Dom.BoxOffice~. -Genre -Source -ProductionMethod -CreativeType, data=Movies, subset=train)
我明白了
Error in randomForest.default(m, y, ...) : Can not handle categorical predictors with more than 53 categories.
在阅读this之后,我试着检查我的变量的值并得到了这个
>length(unique(Movies$Genre))
[1] 12
> length(unique(Movies$Source))
[1] 16
> length(unique(Movies$ProductionMethod))
[1] 5
> length(unique(Movies$CreativeType))
[1] 9
单独地,它们都不大于53,并且加在一起,它们小于53.那么为什么我仍然得到错误?
如果从你的问题的上下文看,你打算只使用这四个特征(Genre, Source, ProductionMethod, CreativeType
)来预测Infl.Adj.Dom.BoxOffice
,那么你正在以错误的方式使用R公式:你的用法
Infl.Adj.Dom.BoxOffice~. -Genre -Source -ProductionMethod -CreativeType
实际上说“使用所有特征(Infl.Adj.Dom.BoxOffice
)预测.
除了Genre, Source, ProductionMethod, CreativeType
”(-
符号用于excluding变量)。
因此,这里实际发生的是,您的其他功能中的一个(或多个)是超过53个级别的分类功能。
正确的用法,如果你确实只想使用你提到的这四个功能,应该是:
movies.rf <- randomForest(Infl.Adj.Dom.BoxOffice ~ Genre + Source + ProductionMethod + CreativeType, data=Movies, subset=train)