R中的决策树使用基于多个拆分属性的rpart

时间:2015-05-04 16:25:03

标签: r prediction decision-tree

我正在尝试为以下数据集构建预测模型的决策树:

enter image description here

这是我的代码:

fitTree = rpart(classLabel ~ from_station_id + start_day + start_time
            + gender +  age, method = "class", data=d)
fancyRpartPlot(fitTree)

但是结果决策树只使用了其中一个属性(from_station_id)作为'分割属性'而且不关心其他属性的值(start_day,start_time,gender,age)。结果如下:

Click放大。

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的语法看起来正确。基于数据集的片段,classLabel和from_station_id可能密切相关(也可能是性别?)。在这种情况下,from_station_id将是您的classLabel的最佳预测器,其他变量只是不提供信息(或者也是相关但被屏蔽),并且不会显示在树上。尝试:

summary.rpart(fitTree)

这将更好地向您展示如何进行拆分以及变量重要性,这可以帮助您评估屏蔽。您应该避免使用相关预测变量,因为它们会导致屏蔽并且会干扰交互。

如果您只是在摘要中看到from_station_id,那么您知道它忽略了其他变量,但我不确定为什么会这样。