Merge pull request #315 from Vhizux/feature/condProb

Conditional probability
This commit is contained in:
Luke Weiler
2020-10-23 13:54:54 -04:00
committed by GitHub
4 changed files with 32 additions and 7 deletions

View File

@@ -135,4 +135,4 @@ problem, solution = mathgen.genById(0)
| 101 | Leap Year or Not | Year 2049 | is not a leap year | is_leap_year | | 101 | Leap Year or Not | Year 2049 | is not a leap year | is_leap_year |
| 102 | Minute to Hour conversion | Convert 960 minutes to Hours & Minutes | 16 hours and 0 minutes | minutes_to_hours | | 102 | Minute to Hour conversion | Convert 960 minutes to Hours & Minutes | 16 hours and 0 minutes | minutes_to_hours |
| 103 | Decimal to Binary Coded Decimal | BCD of Decimal Number 6561 is = | 19101 | decimal_to_bcd | | 103 | Decimal to Binary Coded Decimal | BCD of Decimal Number 6561 is = | 19101 | decimal_to_bcd |
| 104 | Circumference | Circumference of circle with radius 11 | 69.14285714285714 | circumference | | 104 | Circumference | Circumference of circle with radius 11 | 69.14285714285714 | circumference |

View File

@@ -110,3 +110,4 @@ from .minutes_to_hours import *
from .decimal_to_bcd import * from .decimal_to_bcd import *
from .circumference import * from .circumference import *
from .combine_like_terms import * from .combine_like_terms import *
from .conditional_probability import *

View File

@@ -0,0 +1,25 @@
from .__init__ import *
def conditionalProbFunc():
P_disease = round(2. * random.random(), 2)
true_positive = round(random.random() + float(random.randint(90, 99)), 2)
true_negative = round(random.random() + float(random.randint(90, 99)), 2)
def BayesFormula(P_disease, true_positive, true_negative):
P_notDisease = 100. - P_disease
false_positive = 100. - true_negative
P_plus = (P_disease) * (true_positive) + (P_notDisease) * (false_positive)
P_disease_plus = ((true_positive) * (100 * P_disease)) / P_plus
return P_disease_plus
problem = "Someone tested positive for a nasty disease which only {0:.2f}% of population have. " \
"Test sensitivity (true positive) is equal to SN= {1:.2f}% whereas test specificity (true negative) SP= {2:.2f}%. " \
"What is the probability that this guy really has that disease?".format(P_disease, true_positive, true_negative)
answer = str(round(BayesFormula(P_disease, true_positive, true_negative), 2)) + "%"
return problem, answer
conditionalProb = Generator("Conditional Probability", 101, "P(A|+)=", "c", conditionalProbFunc)

11
test.py
View File

@@ -2,13 +2,12 @@ from mathgenerator import mathgen
# test your generators here # test your generators here
print(mathgen.addition()) # print(mathgen.addition())
# prints each generator in genList # prints each generator in genList
list = mathgen.getGenList() # list = mathgen.getGenList()
for item in list: # for item in list:
print(item[2]) # print(item[2])
# print(mathgen.getGenList()) # print(mathgen.getGenList())
print(mathgen.decimal_to_roman_numerals()) print(mathgen.genById(101))
print(mathgen.genById(105))