-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgbm.R
More file actions
29 lines (21 loc) · 642 Bytes
/
gbm.R
File metadata and controls
29 lines (21 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library(gbm)
library(dplyr)
train = sample(1:699, 300, replace = F)
test = -train
data = BreastCancer
cs = factor(BreastCancer$Class)
classes = as.numeric(cs)
classes[classes == 2] = 0
data = cbind(data, classes)
?gbm
data.train = data[train,]
data.test = data[-train,]
model = gbm.fit(x=data.train[,2:10], y = data.train[,12], n.trees = 5000, distribution = "bernoulli", shrinkage = 0.001, verbose = T)
summary(model)
best.iter = gbm.perf(model)
f.predict <- predict(model, data.test[, c(2:10,12)], best.iter)
f.predict[f.predict>0] = 1
f.predict[f.predict<0] = 0
data.test[,12][1:10]
f.predict[1:10]
table(data.test[,12],f.predict)