开始使用免费开始使用

Normal sampling distributions

You'd like to estimate a realistic mean closing price for the S&P 500 over a subset of its trading history. This seems like a natural application of a confidence interval, since you have a sample statistic and want to use it to estimate a population statistic. However, your first step should be to check if the sampling distribution is approximately normal. In this exercise, you'll do exactly that. In the next exercise, you'll use this result to create your confidence interval.

The same data btc_sp_df has been loaded for you, as have the packages pandas as pd, NumPy as np and Matplotlib as plt.

本练习是课程的一部分

Foundations of Inference in Python

查看课程

练习说明

  • Define a variable num_samples as the desired number of samples (200), and define an empty list sample_means to store the mean from each of the 200 samples.
  • Write a for loop which will repeat the sampling process num_samples times.
  • Select 500 random S&P500 closing prices from the Close_SP500 column of btc_sp_df.
  • Compute the mean of each of these samples and store them in sample_means.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Define the number of samples to take and store the sample means
num_samples = ____
sample_means = ____

# Write a for loop which repeats the sampling num_samples times
for i in ____:
  # Select 500 random Close_SP500 prices 
  sp500_sample = np.___(____, size=____)
  # Compute mean closing price and save it to sample_means
  ____.append(____.mean())
    
plt.hist(sample_means)
plt.show()
编辑并运行代码