Implementing Naïve Bayes algorithm in Java - Need some guidance
Posted
by techventure
on Stack Overflow
See other posts from Stack Overflow
or by techventure
Published on 2010-05-22T12:49:37Z
Indexed on
2010/05/25
23:51 UTC
Read the original article
Hit count: 578
hello stackflow people
As a School assignment i'm required to implement Naïve Bayes algorithm which i am intending to do in Java.
In trying to understand how its done, i've read the book "Data Mining - Practical Machine Learning Tools and Techniques" which has a section on this topic but am still unsure on some primary points that are blocking my progress.
Since i'm seeking guidance not solution in here, i'll tell you guys what i thinking in my head, what i think is the correct approach and in return ask for correction/guidance which will very much be appreciated. please note that i am an absolute beginner on Naïve Bayes algorithm, Data mining and in general programming so you might see stupid comments/calculations below:
The training data set i'm given has 4 attributes/features that are numeric and normalized(in range[0 1]) using Weka (no missing values)and one nominal class(yes/no)
1) The data coming from a csv file is numeric HENCE
- * Given the attributes are numeric i use PDF (probability density function) formula.
- + To calculate the PDF in java i first separate the attributes based on whether they're in class yes or class no and hold them into different array
(array class yes and array class no)
- + Then calculate the mean(
sum of the values in row / number of values in that row
) and standard divination for each of the 4 attributes (columns) of each class- + Now to find PDF of a given value(n) i do
(n-mean)^2/(2*SD^2),
- + Then to find
P( yes | E)
and P( no | E)
i multiply the PDF value of all 4 given attributes and compare which is larger
, which indicates the class it belongs to In temrs of Java, i'm using ArrayList of ArrayList
and Double
to store the attribute values.
lastly i'm unsure how to to get new data? Should i ask for input file (like csv) or command prompt and ask for 4 values?
I'll stop here for now (do have more questions) but I'm worried this won't get any responses given how long its got. I will really appreciate for those that give their time reading my problems and comment.
© Stack Overflow or respective owner