0
$\begingroup$

I would really appreciate if anyone you can explain how it went from step 1 to the answer provided below. This is from the book Doing Data Science by Cathy O'Neil and Rachel Schutt pages 101 to 102.

I have provided my answers with the steps I took to get there.

$p(x|c) = \Pi_j\theta_{jc}^{x_j}(1-\theta_{jc})^{(1-x_j)}$

Take ln both sides:

$ln(p(x|c)) = ln(\Pi_j\theta_{jc}^{x_j}(1-\theta_{jc})^{(1-x_j)})$

Known:

$\Pi_j \theta_{jc}^{x_j} = \theta_{jc}^{(\sum_{j} x)}$

$\Pi_j(1-\theta_{jc})^{(1-x_j)} = (1-\theta_{jc})^{n - \sum_j x}$

Substitute the known into the equations:

$ln(p(x|c)) = ln(\theta_{jc}^{(\sum_{j} x)} * (1-\theta_{jc})^{n - \sum_j x})$

Expand the muliplication:

$ ln(p(x|c)) = ln(\theta_{jc}^{(\sum_{j} x)}) + ln((1-\theta_{jc})^{n - \sum_j x})$

Simply:

$ln(p(x|c)) = (\sum_{j} x)ln(\theta_{jc}) + ({n - \sum_j x})ln(1-\theta_{jc})$

$ln(p(x|c)) = (\sum_{j} x)ln(\theta_{jc}) - (\sum_j x)ln(1-\theta_{jc}) + (n)ln(1-\theta_{jc})$

My answer:

$ln(p(x|c)) = (\sum_{j} x)ln(\frac{\theta_{jc}}{1-\theta_{jc}}) + (n)ln(1-\theta_{jc})$

Text book answer:

$ln(p(x|c)) = (\sum_j x_j) ln(\frac{\theta_j}{1-\theta_j}) + \sum_j log(1-\theta_j)$

Thanks in advance!

$\endgroup$
  • $\begingroup$ Welcome to CrossValidated! To make your question more interesting to those who might answer it, you may find it helpful to provide some context to start. Something like a restatement of the actual problem/exercise might help, and (if possible) some note about why the quesion is interesting as more than an exercise in symbol manipulation. $\endgroup$ – David C. Norris Sep 6 at 8:26
2
$\begingroup$

I don't have access to the book, but I think you've some typos in its answer. The parentheses should cover both $x_j$ and the $\ln$ term because outside we have no $j$ index. Also, we have $\theta_{jc}$, not $\theta_j$.

If we start from taking log of both sides, $$\begin{align}p(x|c)&=\sum_{j}\ln(\theta_{jc}^{x_j}(1-\theta_{jc})^{1-x_j})\\&=\sum_jx_j(\ln\theta_{jc}+(1-x_j)\ln(1-\theta_{jc})) \\&=\sum_j x_j\ln \left(\frac{\theta_{jc}}{1-\theta_{jc}}\right)-\sum_j \ln(1-\theta_{jc}) \end{align}$$

Your mistakes start from the "Known" section, e.g. $$\prod_j\theta_{jc}^{x_j}\neq\theta_{jc}^{\sum_j x_j}$$ because $\theta_{jc}$ is dependent on $j$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.