Last active
August 31, 2016 14:30
-
-
Save vascoosx/9b6a34f46407ac5c733eb1092a8cd39e to your computer and use it in GitHub Desktop.
hypothesis testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from functools import reduce | |
from sys import argv | |
def partial_fact(tries, success): | |
m = range(tries - success + 1, tries + 1) | |
return reduce((lambda x,y: x*y), m) | |
def fact(n): | |
return reduce((lambda x,y: x*y), range(1, n+1)) | |
def combs(tries, success): | |
return partial_fact(tries, success)/fact(success) | |
def pval(tries, success): | |
all_combs = 2**tries | |
return combs(tries, success) / all_combs | |
if __name__ == "__main__": | |
tries = int(argv[1]) | |
success = int(argv[2]) | |
print("probability of random prediction is: %.3f" % pval(tries, success)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment