How to Calculate the Probability of Normal Distribution using SciPy

Shiv Yadav Feb 15, 2024
  1. Normal Distribution
  2. Calculate the Probability of Normal Distribution Using SciPy
How to Calculate the Probability of Normal Distribution using SciPy

In this article, we will discuss the SciPy normal distribution. We will calculate the probability of normal distribution using SciPy.

Normal Distribution

First, let’s understand the normal distribution.

The normal distribution is a continuous probability distribution for a random variable with actual values. It is calculated using the mean and standard deviation.

The probability density function, sometimes known as the PDF, computes the likelihood of a single point in a distribution. The PDF is calculated by using this formula:

PDF Formula

Where μ is the mean and σ is the standard deviation of the distribution.

Calculate the Probability of Normal Distribution Using SciPy

To compute the probability density function of a particular distribution, we will utilize one of the scipy.stats.norm.pdf() methods.

The syntax of scipy.stats.norm.pdf() is given below:

scipy.stats.norm.pdf(data, loc, scale)

Where data is a collection of points or values representing equally sampled data in the form of array data, loc is the location of sample data (mean), and scale is a sample of standard deviation.

Let’s look at how to compute the pdf of a particular distribution using the methods below:

First, import the required libraries like this:

Importing Library

Then create an array to get random numbers. Here, we have created an array between -10 to 10 with a difference of 0.3 and stored it in an object x_arr.

Creating Array

Let’s get the mean and standard deviation values using the given random data.

Value of Mean and Standard Deviation

Now computing the pdf value using the norm method with loc=mean and scale=std.

Calculate PDF

Here, 5 is an array-like object whose probability is to be calculated.

Printing the calculated value of pdf:

Probability Value

Here is the complete code screenshot:

Code to Calculate Probability

This way, we can use the mean and standard deviation values to calculate the probability of normal distribution using the SciPy library.

Author: Shiv Yadav
Shiv Yadav avatar Shiv Yadav avatar

Shiv is a self-driven and passionate Machine learning Learner who is innovative in application design, development, testing, and deployment and provides program requirements into sustainable advanced technical solutions through JavaScript, Python, and other programs for continuous improvement of AI technologies.

LinkedIn