R中的分类树限制为32个级别 [英] Classification tree in R limit to 32 levels

查看:299
本文介绍了R中的分类树限制为32个级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用包树在R中创建分类树。

I am trying to create a classification tree in R using the package tree.

这是我正在使用的数据集的摘录(包括标题):

This is an excerpt of the dataset I am using (header included):

CENTRO_EXAMEN,NOMBRE_AUTOESCUELA,MES,TIPO_EXAMEN,NOMBRE_PERMISO,PROB
Alcal· de Henares,17APTOV,5,PRUEBA DESTREZA,A2 ,0
Alcal· de Henares,17APTOV,5,PRUEBA CONDUCCION Y CIRCULACION,B  ,0.8
Alcal· de Henares,17APTOV,5,PRUEBA TEORICA,B  ,0.333333333
Alcal· de Henares,2000,5,PRUEBA TEORICA,B  ,0

这是我向R发出的命令:

and this is the commands I am issuing to R:

madrid=read.csv("madrid.csv",header=T,na.strings="?")
#madrid=na.omit(madrid)
names(madrid)
dim(madrid)
fix(madrid)
library(tree)
attach(madrid)

#costruisce albero
High=ifelse(PROB<=0.5,"No","Yes")
madrid=data.frame(madrid,High)
tree.madrid=tree(High~CENTRO_EXAMEN+NOMBRE_AUTOESCUELA+MES+TIPO_EXAMEN+NOMBRE_PERMISO,madrid)
summary(tree.madrid)
plot(tree.madrid)
text(tree.madrid,pretty=0)
tree.madrid

R发出tree.madrid后返回以下错误

R returns the following error after issuing tree.madrid

Error in tree(High ~ CENTRO_EXAMEN + NOMBRE_AUTOESCUELA + MES + TIPO_EXAMEN +  : 
  factor predictors must have at most 32 levels

知道为什么吗?

推荐答案

基本上,在您的数据中创建如此多的拆分在计算上是昂贵的,因为您正在选择所有2 ^ 32(大约)个可能的分割中的最佳分割。

Basically, it becomes computationally expensive to create so many splits in your data, since you are selecting the best split out of all 2^32 (approx) possible splits.

如果您能够使用随机森林,则Ben的评论此处表示 randomForest 现在可以处理多达53个级别。如果由于某种原因而无法使用随机森林,则可以考虑破坏分类预测变量的级别。

If you are able to use a random forest, Ben's comment here suggests that the randomForest can now handle up to 53 levels. If you cannot use a random forest for whatever reason, you can consider collapsing the levels of your categorical predictor.

这篇关于R中的分类树限制为32个级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆