2014-01-16 54 views
0

后,我把我的响应变量的一个因素做as.factor(response),我跑:结果是矢量值,而不是标

tree = ctree(response~., data=trainingset) 

当我绘制这棵树:它给了我矢量值y的在图中作为一个例子: Y =(0.095,0.905,0) 我注意到,3个值之和为1。

但作为一个问题是,实际的响应变量包括0,1值,只有99。

任何人都可以帮我解释ctree阴谋这个载体吗?谢谢!

在特定的代码方面,它看起来像如下:为每个类的

response = as.factor(data$response) 
newdata = cbind(predictor.matrix, response) 

ind = sample(2, nrow(newdata), replace=TRUE, prob=c(0.7, 0.3)) 
trainData = newdata[ind==1,] 
testData = newdata[ind==2,] 

tree = ctree(response~., data=trainData) 
plot(tree, type="simple") 
+1

这些都是为每个类的后验概率;即'1'类的后验概率为〜0.9(90%)。 –

+0

谢谢加文,我用命令plot(tree,type =“simple”) –

+0

和is.factor()问题,返回值为TRUE。 :) –

回答

0

这些都是后验概率;即该节点的后验概率对于类别1为〜0.9(90%)(假设您的因子水平为c(0, 1, 99),

在实际意义上,这意味着该节点中约90%的观察值是1类,〜5%是0类,并没有观察的是99类的。

我觉得是抛出你的是,你的类是数字水平和剧情有后验概率,也是数字。如果我们请看派对包的示例,其中响应是带有字符级别的因素,希望您能理解绘图和输出从树更好。

?ctree

library("party") 
irisct <- ctree(Species ~ ., data = iris) 
irisct 

R> irisct 

    Conditional inference tree with 4 terminal nodes 

Response: Species 
Inputs: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width 
Number of observations: 150 

1) Petal.Length <= 1.9; criterion = 1, statistic = 140.264 
    2)* weights = 50 
1) Petal.Length > 1.9 
    3) Petal.Width <= 1.7; criterion = 1, statistic = 67.894 
    4) Petal.Length <= 4.8; criterion = 0.999, statistic = 13.865 
     5)* weights = 46 
    4) Petal.Length > 4.8 
     6)* weights = 8 
    3) Petal.Width > 1.7 
    7)* weights = 46 

这里,Species是水平的因子变量

R> with(iris, levels(Species)) 
[1] "setosa"  "versicolor" "virginica" 

绘制的树示出了在终端节点中的数字后验概率:

plot(irisct, type = "simple") 

enter image description here

更翔实的情节虽然是:

plot(irisct) 

enter image description here

由于这清楚地表明,每个节点具有多个从一个或多个类的观察。后验概率是如何计算出来的。从树

预测由predict()方法

predict(irisct) 

R> predict(irisct) 
    [1] setosa  setosa  setosa  setosa  setosa  setosa  
    [7] setosa  setosa  setosa  setosa  setosa  setosa  
[13] setosa  setosa  setosa  setosa  setosa  setosa 
.... 

您可以通过treeresponse功能objtain每个obsevration的posterioro概率给出

R> treeresponse(irisct)[145:150] 
[[1]] 
[1] 0.00000 0.02174 0.97826 

[[2]] 
[1] 0.00000 0.02174 0.97826 

[[3]] 
[1] 0.00000 0.02174 0.97826 

[[4]] 
[1] 0.00000 0.02174 0.97826 

[[5]] 
[1] 0.00000 0.02174 0.97826 

[[6]] 
[1] 0.00000 0.02174 0.97826 
+0

这太棒了,再次感谢Gavin! –

相关问题