The likelihood function for the Bernoulli distribution based on data \(x_1, \ldots, x_N \sim\) Bernoulli(\(p\)) with unknown parameter \(p\) is

\[L(p | \mathbf{x}) = \prod_{n=1}^N p^{x_n} (1 - p)^{1 - x_n}\]

The log-likelihood function is

\[\ell(p | \mathbf{x}) = \log{ L(p | \mathbf{x}) } = \log{ \prod_{n=1}^N p_n^{x_n}(1 - p)^{1 - x_n} }\]

which simplifies to

\[\ell(p | \mathbf{x}) = \sum_{n=1}^N x_n \log{p} + (1 - x_n) \log{(1 - p)}\]

The derivative of \(\ell\) with respect to \(p\) is

\[\frac{d \ell}{dp} = \sum_{n=1}^N \frac{x_n}{p} - \frac{1 - x_n}{1-p}\]

Set the derivative equal to zero to get

\[\sum_{n=1}^N \frac{x_n}{p} = \sum_{n=1}^N \frac{1-x_n}{1-p}\]

Solve for \(p\) to find the maximum likelihood estimate of \(p\) based on data \(\mathbf{x}\)

\[\hat{p} = N^{-1} \sum_{n=1}^N x_n\]