Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import warnings
- import numpy as np
- from scipy import stats
- significant_level = 0.05 # five percent significant level for one-sided t-test
- def hypothesis_test(*results):
- signif = [False] * len(results)
- # choose the index with the maximum mean
- i_best = np.argmax([result.mean() for result in results])
- for i in range(len((results))):
- if i == i_best:
- signif[i] = True
- else:
- signif[i] = [0]*len(results[i])
- if not np.array_equal(results[i], results[i_best]):
- t_stat, p_ = stats.ttest_ind(results[i], results[i_best])
- p = 0.5 * p_ # two-sided p-value -> one-sided p-value
- signif[i] = p > significant_level
- return signif
- # score of each method with 5 trials
- method_1_scores = np.array([10, 11, 12, 14, 16])
- method_2_scores = np.array([14, 21, 20, 17, 12])
- method_3_scores = np.array([14, 15, 11, 14, 12])
- results = np.array([method_1_scores, method_2_scores, method_3_scores])
- print(results)
- print(hypothesis_test(*results))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement