2017-07-26 89 views
0

這是一般的虹膜建模代碼和結果:如何訪問分類決策樹結果和混淆矩陣結果?

This is the general iris modeling code and result: 

    > library(party) 
    > library(rpart) 
    > library(tree) 
    > library(caret) 
    > train = sample(1:nrow(iris),nrow(iris)* 0.7) 
    > Training_set = iris[train,] 
    > Test_set = iris[-train,] 
    > iris_ctree = ctree(Species~., data = Training_set) 
    > iris_ctree 

     Conditional inference tree with 4 terminal nodes 

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

    1) Petal.Length <= 1.9; criterion = 1, statistic = 97.056 
     2)* weights = 30 
    1) Petal.Length > 1.9 
     3) Petal.Width <= 1.7; criterion = 1, statistic = 48.636 
     4) Petal.Length <= 4.7; criterion = 0.998, statistic = 12.282 
      5)* weights = 36 
     4) Petal.Length > 4.7 
      6)* weights = 7 
     3) Petal.Width > 1.7 
     7)* weights = 32 
    > plot(iris_ctree) 
    > pred = predict(iris_ctree, Test_set) 
    > confusionMatrix(pred, Test_set$Species) 
    Confusion Matrix and Statistics 

       Reference 
    Prediction setosa versicolor 
     setosa   20   0 
     versicolor  0   10 
     virginica  0   0 
       Reference 
    Prediction virginica 
     setosa    0 
     versicolor   1 
     virginica   14 

    Overall Statistics 

        Accuracy : 
        95% CI : 
     No Information Rate : 
     P-Value [Acc > NIR] : 

         Kappa : 
    Mcnemar's Test P-Value : 

    0.9778   
    (0.8823, 0.9994) 
    0.4444   
    8.12e-15   

    0.9655   
    NA    

    Statistics by Class: 

         Class: setosa 
    Sensitivity     1.0000 
    Specificity     1.0000 
    Pos Pred Value    1.0000 
    Neg Pred Value    1.0000 
    Prevalence     0.4444 
    Detection Rate    0.4444 
    Detection Prevalence  0.4444 
    Balanced Accuracy   1.0000 
         Class: versicolor 
    Sensitivity      1.0000 
    Specificity      0.9714 
    Pos Pred Value     0.9091 
    Neg Pred Value     1.0000 
    Prevalence      0.2222 
    Detection Rate     0.2222 
    Detection Prevalence   0.2444 
    Balanced Accuracy    0.9857 
         Class: virginica 
    Sensitivity     0.9333 
    Specificity     1.0000 
    Pos Pred Value     1.0000 
    Neg Pred Value     0.9677 
    Prevalence      0.3333 
    Detection Rate     0.3111 
    Detection Prevalence   0.3111 
    Balanced Accuracy    0.9667 
  1. 我想知道如何訪問「Ctree」的特定節點的值。例如,接近最低分支「7」的值。

  2. 我想知道如何處理混淆矩陣的價值。例如,要接近準確度值。

這個問題的原因是我必須用r對數據庫中的各種數據建模並得到結果。如果你能給我一個提示,我會很感激。

回答