To solve a problem, the common ready libraries are used but we don’t search the function how to work and how to serve our purpose. More importantly, if we need to modify a function, we don’t know how to do that.

So, the purpose of this article is how to code bernoulli probability distributions and their some properties in a simple way, without using ready libraries like “SciPy” and gain some basic skills from scratch.

The bernoulli distribution is a discrete distribution that is used when a random experiment is performed and only two results are obtained such as good-bad, positive-negative, success-failure. Those statements are used to describe the probabilities of an event. Bernoulli trial is the simple way to represent an experiment like the outcome of a coin heads or tails, the result of an exam pass or failure, etc.

Probability Function

If X is a random variable and p is a probability of an event with this distribution, then:

Image for post

bernoulli probability mass function

Python Code:

#bernoulli probability mass function:

def pmf(x,p):
    f = p**x*(1-p)**(1-x)
    return f

#probability #scratch-programming #python

Bernoulli Distribution with Python from Scratch
3.95 GEEK