In: Computer Science
Given the names of employees in an office: employees = ["Jack", "Michael", "Tally", "John", "Jane", "Bill"]
1. Using the Random library in Python, create a codes that: Draws a random sample (with replacement) of 4 employees. Save and Displays the sample.
2. Explain what the difference is between a sample with replacement vs without replacement
Answer :-
2. difference between a sample with replacement vs without replacement
Sampling with replacement :
Sampling with replacement is a method of sampling where an item may
be sampled more than once.
Sampling with replacement generally produces independent events.
When we sample with replacement, the two sample values are independent. Practically, this means that what we get on the first one doesn't affect what we get on the second.
Mathematically, this means that the covariance between the two is zero.
example:- For given question sample may be ["Jack" , "John" , "John" , "Bill"] (In with replacement Here employee name john will repeat)
Sampling with out replament :
Sampling with out replacement is a method of sampling where an item
may not be sampled more than once.
sampling without replacement generally produces dependent events.
In sampling without replacement, the two sample values aren't independent. Practically, this means that what we got on the for the first one affects what we can get for the second one.
Mathematically, this means that the covariance between the two isn't zero.
example:- For given question sample may be ["Jack" , "John" , "Jane" , "Bill"] (In with out replacement Here employee name will not repeat)
1. Using the Random library in Python, create a codes that: Draws a random sample (with replacement) of 4 employees. Save and Displays the sample.
Answer :-
Python code :-
import random
employees = ["Jack", "Michael", "Tally", "John", "Jane", "Bill"] # given array
sample=[] # declare sample array
# Random sampling with replacement: random.choices() and k is
number of employees
sample = random.choices(employees, k=4)
print(sample) # print sample
Screenshot of code and output :-