Originally Posted by

**Andreea** I am programming this bayesian classifier using C. I have the feeling I'm doing something wrong. I will post the code here, could you take a look?

This is the KDE:

double estimantFDP(double x, double hn, double *bufVal, unsigned int n)

{

double val = 0;

double inv_hn = 1/hn;

unsigned int k;

for (k = 0; k < n; k++)

val += fctExp ((x-bufVal[k])/hn);

return (val*inv_hn/n);

}

//functia fereastra de tip exponential

double fctExp(double x)

{

return (exp(-x*x/2)/SQRT2PI);

}

This is the class function returner, where cateC1/cate is the prior probability P(F), x[0]=height, x[1]=weight, valoriX01= a buffer with female height values, X02 - male height, Y01 - female weight, Y02 - male weight:

int Bayes_Parzen_Classifier(double x[2], double *valoriX, double *valoriY)

{

double inm1, inm2,a;

inm1=(cateC1/cate) * estimantFDP(x[0], hn, valoriX01, n) * estimantFDP(x[1], hn, valoriY01, n);

inm2=(cateC2/cate) * estimantFDP(x[0], hn, valoriX02, n) * estimantFDP(x[1], hn, valoriY02, n);

if (inm1>inm2)

a=0;

else a=1;

printf("%lf\t%lf\t%lf\n",inm1,inm2,a);

return a;

}