library(RODBC); channel <- odbcConnect("Postgre"); all5000 <- sqlQuery(channel, "select * from marketing_train limit 5000", nullstring=0,) levels(all5000[,"target_b"])<-c(0,1) train4000 <- all5000[1:4000,c((1:126,140:158,160:164)] levels(train4000[,"target_b"])<-c(0,1) nb <- NaiveBayes(target_b ~., train4000) test1000 <- all5000[4001:5000,c(1:126,140:158,160:164)] #test1000[,"target_b"] <- 0 pred<-predict(nb,test1000) write.csv(pred$posterior,"posterior4000-50000.txt") write.csv(all5000[4001:5000,],"real4000-5000.txt")