Perform the following steps to generate a classification model for the telecom churn dataset:
- First, you need to install and load the adabag package (it might take a while to install adabag):
> install.packages("adabag") > library(adabag)
- Next, you can use the bagging function to train a training dataset (the result may vary during the training process):
> set.seed(2) > churn.bagging = bagging(churn ~ ., data=trainset, mfinal=10)
- Access the variable importance from the bagging result:
> churn.bagging$importance
Output:
international_plan number_customer_service_calls
10.4948380 16.4260510
number_vmail_messages total_day_calls
0.5319143 0.3774190
total_day_charge total_day_minutes
0.0000000 28.7545042
total_eve_calls total_eve_charge
0.1463585 0.0000000
total_eve_minutes total_intl_calls
14.2366754 8.7733895
total_intl_charge total_intl_minutes
0.0000000 9.7838256
total_night_calls total_night_charge
0.4349952 0.0000000
total_night_minutes voice_mail_plan
2.3379622 7.7020671
- After generating the classification model, you can use the predicted results from the testing dataset:
> churn.predbagging= predict.bagging(churn.bagging,
newdata=testset)
- From the predicted results, you can obtain a classification table:
> churn.predbagging$confusion
Output:
Observed Class
Predicted Class yes no
no 35 866
yes 106 11
- Finally, you can retrieve the average error of the bagging result:
> churn.predbagging$error Output [1] 0.0451866