mardi 31 août 2021

Create Dummy Population for Sampling

I have to create a function that generates a population of 5,000 individuals and returns the mean and standard deviation of how many times per day they pick-up their phone. Later in the assignment, I'll have to use this dummy data to extract a sample of 30 individuals, though I need help with the first part before I can move on to the sampling. Here is the given test code that gave me a hint on how to start:

pop_pickups, pop_mean, pop_std = get_population(45, 5000, 42)
assert np.abs(pop_mean - 45) < 0.5, "Get population problem, testing pop_mean, population mean returned does not match expected population mean"
assert np.abs(pop_std - np.sqrt(45)) < 0.5, "Get population problem, testing pop_std, population standard deviation returned does not match expected standard deviation"

I have the idea that the function will look something like:

def get_population(pickups, pop_size, std):

and that I may need to use the np.random.randint method to start, but I am really not sure where to go from there or if that's correct. I'm not clear on how to assign a random number to a fake sample (e.g. number of pickups per individual).




Aucun commentaire:

Enregistrer un commentaire