Recap: Polling a Town
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 23 of 64.
Challenge
MediumTime to poll the town about a new park. A poll reports a share of supporters, give or take a margin: 2 times the poll's .std() over the square root of its size. Do margins catch the truth? 25 polls of another town:
voters holds 1 per supporter, 0 for the rest; the program reads the poll size.
- Print the true support.
- Run 400 polls of different voters; print the first one's share and margin.
- Print how many margins hold the true support, and how many polls show 0.5 or less.
Shares and margins to 3 decimals. For that other town and 200:
True support: 0.52
First poll: 0.525, give or take 0.071
Margins that caught the truth: 384 of 400
Polls calling it wrong: 127Try it yourself
import numpy as np
size = int(input())
# Don't change the lines below: 1 for each voter who supports the park, 0 for the others
voters = np.concatenate([np.ones(10800), np.zeros(9200)])
rng = np.random.default_rng(23)
# Write your code below
All lessons in Statistics for ML
1Center and Spread
Mean and MedianPercentiles and QuartilesVariance and StdSample or Population?The Most Common ValueRecap: Delivery Times4Samples and Populations
Population and SampleSample Means VaryThe Sampling DistributionBigger Samples, Less NoiseRecap: Polling a Town2Distributions
Density HistogramsShapes of DataThe Normal CurveThe 68-95-99.7 RuleZ-ScoresRecap: Battery Life3Probability by Simulation
Probability as FrequencyThe Law of Large NumbersSums of DiceExpected ValueConditional ProbabilityRecap: Dice Stall Odds6Relationships
Reading Scatter PlotsCorrelationCorrelation MatrixCorrelation HeatmapsCorrelation Is Not CauseRecap: Ice Cream and SunPractice on your own: Online Python compiler