Last active
January 8, 2017 14:45
-
-
Save khrlimam/7d62edc47f35344fcea4624b399bab79 to your computer and use it in GitHub Desktop.
Get intuitive of how sample is important to a population data sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| population = [random.randint(70, 100) for n in range(100)] | |
| def comparePopulationMeanAndSampleMean(population, numberOfSample): | |
| populationMean = sum(population)/population.__len__() | |
| random.shuffle(population) | |
| sample = population[:numberOfSample] | |
| sampleMean = sum(sample)/sample.__len__() | |
| print "population mean: %s \nsample mean: %s" % (populationMean, sampleMean) | |
| def runTest(): | |
| # run 20 tests, change test respectively | |
| for i in range(20): | |
| #get number of samples that going to used, max is half of sample, minimal is 20 | |
| numberOfSample = random.randint(20, round(population.__len__()/2)) | |
| print "Test number %d, number of samples is %s, data taken randomly from population" % (i+1, numberOfSample) | |
| comparePopulationMeanAndSampleMean(population, numberOfSample) | |
| if __name__ == '__main__': | |
| print "data population", population | |
| runTest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment