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

Decision Tree in R using rpart based on multiple splitting attributes

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

这是我的代码:

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

但是结果决策树只使用了一个属性(from_station_id)作为'splitting attribute'而没有关心其他属性的值(start_day,start_time、性别、年龄)。这是结果:

Click放大。

我做错了什么?

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

summary.rpart(fitTree)

这将更好地向您展示拆分的方式和变量的重要性,这可以帮助您评估掩蔽。您应该避免相关的预测变量,因为它们会导致掩蔽并可能干扰交互。

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