r中的C50失败,“c50代码名为exit,值为1”

时间:2018-04-13 18:33:57

标签: r machine-learning decision-tree

我遇到了在我的数据集上训练C50的问题。在这篇文章之前,我研究了人们拥有的所有其他类似问题/解决方案。但是,我的数据集没有任何问题,但仍然无法在r中执行C50。我的数据集看起来像:

'data.frame':   113967 obs. of  15 variables:
$ region                : Factor w/ 51 levels "US:AK","US:AL",..: 2 3 3 4 4 4 4 5 5 5 ...
$ city                  : Factor w/ 6396 levels "179708","179720",..: 24 156 156 194 214 226 244 276 316 407 ...
$ dma                   : Factor w/ 211 levels "1","500","501",..: 24 148 148 173 173 173 189 195 204 208 ...
$ user_day              : Factor w/ 7 levels "0","1","2","3",..: 6 6 6 6 6 6 6 6 6 6 ...
$ user_hour             : Factor w/ 24 levels "0","1","10","11",..: 5 16 16 4 22 7 10 11 15 21 ...
$ os_extended           : Factor w/ 71 levels "0","100","113",..: 55 68 68 7 29 14 14 14 29 34 ...
$ browser               : Factor w/ 19 levels "0","10","11",..: 19 18 18 8 18 9 18 17 18 18 ...
$ domain                : Factor w/ 2685 levels "0calc.com","100daysofrealfood.com",..: 1709 777 777 1406 727 2658 1406 1604 964 2658 ...
$ position              : Factor w/ 3 levels "0","1","2": 1 2 2 1 1 2 1 1 1 2 ...
$ placement             : Factor w/ 5406 levels "10004098","10008956",..: 3331 1696 1714 3600 438 479 3598 3423 5406 479 ...
$ publisher             : Factor w/ 1641 levels "1000773","1000776",..: 581 687 687 663 1369 1525 663 624 1641 1525 ...
$ seller_member_id      : Factor w/ 304 levels "1001","1019",..: 19 101 101 40 19 35 40 40 75 35 ...
$ user_group            : Factor w/ 1000 levels "0","1","10","100",..: 252 243 243 363 343 342 162 380 122 212 ...
$ size                  : Factor w/ 7 levels "160x600","300x250",..: 5 2 2 4 5 2 2 1 2 2 ...
$ predict.bid.vector.bin: Factor w/ 2 levels "(0.112,0.831]",..: 1 1 1 1 1 1 1 2 1 2 ...

如您所见,最后一个变量是我的目标变量(作为因子),此处的所有要素都有超过1个等级。此外,数据集中没有NA。然而,当我执行C50时,我收到了错误:

> library(C50)
> myC50_Tree <- C5.0(x = test_set[,-15], y = test_set$predict.bid.vector.bin)

c50 code called exit with value 1

> summary(myC50_Tree)

Call:
C5.0.default(x = test_set[, -15], y = test_set$predict.bid.vector.bin)


C5.0 [Release 2.07 GPL Edition]     Fri Apr 13 14:29:54 2018
-------------------------------

*** line 6 of `undefined.names': attribute `region' has only one value `US'

Error limit exceeded

这里会出现什么问题?

***您可以使用以下r代码获取我的模拟数据集:

# --- Set unique feature values

region <- c("US:AL","US:AR","US:AZ","US:CA","US:CO","US:CT","US:DC","US:FL")
city <- c("179944","180802","181120","181212","181251","181315","181400","181512","181762","181842","181934","181953","182259","182295")
dma <- c('522','693','754','875','345','234')
user_day <- c('1','2','3','4','5','6')
user_hour <- c('12','11','10','9','8','7','6','5')
os_extended <- c('187','92','125','87','90')
browser <- c('8','9','18','5')
domain <- c('yahoo.com','youtube.com','mmctw.com','msn.com','frive.com','wework.com')
position <- c('0','1','2','3')
placement <- c('`234123412','34563451','235234624','46785467','234556834','85991927394')
publisher <- c('5345','57867','78034','123452','84567','245645','956752')
seller_memeber_id <- c('234','745','546','687','235')
user_group <- c('112','556','009','345','238')
size <- c('100X20','340X10','300X500','300X600')
predict.bid.vector.bin <- c('(0.831,1.55]',  '(0.112,0.831]')
features <- list(region,city,dma,user_day,user_hour,os_extended,browser,domain,position,placement,publisher,seller_memeber_id,user_group,size,predict.bid.vector.bin)

# --- Sample simulated dataset

test_set <- vector()

for (feature in 1:length(features)) {
  test_set <- cbind(test_set, sample(features[[feature]],1000,replace=TRUE))
}
test_set <- data.frame(test_set)
colnames(test_set) <- c('region','city','dma','user_day','user_hour',
                      'os_extended','browser','domain','position',
                      'placement','publisher','seller_memeber_id',
                      'user_group','size','predict.bid.vector.bin')
# --- check data

str(test_set)

1 个答案:

答案 0 :(得分:1)

问题是变量名region - 我认为C5.0不喜欢那里的冒号。我用以下内容重新创建了数据集:

region <- c("AL","AR","AZ","CA","CO","CT","DC","FL")

然后它没有任何错误:

treeModel <- C5.0(x=test_set[,-15],y=test_set[,15])
treeModel

...
Evaluation on training data (1000 cases):

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

   103  220(22.0%)   <<


   (a)   (b)    <-classified as
  ----  ----
   358   122    (a): class 1
    98   422    (b): class 2


Attribute usage:

100.00% user_hour
 28.30% region
 27.30% dma
 24.30% city
 17.60% user_day
 15.40% size
 12.70% placement
  9.10% user_group
  7.90% browser
  6.50% os_extended
  4.70% publisher
  4.40% position
  3.70% domain
  3.00% seller_memeber_id

我还将因变量重新编码为12以防万一带有范围的字符串给它一个问题,但这似乎根本不重要(但在输出中)上面你会看到它预测为1级和2级,这就是原因。