1

我正在使用ada包进行分类,其中描述符变量都是categoricnumeric。这会导致调用pairs函数时出现问题。下面是一个说明我的问题的例子:

require(rpart)
require(ada)

data(car90, package = "rpart")
target = "Country"
input = setdiff(names(car90), target)

# ada only works with two distinct responses
car90 = car90[car90$Country %in% c("USA", "Japan/USA"), ] 

# remove surplus factor levels
car90$Country = as.character(car90$Country) 

adaCar90 = ada(car90[, input], car90[, target])
pairs(adaCar90, car90[, input], vars = 32:33)

# Error in pairs.default(as.matrix(rbind(train.data, test.x))[, vars],   
# lower.panel = panel.low,  :  non-numeric argument to 'pairs'  

使用函数的参数仅选择numeric描述符似乎并不能解决问题。有谁知道我该如何解决这个问题?varspairs

干杯。

4

1 回答 1

1

看起来ada包的维护者没有预料到你的具体用例。最后一行ada:::pairs.ada写着:

pairs(as.matrix(rbind(train.data, test.x))[, vars], lower.panel = panel.low, 
    upper.panel = panel.up)

问题在于[, vars]放置在哪里。train.data代码将和绑定在一起test.x,然后将整个事物变成一个矩阵,然后是子集。因为您的 train.data 包含一堆非数字列,as.matrix所以返回一个字符矩阵。如果将最后一行更改为:

pairs(as.matrix(rbind(train.data, test.x)[, vars]), lower.panel = panel.low, 
    upper.panel = panel.up)

thenas.matrix仅在包含数字数据的子集上调用,并且该函数有效。

编辑

I think what I suggested above is a good long-term solution, but there could be an easier short-term fix: pass only those columns of your training data that you will need for the graph instead of using the vars option. That way, only numeric data is ever passed to that final line of code. That would probably get you your graphs without you needing to hack the function.

于 2013-06-08T20:16:56.007 回答