Perform the following steps to calculate and classify data with the gradient boosting method:
- First, install and load the package gbm:
> install.packages("gbm") > library(gbm)
- The gbm function only uses responses ranging from 0 to 1; therefore, you should transform yes/no responses to numeric responses (0/1):
> trainset$churn = ifelse(trainset$churn == "yes", 1, 0)
- Next, you can use the gbm function to train a training dataset:
> set.seed(2) > churn.gbm = gbm(formula = churn ~ .,distribution = "bernoulli" ,data = trainset,n.trees = 1000,interaction.depth = 7,shrinkage = 0.01, cv.folds=3)
- Then, you can obtain the summary information from the fitted model:
> summary(churn.gbm)