1
$\begingroup$

Page 24, Think Bayes by Allen B. Downey.

Can you explain me how he compute mean by this code :

def Mean(suite): 
    total = 0 
    for hypo, prob in suite.Items(): 
        total += hypo * prob 
    return total

I'm actually no idea about this. The prob is computed by sum and normalized. So result of Normalize is the part of mean? Thank you for your answer.

$\endgroup$
3
  • 1
    $\begingroup$ The code seems to be a direct translation of the definition $\text{mean}=\sum_{i=1}^n x_i p_i$. With equal probabilities this becomes $p_i=1/n$. $\endgroup$ Jul 1, 2018 at 19:04
  • $\begingroup$ Is it a pmf? Because the class suite inherits from Pmf() class so the way that I can compute mean is using this equation : $mean = ∑_{i=1}^n p_ix_i$ $\endgroup$ Jul 1, 2018 at 19:25
  • $\begingroup$ Yes, and your code seems to be a direct translation of that formula! $\endgroup$ Jul 1, 2018 at 19:57

1 Answer 1

1
$\begingroup$

I found more information that has an explanation and can answer my question on this website. It's very useful. Thank you very much @kjetil b halvorsen.

Visit : https://socratic.org/questions/how-do-you-use-a-probability-mass-function-to-calculate-the-mean-and-variance-of

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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