我们通常假设两个样本之间无显著差异作为原假设。
from scipy import stats
import numpy as np
data = [0.7922077922077922, 0.7922077922077922, 0.7748917748917749, 0.7229437229437229, 0.7878787878787878]
data = np.array(data)
mu = data.mean()
mu = mu - 0
t = mu / (np.std(data, ddof=1) / np.sqrt(len(data)))
p = (1 - stats.t.cdf(np.abs(t), len(data) - 1)) * 2
print("p值为:", p)
# test_res = stats.ttest_1samp(data, 0)
from scipy import stats
import numpy as np
score1 = [0.7922077922077922, 0.7922077922077922, 0.7748917748917749, 0.7229437229437229, 0.7878787878787878]
score2 = [0.7272727272727273, 0.6147186147186147, 0.70995670995671] # 两个样本长度不必相等
score1 = np.array(score1)
score2 = np.array(score2)
test_res = stats.ttest_ind(score1, score2)
print(test_res)
from scipy import stats
import numpy as np
score1 = [0.7922077922077922, 0.7922077922077922, 0.7748917748917749, 0.7229437229437229, 0.7878787878787878]
score2 = [0.7272727272727273, 0.6147186147186147, 0.70995670995671, 0.5887445887445888, 0.6536796536796536] # 两个样本长度必须相等
score1 = np.array(score1)
score2 = np.array(score2)
test_res = stats.ttest_rel(score1, score2)
print(test_res)