Naive Bayes Classifier

Bayesian Networks related tools in R

Naive Bayes Classifier

Postby meninonas » Thu Dec 04, 2014 12:32 am

Hey everyone,


As seen below, the results of Naive Bayes Classifier is displayed. In order to achieve this, please do the following:

Since the Naive Bayes package is not installed, the following two commands will install and load it:

    install.packages("e1071")

    library(e1071)

Then, the following command will calculate NBC:

classifier<- naiveBayes(disease ~ weight + BP, mydata, laplace = 0, subset, na.action = na.pass)

The last command is explained as follow:

    In the naiveBayes command, it is important to note that the results are being saves as classifier (classifier<-)

    Then, within the command, you will place the formula, (disease ~ BP + weight) where ~ means =.

    After the comma, you tell the command the data you're basing the calculation on.

    The laplace=0 disables Laplace smoothing. The number can be increased if Laplace smoothing is desired.

    subset is for data given in a data frame, an index vector specifying the cases to be used in the training sample

    na.pass is a function to specify the action to be taken if NAs are found. The default action is not to count them for the computation of the probability factors. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable.

Results:

Naive Bayes Classifier for Discrete Predictors


Call:

naiveBayes.default(x = X, y = Y, laplace = laplace)


A-priori probabilities:

Y

0 1

0.47 0.53

Conditional probabilities:

weight

Y large small

0 0.06382979 0.93617021

1 0.75471698 0.24528302

BP
Y high low

0 0.12765957 0.87234043

1 0.01886792 0.98113208

P.S. In order for this to work properly, you must have a categorical dataset. The following links and attached files should work as a resource and a review:

http://en.wikipedia.org/wiki/Naive_Bayes_classifier

https://www.stat.berkeley.edu/~spector/R.pdf

http://ugrad.stat.ubc.ca/R/library/e107 ... Bayes.html

http://stackoverflow.com/questions/2009 ... ifier-in-r

https://stat.ethz.ch/R-manual/R-devel/l ... ct.lm.html

http://ugrad.stat.ubc.ca/R/library/e107 ... Bayes.html

http://www.stat.berkeley.edu/~s133/factors.html
Attachments
Categorical Dataset.txt
(1.2 KiB) Downloaded 144 times
klaR.pdf
(318.46 KiB) Downloaded 138 times
e1071.pdf
(497.78 KiB) Downloaded 133 times
meninonas
 
Posts: 137
Joined: Tue Jun 24, 2014 3:25 pm

Re: Naive Bayes Classifier

Postby meninonas » Wed Feb 25, 2015 7:17 pm

Dr. Yoo,

I ran Naive Bayes Classifier with the 25 Variable dataset and got the following results:

Code: Select all
Naive Bayes Classifier for Discrete Predictors

Call:
naiveBayes.default(x = X, y = Y, laplace = laplace)

A-priori probabilities:
Y
        0         1
0.5485961 0.4514039

Conditional probabilities:
   Luminal_B
Y        [,1]      [,2]
  0 0.4409449 0.4974805
  1 0.0000000 0.0000000

   Basal_like
Y        [,1]      [,2]
  0 0.3188976 0.4669694
  1 0.0000000 0.0000000

   HER2_enriched
Y        [,1]      [,2]
  0 0.2086614 0.4071541
  1 0.0000000 0.0000000

   Normal_like
Y         [,1]      [,2]
  0 0.03149606 0.1749989
  1 0.00000000 0.0000000

   NRF1
Y       [,1]      [,2]
  0 1.551181 0.7191196
  1 1.526316 0.7908894

   FIP1L1
Y       [,1]      [,2]
  0 1.492126 0.7583117
  1 1.444976 0.8367095

   CREB1
Y       [,1]      [,2]
  0 1.531496 0.7628945
  1 1.545455 0.7266168

   DHX9
Y       [,1]      [,2]
  0 1.488189 0.6012654
  1 1.650718 0.6559725

   CEP85
Y       [,1]      [,2]
  0 1.559055 0.7074258
  1 1.425837 0.8855151

   TTI1
Y       [,1]      [,2]
  0 1.519685 0.6140695
  1 1.454545 0.8080668

   SOS1
Y       [,1]      [,2]
  0 1.527559 0.6809291
  1 1.564593 0.7825562

   CASP2
Y       [,1]      [,2]
  0 1.429134 0.7391492
  1 1.531100 0.8146727

   GTF3C2
Y       [,1]      [,2]
  0 1.535433 0.6920814
  1 1.545455 0.7960787

   HNRNPA2B1
Y       [,1]      [,2]
  0 1.543307 0.6683814
  1 1.464115 0.8261963

   BRD2
Y       [,1]      [,2]
  0 1.500000 0.7478560
  1 1.454545 0.8139947

   KDM2A
Y       [,1]      [,2]
  0 1.421260 0.7436827
  1 1.421053 0.8231838

   PTBP1
Y       [,1]      [,2]
  0 1.539370 0.7253357
  1 1.440191 0.8590648

   UBAC2
Y       [,1]      [,2]
  0 1.409449 0.8085935
  1 1.478469 0.8030983

   SRSF2
Y       [,1]      [,2]
  0 1.515748 0.6636735
  1 1.449761 0.8312482

   RFC2
Y       [,1]      [,2]
  0 1.555118 0.6118990
  1 1.478469 0.8664503

   BIRC6
Y       [,1]      [,2]
  0 1.492126 0.7371676
  1 1.593301 0.7352087

   ARPC1A
Y       [,1]      [,2]
  0 1.370079 0.7781924
  1 1.531100 0.7784595

   EDRF1
Y       [,1]      [,2]
  0 1.425197 0.8053152
  1 1.545455 0.7839072

   SNRNP70
Y       [,1]      [,2]
  0 1.653543 0.6698233
  1 1.593301 0.7220118


Some of the probabilities are larger than 1. I believe this is so because some of the genes are not binary variables as they contain 0, 1, and 2. I'll check it tomorrow.
meninonas
 
Posts: 137
Joined: Tue Jun 24, 2014 3:25 pm

Re: Naive Bayes Classifier

Postby AdnanS2024 » Thu Apr 18, 2024 4:58 am

Beyond the practical aspects, bricklaying can be personally fulfilling, providing a sense of accomplishment and pride in creating something tangible and enduring. Dive into the comprehensive curriculum for courses of brick layer near me. From safety practices to masonry techniques, acquire foundational knowledge at the College of Contract Management.
AdnanS2024
 
Posts: 1
Joined: Thu Apr 18, 2024 4:57 am


Return to Bayesian Networks in R

Who is online

Users browsing this forum: No registered users and 1 guest