python绘制四分位数
import numpy as np
import random
import matplotlib.pyplot as plt
# 根据测量数据的最大值及最小值,在该区间内生成100个随机数据
data = [random.uniform(0.87, 0.76) for _ in range(100)]
q1 = np.percentile(data, 25)
q2 = np.percentile(data, 50)
q3 = np.percentile(data, 75)
plt.figure(figsize=(10, 5))
plt.boxplot(data, vert=False, patch_artist=True)
plt.axvline(q1, color='r', linestyle='--', label='Q1')
plt.axvline(q2, color='g', linestyle='--', label='Q2')
plt.axvline(q3, color='b', linestyle='--', label='Q3')
plt.legend()
plt.show()
python计算皮尔逊相关系数
import numpy as np
x = np.array([1.2, 1.1, 0.95, 0.97, 1.01])
y = np.array([0.33, 0.26, 0.78, 0.55, 0.62])
#计算皮尔逊相似度
correlation = np.corrcoef(x, y)
print(correlation[0, 1])
R语言
> patientID <- c(1,2,3,4)
> age <- c(25,34,28,52)
> diabetes <- c("Type1", "Type2", "Type1", "type1")
> status <- c("Poor", "Improved", "Excellent", "Poor")
> diabetes <- factor(diabetes)
> patientdata <- data.frame(patientID, age, diabetes, status)
> cor(patientID, age)
[1] 0.8006408
> str(patientdata)
'data.frame': 4 obs. of 4 variables:
$ patientID: num 1 2 3 4
$ age : num 25 34 28 52
$ diabetes : Factor w/ 3 levels "type1","Type1",..: 2 3 2 1
$ status : chr "Poor" "Improved" "Excellent" "Poor"
> summary(patientdata)
patientID age diabetes status
Min. :1.00 Min. :25.00 type1:1 Length:4
1st Qu.:1.75 1st Qu.:27.25 Type1:2 Class :character
Median :2.50 Median :31.00 Type2:1 Mode :character
Mean :2.50 Mean :34.75
3rd Qu.:3.25 3rd Qu.:38.50
Max. :4.00 Max. :52.00