1. 集中趋势 – 均值(Mean)
1.1 介绍
均值是统计学中用于衡量一组数据中心位置的指标,它表示数据的平均水平。
均值是描述数据集集中趋势的基本统计量之一。
1.2 原理
![图片[1]-二、描述统计学-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/10/image-191.png)
其中:
![图片[2]-二、描述统计学-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/10/image-190.png)
1.3 重点和注意事项
- 重点: 均值提供了数据集中心的一个重要指标,对于初步了解数据整体趋势非常有用。
- 注意事项:
- 均值对异常值敏感,极端值可能对均值产生较大影响。
- 在处理偏态分布的数据时,均值可能不是一个很好的代表。
1.4 完整案例
考虑一个案例:某城市一周内每天的气温。我们想计算这周每天气温的均值,并绘制直方图以展示数据分布。
数据:
气温数据:[25, 23, 26, 28, 30, 22, 24]
![图片[3]-二、描述统计学-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/10/image-192.png)
Python代码示例:
import numpy as np
import matplotlib.pyplot as plt
# 气温数据
temperature_data = np.array([25, 23, 26, 28, 30, 22, 24])
# 计算均值
mean_temperature = np.mean(temperature_data)
# 绘制直方图
plt.hist(temperature_data, bins=5, alpha=0.7, color='green', edgecolor='black', label='Temperature Distribution')
plt.axvline(mean_temperature, color='red', linestyle='dashed', linewidth=2, label='Mean')
# 添加标题和标签
plt.title('Temperature Distribution and Mean for Each Day of the Week')
plt.xlabel('Temperature')
plt.ylabel('Frequency')
# 添加图例
plt.legend()
# 显示图表
plt.show()
print("Mean temperature for each day of the week:", mean_temperature)
代码中使用 NumPy 计算气温的均值,并使用 Matplotlib 绘制直方图。直方图展示了一周内每天气温的分布情况,而红色虚线表示均值的位置。可以根据需要调整 bins 参数以更精细地控制直方图的细节。
![图片[4]-二、描述统计学-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/10/image-193.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END












请登录后查看评论内容