0

How calculate variance?

Hello everyone, could you please where is there mistake. Text of task: Using the same vaccinations dataset, which includes the number of times people got the flu vaccine. The dataset contains the following numbers: never: 5 once: 8 twice: 4 3 times: 3 Calculate and output the variance. We will soon learn about easier ways to calculate the variance and other summary statistics using Python. For now, use Python code to calculate the result using the corresponding equation. My code: vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] #ваш код accum = 0 count = 0 for i in vac_nums: count = count + 1 accum = accum + 1 avg = accum / count variance = 0 for i in vac_nums: variance = variance + (avg - i)**2 variance = (variance / count) print(variance)

16th Jan 2022, 12:10 PM
Lyapunov Alexander
Lyapunov Alexander - avatar
3 Respuestas
+ 4
accum = accum + i
16th Jan 2022, 12:33 PM
Simba
Simba - avatar
0
Simba Thank you very much! You are right!
16th Jan 2022, 1:50 PM
Lyapunov Alexander
Lyapunov Alexander - avatar
0
vaccs = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3] mean = sum(vaccs)/len(vaccs) variance = (sum((v-mean)**2 for v in vaccs)/len(vaccs)) print(variance)
5th Dec 2022, 10:46 AM
Lavanya Mangala