cancer <- read.csv('breast-cancer-wisconsin.data', header = FALSE, na.strings="?")
cancer <- cancer[complete.cases(cancer),]
names(cancer)[11] <- "class"
cancer[, 11] <- factor(cancer[, 11], labels = c("benign", "malignant"))
library(gbm)
Firstly, I remove 'NA' values using complete.cases and make the eleventh column, the "class", as factor. I want to use "class" as the response variable and other columns, except the first one, as predictor variables.
On my first attempt, I typed in:
boost.cancer <- gbm(class ~ .-V1, data = cancer, distribution = "bernoulli")
Error in gbm.fit(x, y, offset = offset, distribution = distribution, w = w, :
Bernoulli requires the response to be in {0,1}
Then, I use the contrasts of the class instead of class.
boost.cancer <- gbm(contrasts(class) ~ .-V1, distribution = "bernoulli", data = cancer)
Error in model.frame.default(formula = contrasts(class) ~ . - V1, data = cancer, :
variable lengths differ (found for 'V1')
How do I correct these errors? I'm sure there is something wrong with my method.