CODE.docx - R code For NavieBayes Classifier library(readxl dav < read_excel\"C\/Users\/Manoj SN\/Desktop\/New folder\/Docx\/Data Mining\/tic-tac-toe.data

CODE.docx - R code For NavieBayes Classifier library(readxl...

This preview shows page 1 - 3 out of 7 pages.

R code For NavieBayes Classifier: library(readxl) dav <- read_excel("C:/Users/Manoj SN/Desktop/New folder/Docx/Data Mining/tic-tac-toe.data.xlsx") summary(dav) dav[sapply(dav, is.character)] <- lapply(dav[sapply(dav, is.character)], as.factor) #To display the no of class labels table(dav$Class) data <- sample(2, nrow(dav), replace =TRUE, c(0.60, 0.40) ) #creating Training dataset trainD <- dav[data==1,] testD <- dav[data==2,] nrow(trainD) nrow(testD) # creating the navie bayes model library(e1071) library(rminer) e1071model <- naiveBayes(Class ~. ,data=trainD) e1071model #Testing the Naive Bayes model
Image of page 1
e1071prediction <- predict(e1071model, testD) mmetric(testD$Class, e1071prediction, c("ACC", "PRECESSION", "TPR", "F1")) OUTPUTS: library(readxl) > dav <- read_excel("C:/Users/Manoj SN/Desktop/New folder/Docx/Data Mining/tic-tac-toe.data.xlsx") > summary(dav) top-left-square top-middle-square top-right-square middle-left-square middle-middle-square middle-right-squa Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.: Median :2.000 Median :2.000 Median :2.000 Median :2.000 Median :2.000 Median :2.000 Med Mean :1.778 Mean :1.866 Mean :1.778 Mean :1.866 Mean :1.689 Mean :1.866 Mean 3rd Qu.:2.000 3rd Qu.:3.000 3rd Qu.:2.000 3rd Qu.:3.000 3rd Qu.:2.000 3rd Qu.:3.000 3rd Qu Max. :3.000 Max. :3.000 Max. :3.000 Max. :3.000 Max. :3.000 Max. :3.000 Max. :3.00 bottom-middle-square bottom-right-square Class Min. :1.000 Min. :1.000 Length:958 1st Qu.:1.000 1st Qu.:1.000 Class :character Median :2.000 Median :2.000 Mode :character Mean :1.866 Mean :1.778 3rd Qu.:3.000 3rd Qu.:2.000 Max. :3.000 Max. :3.000 > dav[sapply(dav, is.character)] <- lapply(dav[sapply(dav, is.character)], as.factor) > #To display the no of class labels > table(dav$Class) negative positive 332 626 > data <- sample(2, nrow(dav), replace =TRUE, c(0.60, 0.40) ) > #creating Training dataset > trainD <- dav[data==1,] > testD <- dav[data==2,] > nrow(trainD) [1] 562 > nrow(testD) [1] 396 > # creating the navie bayes model > library(e1071) > library(rminer) > e1071model <- naiveBayes(Class ~. ,data=trainD)
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 7 pages?

  • Winter '17
  • sathya raja shekaran

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors