Some quick things in R

Part of a revelation I’ve had this past couple of months relates to how different programs are good at doing different things.

For instance, R is very intuitive and fast when it comes to doing classifications and projections. Here is how you would implement a Naive Bayes and K-NN in R.

naive Bayes in R :
make sure the columns for train and test have the same heading.
> train<-read.csv("train_7dim.csv")
> test<-read.csv("test_7dim.csv")
> dft <- data.frame(cbind(train,label))
> head(dft)
> dft$X0 <- as.factor(dft$X0)
> m<-naiveBayes(X0~.,dft)
> table(predict=predict(m, test))

k-nn in R :
> knn(train, test, label, k = 1, l = 0, prob = FALSE, use.all = TRUE)