Optional 💽
🖱️Right-click and select “Save link as” to download the exercise HERE 👈 so you can work on it locally on your computer
Hint
We need to find:
Define the Known Probabilities¶
We will start by defining the probabilities given in the problem statement.
# Probability that a structure is affected by corrosion
p_corrosion = 0.01 # 1 in 100
# Probability of a positive test result given that there is corrosion
p_positive_given_corrosion = 0.99 # 99% detection rate
# Probability of a positive test result given that there is no corrosion
p_positive_given_no_corrosion = 0.05 # 5% false positive rate
Calculate the Total Probability of a Positive Test Result¶
Next, we need to calculate the total probability of a positive test result, which includes both true positives and false positives.
Hint
## Write your code here
p_positive = ...
Apply Bayes’ Theorem¶
Now, we can apply Bayes’ theorem to find the probability that a structure is affected by corrosion given a positive test result.
## Write your code here
p_corrosion_given_positive = ...
Complete Code! 📃💻
Here’s the complete code that you would run in your PC:
p_corrosion = 0.01
p_positive_given_corrosion = 0.99
p_positive_give_no_corrosion = 0.05
p_positive = p_positive_given_corrosion * p_corrosion + p_positive_give_no_corrosion * (1 - p_corrosion)
p_corrosion_given_positive = p_positive_given_corrosion * p_corrosion / p_positive
print(f"P(corrosion|positive) = {p_corrosion_given_positive: .3f}")