# The MIT License (MIT)
#
# Copyright (c) <year> <copyright holders>
#  
#   Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#  
#   The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
 
# Kaggle τ → μμμ competition. Public leadearboard score 0.981817
 
#library(randomForest)
 
train <- read.csv("../input/training.csv")
test <- read.csv("../input/test.csv")

 
f <- signal ~ LifeTime + dira + FlightDistance + FlightDistanceError + IP + IPSig + VertexChi2 

# +
#              pt + DOCAone + DOCAtwo + DOCAthree+ IP_p0p2 + IP_p1p2 + isolationa + isolationb +
#              isolationc + isolationd + isolatione + isolationf + iso + CDF1 + CDF2 + CDF3 +
#              ISO_SumBDT + p0_IsoBDT + p1_IsoBDT + p2_IsoBDT + p0_track_Chi2Dof + p1_track_Chi2Dof +
#              p2_track_Chi2Dof + p0_IP + p1_IP + p2_IP + p0_IPSig + p1_IPSig + p2_IPSig + p0_pt +
#              p1_pt + p2_pt
 
# The terms below are omitted to avoid failing the agreement test
#      p0_p + p1_p + p2_p + p0_eta + p1_eta + p2_eta + SPDhits
 
# m <- randomForest(f, distribution="bernoulli", data = train, ntree=100, do.trace=50, importance=TRUE)
 
m <- glm(f , data=train, family=binomial) 
 
# test <- read.csv("../input/test.csv")
yp <- predict(m, type="response", newdata=test)
 
sub <- data.frame(id=test$id, prediction=yp)
write.csv(sub, "submission.csv", quote=F, row.names=F)