1. Learn
  2. /
  3. Courses
  4. /
  5. Sampling in Python

Exercise

Calculating relative errors

The size of the sample you take affects how accurately the point estimates reflect the corresponding population parameter. For example, when you calculate a sample mean, you want it to be close to the population mean. However, if your sample is too small, this might not be the case.

The most common metric for assessing accuracy is relative error. This is the absolute difference between the population parameter and the point estimate, all divided by the population parameter. It is sometimes expressed as a percentage.

attrition_pop and mean_attrition_pop (the mean of the Attrition column of attrition_pop) are available; pandas is loaded as pd.

Instructions 1/2

undefined XP
  • 1
    • Generate a simple random sample from attrition_pop of fifty rows, setting the seed to 2022.
    • Calculate the mean employee Attrition in the sample.
    • Calculate the relative error between mean_attrition_srs50 and mean_attrition_pop as a percentage.
  • 2
    • Calculate the relative error percentage again. This time, use a simple random sample of one hundred rows of attrition_pop.