2012-03-12 6 views

Trả lời

47

Giả sử bạn có nghĩa là tỷ lệ lỗi tính toán trên mẫu được sử dụng để phù hợp với mô hình, bạn có thể sử dụng printcp(). Ví dụ, sử dụng ví dụ trên mạng,

> library(rpart) 
> fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) 
> printcp(fit) 

Classification tree: 
rpart(formula = Kyphosis ~ Age + Number + Start, data = kyphosis) 

Variables actually used in tree construction: 
[1] Age Start 

Root node error: 17/81 = 0.20988 

n= 81 

     CP nsplit rel error xerror xstd 
1 0.176471  0 1.00000 1.00000 0.21559 
2 0.019608  1 0.82353 0.82353 0.20018 
3 0.010000  4 0.76471 0.82353 0.20018 

Các Root node error được sử dụng để tính toán hai biện pháp thực hiện tiên đoán, khi xem xét giá trị hiển thị trong cột rel errorxerror, và tùy thuộc vào các tham số phức tạp (cột đầu tiên) :

  • 0,76471 x 0,20988 = 0,1604973 (16,0%) là tỷ lệ lỗi resubstitution (ví dụ, tỷ lệ lỗi tính toán trên mẫu đào tạo) - đây là khoảng

    012.351.
    class.pred <- table(predict(fit, type="class"), kyphosis$Kyphosis) 
    1-sum(diag(class.pred))/sum(class.pred) 
    
  • 0,82353 x 0,20988 = 0,1728425 (17,2%) là chéo xác nhận tỷ lệ lỗi (sử dụng 10 lần CV, xem xval trong rpart.control(); nhưng cũng xem thêm xpred.rpart()plotcp() dựa trên loại biện pháp này). Biện pháp này là một chỉ số khách quan hơn về độ chính xác tiên đoán.

Lưu ý rằng nó là nhiều hơn hoặc ít hơn trong thỏa thuận với độ chính xác phân loại từ tree:

> library(tree) 
> summary(tree(Kyphosis ~ Age + Number + Start, data=kyphosis)) 

Classification tree: 
tree(formula = Kyphosis ~ Age + Number + Start, data = kyphosis) 
Number of terminal nodes: 10 
Residual mean deviance: 0.5809 = 41.24/71 
Misclassification error rate: 0.1235 = 10/81 

nơi Misclassification error rate được tính từ mẫu huấn luyện.