mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
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
|
|
|
|
|
|
conditional_probability = Generator("Conditional Probability",
|
|
107, "P(A|+)=", "c", conditionalProbFunc)
|