计算置信区间
data = pd.read_csv(path)
# sample size
sample_size=100
# z-critical Score
z_critical=stats.norm.ppf(q=0.95)
# sampling the dataframe
data_sample=data.sample(n=sample_size, random_state=0)
# finding the mean of the sample
sample_mean=data_sample['SalePrice'].mean()
print(sample_mean)
# finding the standard deviation of the population
population_std=data['SalePrice'].mean()
print(population_std)
# finding the margin of error
margin_of_error=z_critical*population_std/10
# finding the confidence interval
lower_confidence_level=sample_mean-margin_of_error
upper_confidence_level=sample_mean+margin_of_error
confidence_interval=upper_confidence_level-lower_confidence_level
# finding the true mean
true_mean=data['SalePrice'].mean()
print(true_mean)
出现错误,表明下置信度区间和上置信度区间的值不正确!