library(readr)
library(e1071)
library(gbm)

# The competition datafiles are in the directory ../input
# List the files we have available to work with
system("ls ../input")

# Read competition data files:
train <- read_csv("../input/training.csv")
test <- read_csv("../input/test.csv")

# Remove some columns to pass the tests

#train[,"id"] <- NULL
#train[,"IPSig"] <- NULL
#train[,"mass"] <- NULL
#train[,"production"] <- NULL
#train[,"min_ANNmuon"] <- NULL
#train[,"SPDhits"] <- NULL
train <- train[,-which(names(train) %in% c("id","IPSig","mass","production","min_ANNmuon","SPDhits"))]

test <- test[,-which(names(test) %in% c("IPSig","mass","production","min_ANNmuon","SPDhits"))]

#test[,"mass"] <- NULL
#test[,"IPSig"] <- NULL
#test[,"production"] <- NULL
#test[,"min_ANNmuon"] <- NULL
#test[,"SPDhits"] <- NULL

# gbm model parameters are based on another script found around here
#nb <- naiveBayes(as.factor(signal) ~.,train)
gbM <- gbm(signal ~., "bernoulli", train, n.trees=200,interaction.depth=4,
           n.minobsinnode=10, shrinkage=0.1, bag.fraction=0.5, train.fraction=1)

# Predictions
#nb.pred <- predict(nb,test, type = "raw")
gbm.pred <- predict.gbm(gbM,test,type="response",n.trees=200)

# Weighted average
#test.probs <- (1*nb.pred[,2] + 12*gbm.pred)/13
test.probs <- gbm.pred

# Submission file
submission <- data.frame(id=test$id,prediction=test.probs)
write.csv(submission,"nb_gbm_submission.csv",row.names=F)

# Generate output files with write_csv(), plot() or ggplot()
# Any files you write to the current directory get shown as outputs