EasyDeepLearn

Why do we compute Naive Bayes scores in log space?

easy

Answer

  • The product prodj\mathrm{prod}_{j} P(xj    c)P(x_{j}\; \mid \;c) can be astronomically small (underflow) when there are many features (e.g., thousands of words in a document).
  • Taking logs turns the product into a sum: log P(c)  +  sumjP(c)\; + \;\mathrm{sum}_{j} log P(xj    c)P(x_{j}\; \mid \;c).
  • Sums are numerically stable, and the argmax is preserved because log is monotonic.
  • All practical NB implementations work in log space.
Check yourself — multiple choice
  • To make training slower
  • Products underflow with many features; log-sums are numerically stable and preserve argmax
  • To make features Gaussian
  • So we can use gradient descent

Log-space avoids underflow when multiplying many small probabilities.

#naive-bayes#optimization

Practise Supervised Learning

215 interview questions in this topic.

Related questions