Skip to content

Instantly share code, notes, and snippets.

View Alrecenk's full-sized avatar

Alrecenk Alrecenk

View GitHub Profile
@Alrecenk
Alrecenk / NaiveBayesExample.java
Created September 8, 2013 07:39
Naive Bayes Example Calculation
public double ProbabilityOfInputIfPositive(double in[]){
double prob = 1/Math.sqrt(2 * Math.PI) ;
for(int j=0; j<in.length;j++){
prob*= Math.exp(- (in[j]-posmean[j])*(in[j]-posmean[j]) / (2*posvariance[j]) ) ;
}
return prob ;
}
@Alrecenk
Alrecenk / NaiveBayesConstructor.java
Last active December 22, 2015 13:59
Naive Bayes Classifier Construction
//constructs a naive Bayes binary classifier
public NaiveBayes(double in[][], boolean out[]){
int inputs = in[0].length ;
//initialize sums and sums of squares for each class
double[] poss = new double[inputs], poss2 = new double[inputs];
double[] negs = new double[inputs], negs2 = new double[inputs];
//calculate amount of each class, sums, and sums of squares
for(int k=0;k<in.length;k++){//for each data point
if(out[k]){
positives++;//keep track of total positives