Skip to content

Commit 3048f56

Browse files
Update naive-bayes.md
Updating some of the markdown equations. Please consider and please also review this under GSSOC and give this updations some level.
1 parent 7ce4edc commit 3048f56

File tree

1 file changed

+22
-63
lines changed

1 file changed

+22
-63
lines changed

contrib/machine-learning/naive-bayes.md

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ $$
9393

9494
- Rain:
9595

96-
$$
97-
P(Rain|Yes) = \frac{2}{6}
98-
$$
96+
$$P(Rain|Yes) = \frac{2}{6}$$
9997

100-
$$
101-
P(Rain|No) = \frac{4}{4}
102-
$$
98+
$$P(Rain|No) = \frac{4}{4}$$
10399

104100
- Overcast:
105101

@@ -111,10 +107,7 @@ $$
111107
$$
112108

113109

114-
Here, we can see that
115-
$$
116-
P(Overcast|No) = 0
117-
$$
110+
Here, we can see that P(Overcast|No) = 0
118111
This is a zero probability error!
119112

120113
Since probability is 0, naive bayes model fails to predict.
@@ -124,13 +117,9 @@ Since probability is 0, naive bayes model fails to predict.
124117
In Laplace's correction, we scale the values for 1000 instances.
125118
- **Calculate prior probabilities**
126119

127-
$$
128-
P(Yes) = \frac{600}{1002}
129-
$$
120+
$$P(Yes) = \frac{600}{1002}$$
130121

131-
$$
132-
P(No) = \frac{402}{1002}
133-
$$
122+
$$P(No) = \frac{402}{1002}$$
134123

135124
- **Calculate likelihoods**
136125

@@ -151,21 +140,13 @@ Since probability is 0, naive bayes model fails to predict.
151140

152141
- **Rain:**
153142

154-
$$
155-
P(Rain|Yes) = \frac{200}{600}
156-
$$
157-
$$
158-
P(Rain|No) = \frac{401}{402}
159-
$$
143+
$$P(Rain|Yes) = \frac{200}{600}$$
144+
$$P(Rain|No) = \frac{401}{402}$$
160145

161146
- **Overcast:**
162147

163-
$$
164-
P(Overcast|Yes) = \frac{400}{600}
165-
$$
166-
$$
167-
P(Overcast|No) = \frac{1}{402}
168-
$$
148+
$$P(Overcast|Yes) = \frac{400}{600}$$
149+
$$P(Overcast|No) = \frac{1}{402}$$
169150

170151

171152
2. **Wind (B):**
@@ -181,49 +162,27 @@ Since probability is 0, naive bayes model fails to predict.
181162

182163
- **Weak:**
183164

184-
$$
185-
P(Weak|Yes) = \frac{500}{600}
186-
$$
187-
$$
188-
P(Weak|No) = \frac{200}{400}
189-
$$
165+
$$P(Weak|Yes) = \frac{500}{600}$$
166+
$$P(Weak|No) = \frac{200}{400}$$
190167

191168
- **Strong:**
192169

193-
$$
194-
P(Strong|Yes) = \frac{100}{600}
195-
$$
196-
$$
197-
P(Strong|No) = \frac{200}{400}
198-
$$
170+
$$P(Strong|Yes) = \frac{100}{600}$$
171+
$$P(Strong|No) = \frac{200}{400}$$
199172

200173
- **Calculting probabilities:**
201174

202-
$$
203-
P(PlayTennis|Yes) = P(Yes) * P(Overcast|Yes) * P(Weak|Yes)
204-
$$
205-
$$
206-
= \frac{600}{1002} * \frac{400}{600} * \frac{500}{600}
207-
$$
208-
$$
209-
= 0.3326
210-
$$
211-
212-
$$
213-
P(PlayTennis|No) = P(No) * P(Overcast|No) * P(Weak|No)
214-
$$
215-
$$
216-
= \frac{402}{1002} * \frac{1}{402} * \frac{200}{400}
217-
$$
218-
$$
219-
= 0.000499 = 0.0005
220-
$$
175+
$$P(PlayTennis|Yes) = P(Yes) * P(Overcast|Yes) * P(Weak|Yes)$$
176+
$$= \frac{600}{1002} * \frac{400}{600} * \frac{500}{600}$$
177+
$$= 0.3326$$
178+
179+
$$P(PlayTennis|No) = P(No) * P(Overcast|No) * P(Weak|No)$$
180+
$$= \frac{402}{1002} * \frac{1}{402} * \frac{200}{400}$$
181+
$$= 0.000499 = 0.0005$$
221182

222183

223184
Since ,
224-
$$
225-
P(PlayTennis|Yes) > P(PlayTennis|No)
226-
$$
185+
$$P(PlayTennis|Yes) > P(PlayTennis|No)$$
227186
we can conclude that tennis can be played if outlook is overcast and wind is weak.
228187

229188

@@ -366,4 +325,4 @@ print("Confusion matrix: \n",confusion_matrix(y_train,y_pred))
366325
## Conclusion
367326

368327
We can conclude that naive bayes may limit in some cases due to the assumption that the features are independent of each other but still reliable in many cases. Naive Bayes is an efficient classifier and works even on small datasets.
369-
328+

0 commit comments

Comments
 (0)