【问题标题】:problem with decision tree applied to dataset应用于数据集的决策树问题
【发布时间】:2018-11-05 23:12:04
【问题描述】:

我正在测试使用 R 对决策树进行编程,并决定使用来自 UCI 的汽车数据集,可用 here

根据作者的说法,它有 7 个属性:

CAR                      car acceptability
   . PRICE                  overall price
   . . buying               buying price
   . . maint                price of the maintenance
   . TECH                   technical characteristics
   . . COMFORT              comfort
   . . . doors              number of doors
   . . . persons            capacity in terms of persons to carry
   . . . lug_boot           the size of luggage boot
   . . safety               estimated safety of the car

所以我想使用 DT 作为分类器,以考虑购买价格、维护、舒适度、车门、人员、行李箱和安全性来获得汽车的可接受性。

首先我提取了第一列作为因变量,然后我注意到数据是按顺序排列的;取决于第一列的值(非常高、高、中、低)。出于这个原因,我决定对数据进行洗牌。我的代码如下:

car_data<-read.csv("car.data")
library(C50)
set.seed(12345)
car_data_rand<-car_data[order(runif(1727)),]
car_data<-car_data_rand
car_data_train<-car_data[1:1500,]
car_data_test<-car_data[1501:1727,]
answer<-data_train$vhigh
answer_test<-data_test$vhigh
#deleting the dependent variable or y from the data
car_data_train$vhigh<-NULL
car_data_test$vhigh<-NULL
car_model<-C5.0(car_data_train,answer)
summary(car_model)

这里我遇到了一个可怕的错误:

Evaluation on training data (1500 cases):

        Decision Tree   
      ----------------  
      Size      Errors  

         7  967(64.5%)   <<

我做错了什么?

【问题讨论】:

    标签: r decision-tree


    【解决方案1】:
    1. 在你的代码中间你有data_traindata_test而不是car_data_traincar_data_test

    2. 虽然错误率很高,但并没有什么问题。请注意

    1 - table(answer) / length(answer)
    # answer
    #      high       low       med     vhigh 
    # 0.7466667 0.7566667 0.7426667 0.7540000 
    

    这意味着如果你天真地总是猜“低”,你的错误将是 75.6%。因此, 有大约 11.1% 的改进。它有点低的事实意味着预测变量不是很好。

    1. 最后,存在不一致:您说要对汽车的可接受性进行建模,而您的代码是关于buying 变量。现在修复它只会导致 1.1% 的错误。但是,在这种情况下,您的样本非常不平衡:

    1 - table(answer) / length(answer)
    # answer
    #       acc      good     unacc     vgood 
    # 0.7773333 0.9600000 0.3020000 0.9606667 
    

    也就是说,通过总是猜测unacc,你可能已经得到了 30.2% 的错误。然而,29.1% 的提升显然更大。

    【讨论】:

      猜你喜欢
      • 2011-05-14
      • 2012-12-20
      • 1970-01-01
      • 2018-01-04
      • 2018-06-23
      • 2017-03-06
      • 1970-01-01
      • 2021-03-17
      • 2016-08-09
      相关资源
      最近更新 更多