There's more...

Apart from the randomForest package, the party package also provides an implementation of random forest. In the following steps, we illustrate how to use the cforest function within the party package to perform classifications:

  1. First, install and load the party package:
        > install.packages("party")
        > library(party) 
  1. You can then use the cforest function to fit the classification model:
        > churn.cforest = cforest(churn ~ ., data = trainset, con-
trols=cforest_unbiased(ntree=1000, mtry=5))
> churn.cforest
Output
Random Forest using Conditional Inference Trees

Number of trees: 1000

Response: churn
Inputs: international_plan, voice_mail_plan, num-
ber_vmail_messages, total_day_minutes, total_day_calls, to-
tal_day_charge, total_eve_minutes,
total_eve_calls, to-tal_eve_charge, total_night_minutes,
total_night_calls, to-tal_night_charge, total_intl_minutes,
total_intl_calls, to-tal_intl_charge, number_customer_service_calls
Number of observations: 2315
  1. You can make predictions based on the built model and the testing dataset:
        > churn.cforest.prediction = predict(churn.cforest, testset,
OOB=TRUE, type = "response")
  1. Finally, obtain the classification table from the predicted labels and the labels of the testing dataset:
        > table(churn.cforest.prediction, testset$churn)
        Output
        churn.cforest.prediction yes  no
                             yes  91   3
                             no   50 874
..................Content has been hidden....................

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