
library(data.table)

library(caret)

library(gbm)

library(gmp)
library(mlr)


library(matrixStats)
library(ROCR)

train<-fread("../input/train_numeric.csv",nrows=100000,select=c('L1_S24_F1846','L3_S33_F3855','L1_S24_F1723','L3_S32_F3850',
                                                'L3_S34_F3882','L1_S24_F1842','L1_S24_F1844','L3_S38_F3960','L3_S38_F3952','L3_S33_F3859','L3_S33_F3865','L3_S30_F3544',
                                                'L3_S29_F3430','L3_S29_F3324','L2_S26_F3040','L0_S13_F356','L3_S29_F3345','L3_S29_F3351','L3_S29_F3382','L0_S10_F229','L3_S30_F3749','L3_S29_F3373','L2_S26_F3106','L3_S30_F3809',
                                                'L1_S24_F1773','L1_S24_F867','L0_S10_F259','L0_S19_F455','L3_S30_F3609','L0_S0_F20','L3_S30_F3774','L3_S29_F3321','L1_S24_F1518','L3_S30_F3754',
                                                'L1_S24_F1829','Response'))

split <- sample(nrow(train),floor(nrow(train)*0.8))   
train1 <- train[split,]
test1 <- train[-split,]
rm(train)


label<-test1$Response




LogLossBinary = function(actual, predicted, eps = 1e-15) {  
  predicted = pmin(pmax(predicted, eps), 1-eps)  
  - (sum(actual * log(predicted) + (1 - actual) * log(1 - predicted))) / length(actual)
}








gbmModel = gbm(formula = Response ~.,
               
               data = train1,
               n.trees = 2500,
               shrinkage = .01,
               n.minobsinnode = 20)



gbmTestPredictions = predict(object = gbmModel,
                             newdata = test1,
                             n.trees = 2500,
                             type = "response")


pred_val <-prediction(gbmTestPredictions,label)
perf_val <- performance(pred_val,"auc")
perf_val
jpeg('rplot.jpg')
plot(performance(pred_val, measure="lift", x.measure="rpp"), colorize=TRUE)
dev.off()


perf_val <- performance(pred_val, "tpr", "fpr")
#Plot the ROC curve
jpeg('rplot1.jpg')
plot(perf_val, col = "green", lwd = 1.5)
dev.off()






