• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

kristery May 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import os
2. import warnings
3. import numpy as np
4. from scipy import stats
5.
6.
7. significant_level = 0.05 # five percent significant level for one-sided t-test
8.
9. def hypothesis_test(*results):
10.     signif = [False] * len(results)
11.
12.     # choose the index with the maximum mean
13.     i_best = np.argmax([result.mean() for result in results])
14.
15.     for i in range(len((results))):
16.         if i == i_best:
17.             signif[i] = True
18.         else:
19.             signif[i] = [0]*len(results[i])
20.             if not np.array_equal(results[i], results[i_best]):
21.                 t_stat, p_ = stats.ttest_ind(results[i], results[i_best])
22.                 p = 0.5 * p_  # two-sided p-value -> one-sided p-value
23.                 signif[i] = p > significant_level
24.
25.     return signif
26.
27. # score of each method with 5 trials
28. method_1_scores = np.array([10, 11, 12, 14, 16])
29. method_2_scores = np.array([14, 21, 20, 17, 12])
30. method_3_scores = np.array([14, 15, 11, 14, 12])
31.
32. results = np.array([method_1_scores, method_2_scores, method_3_scores])
33. print(results)
34. print(hypothesis_test(*results))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top