1
$\begingroup$

I would like some help with the maths and to check I have understood the algorithm correctly. So I’ve been learning off of a video and I tried my own example. At the end of it I got dodgy results; I think they are “dodgy” because my outputs are not between 0 and 1. If I went with the higher output then yes it has correctly classified my new data but I’m just not sure since the numbers are completely different. I tried by doing the math by hand with a calculator instead of with python but I still got a weird result, so it makes me think that my method is wrong.Here’s what I did, please have a look and tell me what you think:

# data 

x = [[65,50],

[62,49],

[130,78],

[124,79],

[54,47],            # the heights/weights of a child

[169,76],              (0), or an adult (1)

[59,58],

[169,79],

[52,52]]



y = [0,0,1,1,0,1,0,1,0]



new = [58, 54]

Okay so here’s what I think I should do:

  1. Work out the prior probability (in this case 5/9 children, 4/9 adults)

  2. Work out the means and variances for each feature and each class:

x̄(C,H) = 58.4 x̄(C,W) = 51.2

x̄(A,H) = 148 x̄(A,W) = 78

σ²(C,H) = 23.44 σ²(C,W) = 14.16

σ²(A,H) = 445.5 σ²(A,W) = 1.5

  1. Compute the Gaussians f(x,x̄, σ²):

    f(58, 58.4, 23.44) = 0.08212001659 (child height)

    f(54, 51.2, 14.16) = 0.08038037412 (child weight)

    f(58, 148, 445.5) = 2.129877168 x10(-6) (adult height)

    f(54, 78, 1.5) = 1.343766812 x10(-84) (adult weight)

  2. Multiply the Gaussians for the adult and child classes:

0.08212001659 x 0.08038037412 = 6.600837656 x10(-3) (child Gauss) 2.129877168 x10(-6) x 1.343766812 x10(-84) = 2.862058252 x10(-90) (adult Gauss)

  1. Calculate the probability using bayes theorem:

(child gauss x child prob)/(child gauss x child prob x adult gauss x adult prob) (adult gauss x adult prob)/(child gauss x child prob x adult gauss x adult prob)

(6.600837656 x10(-3) x 5/9)/(6.600837656 x10(-3) x 5/9 x 2.862058252 x10(-90) x 4/9) = 9.841633571 x10(89) (2.862058252 x10(-90) x 4/9)/(6.600837656 x10(-3) x 5/9 x 2.862058252 x10(-90) x 4/9) = 341.3788376

...so those were the final probabilities. If i went with the higher one which you are supposed to then the algorithm would've correctly classed the data as a child, but the probabilities were not between 0 and 1 which makes me think this method may not work for other data. I also ran the data through Scikit learn which classified the new data as a child also. Please let me know what you think and if i have been unclear about something, let me know in the comments.

$\endgroup$
2
$\begingroup$

You got the Bayes theorem wrong. There should be a plus in the denominator:

(child gauss x child prob)/(child gauss x child prob + adult gauss x adult prob)

(adult gauss x adult prob)/(child gauss x child prob + adult gauss x adult prob)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.