There's more...

In addition to using the boosting function in the adabag package, one can also use the caret package to perform a classification with the boosting method:

  1. First, load the mboost and pROC package:
        > library(mboost)
        > install.packages("pROC")
        > library(pROC)  
  1. We can then set the training control with the trainControl function and use the train function to train the classification model with AdaBoost.M1:
        > set.seed(2)
        > ctrl = trainControl(method = "repeatedcv", repeats = 1, class
Probs = TRUE, summaryFunction = twoClassSummary) > ada.train = train(churn ~ ., data = trainset, method = "ada",
metric = "ROC", trControl = ctrl)
  1. Use the summary function to obtain the details of the classification model:
        > ada.train$result
        Output
        nu maxdepth iter       ROC      Sens        Spec      ROCSD
SensSD SpecSD 1 0.1 1 50 0.8571988 0.9152941 0.012662155 0.03448418
0.04430519 0.007251045 4 0.1 2 50 0.8905514 0.7138655 0.006083679 0.03538445
0.10089887 0.006236741 7 0.1 3 50 0.9056456 0.4036134 0.007093780 0.03934631
0.09406015 0.006407402 2 0.1 1 100 0.8550789 0.8918487 0.015705276 0.03434382
0.06190546 0.006503191 5 0.1 2 100 0.8907720 0.6609244 0.009626724 0.03788941
0.11403364 0.006940001 8 0.1 3 100 0.9077750 0.3832773 0.005576065 0.03601187
0.09630026 0.003738978 3 0.1 1 150 0.8571743 0.8714286 0.016720505 0.03481526
0.06198773 0.006767313 6 0.1 2 150 0.8929524 0.6171429 0.011654617 0.03638272
0.11383803 0.006777465 9 0.1 3 150 0.9093921 0.3743697 0.007093780 0.03258220
0.09504202 0.005446136
  1. Use the plot function to plot the ROC curve within different iterations:
        > plot(ada.train)
The repeated cross validation plot
  1. Finally, we can make predictions using the predict function and view the classification table:
        > ada.predict = predict(ada.train, testset, "prob")
        > ada.predict.result = ifelse(ada.predict[1] > 0.5, "yes", "no")
    
        > table(testset$churn, ada.predict.result)
        Output
             ada.predict.result
               no yes
          yes  40 101
          no  872   5 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset