Multimedia Application L7 - For
Multimedia Application L7 - For
Application
By
There are three types of Naive Bayes model under the scikit-learn library:
• Gaussian: It is used in classification and it assumes that features follow
a normal distribution.
• Multinomial: It is used for discrete counts. For example, let’s say, we
have a text classification problem. Here we can consider Bernoulli trials
which is one step further and instead of “word occurring in the
document”, we have “count how often word occurs in the document”,
you can think of it as “number of times outcome number x_i is observed
over the n trials”.
• Bernoulli: The binomial model is useful if your feature vectors are
binary (i.e. zeros and ones). One application would be text classification
with ‘bag of words’ model where the 1s & 0s are “word occurs in the
document” and “word does not occur in the document” respectively.
Example
Example solution
Solution:
P(A|B) = (P(B|A) * P(A) )/ P(B)
1. Mango:
P(X | Mango) = P(Ye | Yellow ) * P(Sweet | Mango) * P(Long | Mango)
a)P(Yellow | Mango) = (P(Mango | Yellow) * P(Yellow) )/ P (Mango)
= ((350/800) * (800/1200)) / (650/1200)
P(Yellow | Mango)= 0.53 →1
Text Classification
Input:
a document d
a fixed set of classes C = {c1, c2,…, cJ}
Output:
a learned classifier γ:d c
Classification Methods:
Supervised Machine Learning
Any kind of classifier
Naïve Bayes
Logistic regression
Support-vector machines
k-Nearest Neighbors
Naive Bayes Intuition
seen 2
sweet 1
γ whimsical
recommend
happy
1
1
1
)=c
( ... ...
Training
MAP is “maximum a
posteriori” = most
likely class
Bayes Rule
Dropping the
denominator
Text Classification and Naïve Bayes
Learning the Multinomial Naive Bayes Model
𝑁𝑐
^ (𝑐 )=
𝑃 𝑗
𝑗
𝑁 𝑡𝑜𝑡𝑎𝑙
Parameter estimation
Sentiment
Example:
A worked sentiment example with
add-1 smoothing
1. Prior from training:
^ (𝑐 )=
𝑃 𝑗
𝑁𝑐 𝑗 P(-) = 3/5
𝑁 𝑡𝑜𝑡𝑎𝑙
P(+) = 2/5
2. Drop "with"
3. Likelihoods from training:
𝑐𝑜𝑢𝑛𝑡 ( 𝑤 𝑖 , 𝑐 ) +1
𝑝 ( 𝑤 𝑖|𝑐 ) =
(∑ )
𝑐𝑜𝑢𝑛𝑡 (𝑤 ,𝑐 ) + ¿ 𝑉 ∨¿ ¿ 4. Scoring the test set:
𝑤 ∈𝑉
Optimizing for sentiment analysis
Theresa Wilson, Janyce Wiebe, and Paul Hoffmann (2005). Recognizing Contextual Polarity in
Phrase-Level Sentiment Analysis. Proc. of HLT-EMNLP-2005.
Riloff and Wiebe (2003). Learning extraction patterns for subjective expressions. EMNLP-2003.
Chapter 4
Question
Thank you