pub-3785248829033902 | Python: Statistics #3 | - Big data with Python

| Python: Statistics #3 |

In the program below - we've tried to show resampling with replacement to estimate a confidence interval for the mean of a sample of size five: 


The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of statement for confidence interval in Python:

Æ’ python command

from statistics import mean
from random import choices
data = 2, 4, 6, 6, 12
means = sorted(mean(choices(data, k=5)) for i in range(20))
print(f'The sample mean of {mean(data):.1f} has a 90% confidence '     
f'interval from {means[1]:.1f} to {means[-2]:.1f}')

output

The sample mean of 6.0 has a 90% confidence interval from 4.4 to 8.4   


Previous
Next Post »