featured work

Categories:

featured work

Content:

Text-To-Speech Expand to full view

Bayes Theorem in R

Bayes Theorem in R

I was thinking that we should do something useful right away. Bayes Theorem is a data algorithm for mining data. A good tutorial on the basic of this concept you can find here.

#reads in a table and creates a data frame that we call NewDisease
NewDisease = read.table("c:/temp/NewDisease.txt", header = T, sep="\t")
#creating the subsets
Sick = subset(NewDisease, NewDisease=="YES")
NotSick = subset(NewDisease, NewDisease=="NO")
#sets the dimension of the dataframe 
dim(Sick)[1]
dim(NotSick)[1]
#a vector for obtaining the elements of the vector being sampled
prob.Sick = colSums(Sick[,1:6]== "YES")/4
prob.NotSick  = colSums(NotSick[,1:6]== "NO")/6
#if(!require("e1071")) install.packages("e1071")
#Install the Naive Bayes module if needed uncomment the line below
#install.packages("e1071", dependencies = TRUE)
library(e1071)
#the arguments on the left side takes values to be predicted with the predictor on the right side
Classify = naiveBayes(NewDisease[1:10,1:6], 
                      NewDisease[1:10,7])         
Classify
#then we use the method predict
predict(Classify, NewDisease[11,1:6])


`p(X,C) = p(C)prod((n),(k))p(X|C)`

# We can also set multiple variable values and then as long as we got corresponding values for the equation
# what will do is divide the values in the print method
v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v/t)


Print Friendly and PDF

Please authenticate to bookmark

0 Votes (0) Average Rating
839 Views
Date Created 2016-10-16
Author : fb-fac3b0ok 
 
Report

There are no comments yet!


Sorry! You need to register and loggin before you can comment.