# You can write R code here and then click "Run" to run it on our platform

library(readr)
library(nnet)

# The competition datafiles are in the directory ../input
# Read competition data files:
train <- read_csv("../input/train.csv")
test <- read_csv("../input/test.csv")
predictions<-data.frame('C1'=NA, 'C2'=NA,'C3'=NA,'C4'=NA,'C5'=NA,'C6'=NA,'C7'=NA,'C8'=NA,'C9'=NA,'C0'=NA,Imageid=1:nrow(test),Label=NA)

# Generate output files with write_csv(), plot() or ggplot()
# Any files you write to the current directory get shown as outputs
inTrain=sample(1:nrow(train),1000)
label <- as.factor(train[inTrain,1])
train<-train[inTrain,-1]

mod1<-glm((label==1)~.,data=train,family=binomial(link=logit))
mod2<-glm((label==2)~.,data=train,family=binomial(link=logit))
mod3<-glm((label==3)~.,data=train,family=binomial(link=logit))
mod4<-glm((label==4)~.,data=train,family=binomial(link=logit))
mod5<-glm((label==5)~.,data=train,family=binomial(link=logit))
mod6<-glm((label==6)~.,data=train,family=binomial(link=logit))
mod7<-glm((label==7)~.,data=train,family=binomial(link=logit))
mod8<-glm((label==8)~.,data=train,family=binomial(link=logit))
mod9<-glm((label==9)~.,data=train,family=binomial(link=logit))
mod0<-glm((label==0)~.,data=train,family=binomial(link=logit))

predictions[,2]<-predict(mod1,test,type='response')
predictions[,3]<-predict(mod2,test,type='response')
predictions[,4]<-predict(mod3,test,type='response')
predictions[,5]<-predict(mod4,test,type='response')
predictions[,6]<-predict(mod5,test,type='response')
predictions[,7]<-predict(mod6,test,type='response')
predictions[,8]<-predict(mod7,test,type='response')
predictions[,9]<-predict(mod8,test,type='response')
predictions[,10]<-predict(mod9,test,type='response')
predictions[,1]<-predict(mod0,test,type='response')

predictions[,12]<-apply(predictions[,1:10],1,which.max)
predictions[,12]<-predictions[,12]-1

write_csv(predictions[,11:12], "multinom.csv")