Calculating probabilities of two events F OUN DATION S OF P - - PowerPoint PPT Presentation

calculating probabilities of two events
SMART_READER_LITE
LIVE PREVIEW

Calculating probabilities of two events F OUN DATION S OF P - - PowerPoint PPT Presentation

Calculating probabilities of two events F OUN DATION S OF P ROBABILITY IN P YTH ON Alexander A. Ramrez M. CEO @ Synergy Vision Independence Given that A and B are events in a random experiment, the conditions for independence of A and B


slide-1
SLIDE 1

Calculating probabilities of two events

F OUN DATION S OF P ROBABILITY IN P YTH ON

Alexander A. Ramírez M.

CEO @ Synergy Vision

slide-2
SLIDE 2

FOUNDATIONS OF PROBABILITY IN PYTHON

Independence

Given that A and B are events in a random experiment, the conditions for independence of A and B are:

  • 1. The order in which A and B occur does not affect their probabilities.
  • 2. If A occurs, this does not affect the probability of B.
  • 3. If B occurs, this does not affect the probability of A.
slide-3
SLIDE 3

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-4
SLIDE 4

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-5
SLIDE 5

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-6
SLIDE 6

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-7
SLIDE 7

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-8
SLIDE 8

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-9
SLIDE 9

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-10
SLIDE 10

FOUNDATIONS OF PROBABILITY IN PYTHON

Measuring a sample

Generate a sample that represents 1000 throws of two fair coin ips

from scipy.stats import binom sample = binom.rvs(n=2, p=0.5, size=1000, random_state=1) array([1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 0, 0, 2, 2,...

Find repeated data

from scipy.stats import find_repeats find_repeats(sample) RepeatedResults(values=array([0., 1., 2.]), counts=array([249, 497, 254]))

slide-11
SLIDE 11

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-12
SLIDE 12

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-13
SLIDE 13

FOUNDATIONS OF PROBABILITY IN PYTHON

Measuring a biased sample

Using biased_sample data generated, calculate the relative frequency of each outcome

from scipy.stats import relfreq relfreq(biased_sample, numbins=3).frequency array([0.039, 0.317, 0.644])

slide-14
SLIDE 14

FOUNDATIONS OF PROBABILITY IN PYTHON

Joint probability calculation

Engine Gear box Fails 0.01 0.005 Works 0.99 0.995

P(Engine fails and Gear box fails) =?

P_Eng_fail = 0.01 P_GearB_fail = 0.005 P_both_fails = P_Eng_fail*P_GearB_fail print(P_both_fails) 0.00005

slide-15
SLIDE 15

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with cards

P(Jack or King) =?

slide-16
SLIDE 16

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with cards (Cont.)

P(Jack or King) = P(Jack) + ... P(Jack or King) = + ... 52 4

slide-17
SLIDE 17

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with cards (Cont.)

P(Jack or King) = P(Jack) + P(King) P(Jack or King) = + 52 4 52 4

slide-18
SLIDE 18

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with cards (Cont.)

P(Jack or King) = P(Jack) + P(King) P(Jack or King) = + = = 52 4 52 4 52 8 13 2

slide-19
SLIDE 19

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with cards (Cont.)

P(Jack or King) = P(Jack) + P(King) P(Jack or King) = + = = 52 4 52 4 52 8 13 2

slide-20
SLIDE 20

FOUNDATIONS OF PROBABILITY IN PYTHON

Probability of A or B

slide-21
SLIDE 21

FOUNDATIONS OF PROBABILITY IN PYTHON

Probability of A or B (Cont.)

slide-22
SLIDE 22

FOUNDATIONS OF PROBABILITY IN PYTHON

Probability of A or B (Cont.)

P(A or B) =?

slide-23
SLIDE 23

FOUNDATIONS OF PROBABILITY IN PYTHON

Probability of A or B (Cont.)

P(A or B) = P(A) + ...

slide-24
SLIDE 24

FOUNDATIONS OF PROBABILITY IN PYTHON

Probability of A or B (Cont.)

P(A or B) = P(A) + P(B)

slide-25
SLIDE 25

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap

P(Jack or Heart) =?

slide-26
SLIDE 26

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap (Cont.)

P(Jack or Heart) = P(Jack) + ... P(Jack or Heart) = + ... 52 4

slide-27
SLIDE 27

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap (Cont.)

P(Jack or Heart) = P(Jack) + P(Heart) ... P(Jack or Heart) = + ... 52 4 52 13

slide-28
SLIDE 28

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap (Cont.)

P(Jack or Heart) = P(Jack) + P(Heart)... P(Jack or Heart) = + ... 52 4 52 13

slide-29
SLIDE 29

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap (Cont.)

P(Jack or Heart) = P(Jack) + P(Heart) − P(Jack and Heart) P(Jack or Heart) = + − 52 4 52 13 52 1

slide-30
SLIDE 30

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A or B) with overlap (Cont.)

P(Jack or Heart) = P(Jack) + P(Heart) − P(Jack and Heart) P(Jack or Heart) = + − = = 52 4 52 13 52 1 52 16 13 4

slide-31
SLIDE 31

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B)

slide-32
SLIDE 32

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

slide-33
SLIDE 33

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) =?

slide-34
SLIDE 34

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) = P(A) + ...

slide-35
SLIDE 35

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) = P(A) + P(B) ...

slide-36
SLIDE 36

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) = P(A) + P(B) ...

slide-37
SLIDE 37

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) = P(A) + P(B) − P(A and B)

slide-38
SLIDE 38

FOUNDATIONS OF PROBABILITY IN PYTHON

Diagram of P(A or B) (Cont.)

P(A or B) = P(A) + P(B) − P(A and B)

slide-39
SLIDE 39

FOUNDATIONS OF PROBABILITY IN PYTHON

P(Jack or Heart) calculation in Python

P_Jack = 4/52 P_Hearts = 13/52 P_Jack_n_Hearts = 1/52 P_Jack_or_Hearts = P_Jack + P_Hearts - P_Jack_n_Hearts print(P_Jack_or_Hearts) 0.307692307692

slide-40
SLIDE 40

Let's calculate probabilities of two events

F OUN DATION S OF P ROBABILITY IN P YTH ON

slide-41
SLIDE 41

Conditional probabilities

F OUN DATION S OF P ROBABILITY IN P YTH ON

Alexander A. Ramírez M.

CEO @ Synergy Vision

slide-42
SLIDE 42

FOUNDATIONS OF PROBABILITY IN PYTHON

Dependent events

slide-43
SLIDE 43

FOUNDATIONS OF PROBABILITY IN PYTHON

Dependent events (Cont.)

P(Jack) = ≃ 7.69% 52 4

slide-44
SLIDE 44

FOUNDATIONS OF PROBABILITY IN PYTHON

Dependent events (Cont.)

P(Jack) = ≃ 5.88% 51 3

slide-45
SLIDE 45

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability formula

P(A and B) = P(A)P(B)

slide-46
SLIDE 46

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability formula (Cont.)

P(A and B) = P(A)P(B∣A) P(B∣A) = P(A) P(A and B)

slide-47
SLIDE 47

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability

slide-48
SLIDE 48

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) =?

slide-49
SLIDE 49

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = P(Jack) P(Jack and Red)

slide-50
SLIDE 50

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = P(Jack) P(Jack and Red)

slide-51
SLIDE 51

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = = P(Jack) P(Jack and Red)

52 4

X

slide-52
SLIDE 52

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = = P(Jack) P(Jack and Red)

52 4 52 2

slide-53
SLIDE 53

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = = = = P(Jack) P(Jack and Red)

52 4 52 2

4 2 2 1

slide-54
SLIDE 54

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Red∣Jack) = = = = P(Jack) P(Jack and Red)

52 4 52 2

4 2 2 1

slide-55
SLIDE 55

FOUNDATIONS OF PROBABILITY IN PYTHON

P(Red | Jack) calculation in Python

P_Jack = 4/52 P_Jack_n_Red = 2/52 P_Red_given_Jack = P_Jack_n_Red / P_Jack print(P_Red_given_Jack) 0.5

slide-56
SLIDE 56

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability

P(Jack∣Red) =?

slide-57
SLIDE 57

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = P(Red) P(Red and Jack)

slide-58
SLIDE 58

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = P(Red) P(Red and Jack)

slide-59
SLIDE 59

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = P(Red) P(Red and Jack)

slide-60
SLIDE 60

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = = P(Red) P(Red and Jack)

52 26

X

slide-61
SLIDE 61

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = = P(Red) P(Red and Jack)

52 26 52 2

slide-62
SLIDE 62

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = = = = P(Red) P(Red and Jack)

52 26 52 2

26 2 13 1

slide-63
SLIDE 63

FOUNDATIONS OF PROBABILITY IN PYTHON

Conditional probability (Cont.)

P(Jack∣Red) = = = = P(Red) P(Red and Jack)

52 26 52 2

26 2 13 1

slide-64
SLIDE 64

FOUNDATIONS OF PROBABILITY IN PYTHON

P(Jack | Red) calculation in Python

P_Red = 26/52 P_Red_n_Jack = 2/52 P_Jack_given_Red = P_Red_n_Jack / P_Red print(P_of_Jack_given_Red) 0.0769230769231

slide-65
SLIDE 65

Let's condition events to calculate probabilities

F OUN DATION S OF P ROBABILITY IN P YTH ON

slide-66
SLIDE 66

Total probability law

F OUN DATION S OF P ROBABILITY IN P YTH ON

Alexander A. Ramírez M.

CEO @ Synergy Vision

slide-67
SLIDE 67

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example

slide-68
SLIDE 68

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example (Cont.)

P(Face card) =?

slide-69
SLIDE 69

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example (Cont.)

P(Face card) = P(Club and Face card) + ...

slide-70
SLIDE 70

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example (Cont.)

P(Face card) = P(Club and Face card) + P(Spade and Face card) + ...

slide-71
SLIDE 71

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example (Cont.)

P(Face card) = P(Club and Face card) + P(Spade and Face card)+ P(Heart and Face card) + ...

slide-72
SLIDE 72

FOUNDATIONS OF PROBABILITY IN PYTHON

Deck of cards example (Cont.)

P(Face card) = P(Club and Face card) + P(Spade and Face card)+ P(Heart and Face card) + P(Diamond and Face card)

slide-73
SLIDE 73

FOUNDATIONS OF PROBABILITY IN PYTHON

Face card example in Python

T

  • tal probability calculation, FC is Face card in the code

P_Club_n_FC = 3/52 P_Spade_n_FC = 3/52 P_Heart_n_FC = 3/52 P_Diamond_n_FC = 3/52 P_Face_card = P_Club_n_FC + P_Spade_n_FC + P_Heart_n_FC + P_Diamond_n_FC print(P_Face_card)

The probability of a face card is:

0.230769230769

slide-74
SLIDE 74

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability

slide-75
SLIDE 75

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

slide-76
SLIDE 76

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) =?

slide-77
SLIDE 77

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V 1 and D) + ...

slide-78
SLIDE 78

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V 1 and D) + P(V 2 and D) + ...

slide-79
SLIDE 79

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V 1 and D) + P(V 2 and D) + P(V 3 and D)

slide-80
SLIDE 80

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V 1)P(D∣V 1) + P(V 2)P(D∣V 2) + P(V 3)P(D∣V 3)

slide-81
SLIDE 81

FOUNDATIONS OF PROBABILITY IN PYTHON

Damaged parts example in Python

A certain electronic part is manufactured by three different vendors, V1, V2, and V3. Half of the parts are produced by V1, and V2 and V3 each produce 25%. The probability of a part being damaged given that it was produced by V1 is 1%, while it's 2% for V2 and 3% for V3. What is the probability of a part being damaged?

slide-82
SLIDE 82

FOUNDATIONS OF PROBABILITY IN PYTHON

Damaged parts example in Python (Cont.)

What is the probability of a part being damaged?

P_V1 = 0.5 P_V2 = 0.25 P_V3 = 0.25 P_D_g_V1 = 0.01 P_D_g_V2 = 0.02 P_D_g_V3 = 0.03

slide-83
SLIDE 83

FOUNDATIONS OF PROBABILITY IN PYTHON

Damaged parts example in Python (Cont.)

We apply the total probability formula

P_Damaged = P_V1 * P_D_g_V1 + P_V2 * P_D_g_V2 + P_V3 * P_D_g_V3 print(P_Damaged)

The probability of being damaged is:

0.0175

slide-84
SLIDE 84

Let's start using the total probability law

F OUN DATION S OF P ROBABILITY IN P YTH ON

slide-85
SLIDE 85

Bayes' rule

F OUN DATION S OF P ROBABILITY IN P YTH ON

Alexander A. Ramírez M.

CEO @ Synergy Vision

slide-86
SLIDE 86

FOUNDATIONS OF PROBABILITY IN PYTHON

slide-87
SLIDE 87

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A and B) for independent events

P(A and B) = P(A)P(B)

slide-88
SLIDE 88

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A and B) for dependent events

P(A and B) = P(A)P(B) P(A and B) = P(A)P(B∣A)

slide-89
SLIDE 89

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A and B) for dependent events (Cont.)

P(A and B) = P(A)P(B) P(A and B) = P(A)P(B∣A) P(B and A) = P(B)P(A∣B)

slide-90
SLIDE 90

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A and B) is equal to P(B and A)

P(A and B) = P(A)P(B) P(A and B) = P(A)P(B∣A) P(B and A) = P(B)P(A∣B)

slide-91
SLIDE 91

FOUNDATIONS OF PROBABILITY IN PYTHON

P(A and B) is equal to P(B and A) (Cont.)

P(A and B) = P(A)P(B) P(A and B) = P(A)P(B∣A) P(B and A) = P(B)P(A∣B) P(A)P(B∣A) = P(A and B) = P(B and A) = P(B)P(A∣B)

slide-92
SLIDE 92

FOUNDATIONS OF PROBABILITY IN PYTHON

Bayes' relation

P(A and B) = P(A)P(B) P(A and B) = P(A)P(B∣A) P(B and A) = P(B)P(A∣B) P(A)P(B∣A) = P(A and B) = P(B and A) = P(B)P(A∣B) P(A)P(B∣A) = P(B)P(A∣B)

slide-93
SLIDE 93

FOUNDATIONS OF PROBABILITY IN PYTHON

Bayes' rule

P(A)P(B∣A) = P(B)P(A∣B) ⟹ P(A∣B) =

P(B) P(A)P(B∣A)

slide-94
SLIDE 94

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability

P(D) = P(V and D) + P(V and D) + P(V and D)

1 2 3

slide-95
SLIDE 95

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V and D) + P(V and D) + P(V and D) P(V and D) = P(V )P(D∣V ) P(V and D) = P(V )P(D∣V ) P(V and D) = P(V )P(D∣V ) P(D) = P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 2 3 1 1 1 2 2 2 3 3 3 1 1 2 2 3 3

slide-96
SLIDE 96

FOUNDATIONS OF PROBABILITY IN PYTHON

Total probability (Cont.)

P(D) = P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

slide-97
SLIDE 97

FOUNDATIONS OF PROBABILITY IN PYTHON

Bayes' formula

P(A∣B) = P(B) P(A)P(B∣A)

slide-98
SLIDE 98

FOUNDATIONS OF PROBABILITY IN PYTHON

Bayes' formula (Cont.)

Bayes' formula:

P(A∣B) =

The probability of a part being from vendor i, given that it is damaged:

P(V ∣D) = P(B) P(A)P(B∣A)

i

P(D) P(V )P(D∣V )

i i

slide-99
SLIDE 99

FOUNDATIONS OF PROBABILITY IN PYTHON

Bayes' formula (Cont.)

Bayes' formula:

P(A∣B) =

The probability of a part being from vendor i, given that it is damaged:

P(V ∣D) = P(V ∣D) = P(B) P(A)P(B∣A)

i

P(D) P(V )P(D∣V )

i i 1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-100
SLIDE 100

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-101
SLIDE 101

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-102
SLIDE 102

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-103
SLIDE 103

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-104
SLIDE 104

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-105
SLIDE 105

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-106
SLIDE 106

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-107
SLIDE 107

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

... P(V )P(D∣V )

1 1

slide-108
SLIDE 108

FOUNDATIONS OF PROBABILITY IN PYTHON

Visual representation of Bayes' rule (Cont.)

P(V ∣D) =

1

P(V )P(D∣V ) + P(V )P(D∣V ) + P(V )P(D∣V )

1 1 2 2 3 3

P(V )P(D∣V )

1 1

slide-109
SLIDE 109

FOUNDATIONS OF PROBABILITY IN PYTHON

Factories and parts example in Python

A certain electronic part is manufactured by three different vendors, V1, V2, and V3. Half of the parts are produced by V1, and V2 and V3 each produce 25%. The probability of a part being damaged given that it was produced by V1 is 1%, while it's 2% for V2 and 3% for V3. Given that the part is damaged, what is the probability that it was manufactured by V1?

slide-110
SLIDE 110

FOUNDATIONS OF PROBABILITY IN PYTHON

Factories and parts example in Python (Cont.)

Given that the part is damaged, get the probability that it was manufactured by V1.

P_V1 = 0.5 P_V2 = 0.25 P_V3 = 0.25 P_D_g_V1 = 0.01 P_D_g_V2 = 0.02 P_D_g_V3 = 0.03 P_Damaged = P_V1 * P_D_g_V1 + P_V2 * P_D_g_V2 + P_V3 * P_D_g_V3

slide-111
SLIDE 111

FOUNDATIONS OF PROBABILITY IN PYTHON

Factories and parts example in Python (Cont.)

P_V1_g_D = (P_V1 * P_D_g_V1) / P_Damaged # P(V1|D) calculation print(P_V1_g_D)

A randomly selected part which is damaged is manufactured by V1 with probability:

0.285714285714

slide-112
SLIDE 112

Let's exercise with Bayes

F OUN DATION S OF P ROBABILITY IN P YTH ON