mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Merge pull request #315 from Vhizux/feature/condProb
Conditional probability
This commit is contained in:
@@ -135,4 +135,4 @@ problem, solution = mathgen.genById(0)
|
||||
| 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 |
|
||||
| 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 |
|
||||
@@ -110,3 +110,4 @@ from .minutes_to_hours import *
|
||||
from .decimal_to_bcd import *
|
||||
from .circumference import *
|
||||
from .combine_like_terms import *
|
||||
from .conditional_probability import *
|
||||
25
mathgenerator/funcs/conditionalProbability.py
Normal file
25
mathgenerator/funcs/conditionalProbability.py
Normal 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
11
test.py
@@ -2,13 +2,12 @@ from mathgenerator import mathgen
|
||||
|
||||
# test your generators here
|
||||
|
||||
print(mathgen.addition())
|
||||
# print(mathgen.addition())
|
||||
|
||||
# prints each generator in genList
|
||||
list = mathgen.getGenList()
|
||||
for item in list:
|
||||
print(item[2])
|
||||
# list = mathgen.getGenList()
|
||||
# for item in list:
|
||||
# print(item[2])
|
||||
|
||||
# print(mathgen.getGenList())
|
||||
print(mathgen.decimal_to_roman_numerals())
|
||||
print(mathgen.genById(105))
|
||||
print(mathgen.genById(101))
|
||||
Reference in New Issue
Block a user