任务描述
Q1、人体体温的总体均值是否为98.6华氏度?
Q2、人体的温度是否服从正态分布?
Q3、人体体温中存在的异常数据是哪些?
Q4、男女体温是否存在明显差异?
Q5、体温与心率间的相关性(强?弱?中等?)
数据链接:https://pan.baidu.com/s/1t4SKF6U2yyjT365FaE692A*
笔者使用的是jupyter 进行的数据分析
#导入相关的库
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
#读入数据
file = pd.read_csv("test.csv")
#对查看数据前5行
file.head()
数据字段说明:
-
gender:性别,1为男性,2为女性
-
Temperature:体温
-
HeartRate:心率
Q1、人体体温的总体均值是否为98.6华氏度?
# 1、人体体温的总体均值是否为98.6华氏度?
file.describe()
file.groupby("Gender").mean()
从分析结果可以看出 无论是从总体的均值还是男女性别的均值都是小于 98.6华氏度的
Q2、人体的温度是否服从正态分布?
# 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'])
由于p >0.05, 接受原假设,认为数据服从正态分布
Q3、人体体温中存在的异常数据是哪些?
#3、人体体温中存在的异常数据是哪些? 3 sigma 原则
max_b = mean + 3 * std_
min_b = mean - 3 * std_
res = []
for i in file["Temperature"]:
if i >= max_b or i <= min_b:
res.append(i)
print("异常的数据有%d,分别是:",len(res))
for i in res:
print(i)
Q4、男女体温是否存在明显差异?
#男女体温是否存在明显差异
file.groupby('Gender').sum()
file.groupby("Gender").mean()
file.groupby("Gender").std()
没有发现什么差异
Q5、体温与心率间的相关性(强?弱?中等?)
#体温与心率间的相关性
file.corr()
根据:
·|r|≥0.8 高度相关;
·0.5≤|r|<0.8 中度相关;
·0.3≤|r|<0.5 低度相关;
·|r|<0.3 关系极弱,认为不相关
体温与心率间的相关系数为:0.253656 小于0.3 认为不想关