帮我改写下面的代码,是其结果不变但是表达方式不同:# 2、人体的温度是否服从正态分布? #分别用kstest、shapiro、normaltest来验证分布系数 from scipy import stats ks_test = stats.kstest(file['Temperature'], 'norm') shapiro_test = stats.shapiro(file['Temperature']) normaltest_test = stats.normaltest(file['Temperature'],axis=0) print('ks_test:',ks_test) print('shapiro_test:',shapiro_test) print('normaltest_test:',normaltest_test) # 绘制拟合正态分布曲线 Temperature = file['Temperature'] plt.figure() Temperature.plot(kind = 'kde') #原始数据的正态分布 M_S = stats.norm.fit(Temperature) #正态分布拟合的平均值loc,标准差 scale normalDistribution = stats.norm(M_S[0], M_S[1]) # 绘制拟合的正态分布图 x = np.linspace(normalDistribution.ppf(0.01), normalDistribution.ppf(0.99), 100) plt.plot(x, normalDistribution.pdf(x), c='orange') plt.xlabel('Temperature about Person') plt.title('Temperature on NormalDistribution', size=20) plt.legend(['Temperature', 'NormDistribution'])
时间: 2023-12-04 20:04:17 浏览: 29
下面是代码改写后的版本:
```
# 2、人体的温度是否服从正态分布?
# 分别使用 kstest、shapiro 和 normaltest 进行分布检验
from scipy import stats
# 使用 kstest 进行分布检验
ks_statistic, ks_pvalue = stats.kstest(file['Temperature'], 'norm')
print('ks_statistic:', ks_statistic)
print('ks_pvalue:', ks_pvalue)
# 使用 shapiro 进行分布检验
shapiro_statistic, shapiro_pvalue = stats.shapiro(file['Temperature'])
print('shapiro_statistic:', shapiro_statistic)
print('shapiro_pvalue:', shapiro_pvalue)
# 使用 normaltest 进行分布检验
normaltest_statistic, normaltest_pvalue = stats.normaltest(file['Temperature'], axis=0)
print('normaltest_statistic:', normaltest_statistic)
print('normaltest_pvalue:', normaltest_pvalue)
# 绘制拟合正态分布曲线
temperature = file['Temperature']
plt.figure()
temperature.plot(kind='kde')
# 绘制拟合的正态分布图
mu, sigma = stats.norm.fit(temperature)
norm_distribution = stats.norm(mu, sigma)
x = np.linspace(norm_distribution.ppf(0.01), norm_distribution.ppf(0.99), 100)
plt.plot(x, norm_distribution.pdf(x), c='orange')
plt.xlabel('Temperature of Person')
plt.title('Normal Distribution of Temperature', size=20)
plt.legend(['Temperature', 'Normal Distribution'])
```
注:主要的改动包括:变量名的修改、拆分 kstest、shapiro 和 normaltest 的输出、正态分布参数的获取方式等。