Bernoulli Distribution
The Bernoulli distribution is a discrete probability distribution that models the outcome of a binary experiment, that is, an experiment with two possible outcomes such as heads or tails, success or failure, yes or no, etc.
It has only two possible outcomes, labeled as 1 (success) and 0 (failure), with probability of success denoted by p and probability of failure denoted by (1  p). The Bernoulli distribution is defined by a single parameter p, which can range from 0 to 1, inclusive.
The probability mass function (PMF) of a Bernoulli distribution is given by:
P(X = x) = p^x * (1  p)^(1x), for x = 0, 1
The mean (expected value) of a Bernoulli distribution is given by:
E(X) = p
The variance of a Bernoulli distribution is given by:
Var(X) = p * (1  p)
The Bernoulli distribution is a special case of the binomial distribution, where the number of trials is equal to 1.
Here are a few examples of using the Bernoulli distribution:

Tossing a fair coin: Consider a fair coin with heads (success) and tails (failure). The Bernoulli distribution can be used to model the outcome of a single coin toss, with p = 0.5 (the probability of getting heads). The PMF of this distribution would be: P(Heads) = 0.5 and P(Tails) = 0.5.

Clickthrough rate: In online advertising, the Bernoulli distribution can be used to model the probability of a user clicking on an ad. Let's say the probability of a user clicking on an ad is p = 0.1. Then, the PMF would be: P(Click) = 0.1 and P(No click) = 0.9.

Customer purchase: In marketing, the Bernoulli distribution can be used to model the probability of a customer making a purchase. Let's say the probability of a customer making a purchase is p = 0.7. Then, the PMF would be: P(Purchase) = 0.7 and P(No purchase) = 0.3.
These are just a few examples of how the Bernoulli distribution can be used in various realworld applications.
Here's an implementation of the Bernoulli distribution in Python:
import numpy as np
import matplotlib.pyplot as plt
def bernoulli_pmf(p, x):
return p**x * (1  p)**(1x)
p = 0.7
x = [0, 1]
pmf = [bernoulli_pmf(p, i) for i in x]
plt.bar(x, pmf)
plt.xlabel("Outcome")
plt.ylabel("Probability")
plt.show()
This code defines a function bernoulli_pmf that takes two arguments: p, the probability of success, and x, the outcome of the binary experiment (0 or 1). The function returns the probability of the given outcome using the Bernoulli PMF formula. The code also defines p as 0.7, which is the probability of success, and x as a list of two possible outcomes [0, 1]. The PMF is then calculated for each outcome using a list comprehension, and the results are plotted using the matplotlib library. The resulting bar graph shows the probability of each outcome.