Kurtosis is a statistical metric and we can utilize it in Python with the help of “** scipy.stats.kurtosis**“. So, in this Python tutorial, we will learn about the “

**” with help of multiple examples. Moreover, we will cover the following topics.**

*Python Scipy Stats Kurtosis*- What is Kurtosis
- Python Scipy Stats Kurtosis
- Python Scipy Stats Kurtosis Test
- Python Scipy Stats Kurtosis Fisher
- Python Scipy Stats Kurtosis Nan_policy

Also, check the recent post on Python SciPy: Python Scipy Stats Mode with Examples

## What is kurtosis

Kurtosis is a statistical metric used to characterize how much data clusters in a frequency distribution’s tails or peak. The tails are the endpoints of the distribution, while the peak is its highest point.

- Kurtosis can be classified as mesokurtic, leptokurtic, or platykurtic.

The concept of kurtosis and how each kurtosis looks are given below.

distributions have curves with a medium peaked height and a moderate breadth.*Mesokurtic:*

** 2. Leptokurtic:** More values near the mean and more values at the tails of the distribution.

** 3. Platykurtic:** Fewer values near the mean and fewer values in the tails.

Read: Scipy Stats – Complete Guide

## Python Scipy Stats Kurtosis

Kurtosis is a factual measure that characterizes how vigorously the tails of distribution contrast from the tails of a normal distribution.

The Scipy has a method

that calculates the kurtosis of a given data set. The fourth central moment, when divided by the variance’s square, is known as kurtosis.*kurtosis()*

The syntax is given below.

`scipy.stats.kurtosis(a, axis=0, fisher=True, bias=True, nan_policy='propagate')`

Where parameters are:

It is array data whose kurtosis we want to calculate.*a(array_data):*It is used to specify along which axis we want to calculate the kurtosis, by default kurtosis is calculated on the whole array.*axis(int):*If it is true, then the fisher concept is used, otherwise Pearson concept is used.*fisher(boolean):*If False, statistical bias is taken into account while making the calculations.*bias(boolean):*It is used to deal with the nan values and accept three values:*nan_policy:*

It means calculating the*omit:*`IQR`

by ignoring the nan values.It means returns nan values.*propagate:*It means to throw an error for the nan values.*raise:*

The method

returns the kurtosis values as an array. The values it returns are -3 for the fisher concept and zero for the Pearson concept.*kurtosis()*

Let’s take an example by following the below steps:

Import the required libraries.

```
from scipy import stats
array_data = stats.norm.rvs(size=2000, random_state=2)
stats.kurtosis(array_data)
```

The value of kurtosis is close to zero as we can see in the above output.

Read: Scipy Stats – Complete Guide

## Python Scipy Stats Kurtosis test

In Scipy the method

is used to check whether the given data set has normal kurtosis or not.*kurtosistest()*

The syntax is given below.

`scipy.stats.kurtosistest(a, axis=0, nan_policy='propagate', alternative='two-sided')`

Where parameters are:

It is array data whose kurtosis we want to calculate.*a(array_data):*It is used to specify along which axis we want to calculate the kurtosis, by default kurtosis is calculated on the whole array.*axis(int):*It is used to deal with the nan values and accept three values:*nan_policy:*

It means calculating the*omit:*`IQR`

by ignoring the nan values.It means returns nan values.*propagate:*It means to throw an error for the nan values.*raise:*

The method `kurtosistest()`

returns two values statistics and p-value of type float.

Let’s take an example using the below code.

```
from scipy.stats import kurtosistest
kurtosistest(list(range(30)))
```

From the output, we can conclude whether the given data is normal kurtosis or not.

Read: Scipy Rotate Image + Examples

## Python Scipy Stats Kurtosis Fisher

We have already learned about the method

of Python Scipy and it has one parameter *kurtosis()*

of type boolean from several parameters. Fisher’s kurtosis measures a distribution’s tail-heaviness in relation to a normal distribution. *fisher*

A positive Fisher’s kurtosis indicates that there are substantial outliers in the distribution. If Fisher’s kurtosis is negative, the probability density distribution is substantially more uniform than it would be if it were normal.

- Mesokurtic distributions are those that have a Fisher kurtosis of zero or extremely near to zero. This category includes a distribution that is normal.
- Platypurtic distributions are those that have negative Fisher’s kurtosis and are flat-topped or uniform. E.g a uniform distribution.
- High-positivity distributions Leptokurtic distributions refer to Fisher’s kurtosis. According to the use case, leptokurtic distributions have outliers that may need to be handled or processed. They are “tail-heavy distributions.” Examples include Levy distribution and Laplace distribution.

So here we will tune the parameter

of the method *fisher*

through an example to see the change in result.**kurtosis()**

Import the required libraries using the below python code.

`from scipy import stats`

Generate an array of data containing 3000 values using the method

and calculate the kurtosis with parameter *norm.rvs()*

equal to *fisher*

.*True*

```
array_data = stats.norm.rvs(size=3000, random_state=3)
stats.kurtosis(array_data,fisher = True)
```

Now again calculate the kurtosis of the same data with the parameter

equal to *fisher*

.*False*

```
array_data = norm.rvs(size=3000, random_state=3)
stats.kurtosis(array_data,fisher = False)
```

When we set the

equal to *fisher*

, then the kurtosis for the data is -0.060, and for *True*

fisher value, the result is 2.93. When *False*

equal to *fisher*

, then Pearson kurtosis is calculated. That is why differences exist in the result.*False*

Read: Scipy Optimize – Helpful Guide

## Python Scipy Stats Kurtosis Nan_policy

The method

of Python Scipy accepts a parameter*kurtosis()*** ** to handle the nan values within the array. if we calculate the kurtosis of the array containing nan values, then the method

`nan_policy`

*kurtosis()*

returns nan as result by default.To handle these nan values within the array, we will use the different values for the parameter

of the method *nan_policy*

. The nan_polciy parameters accept three values to deal with nan values:*kurtosis()*

** omit:** It means calculating the

`IQR`

by ignoring the nan values.**It means returns nan values, and It is also by default value.**

*propagate:***It means to throw an error for the nan values.**

*raise:*Let’s understand with an example by following the below steps:

Import the required libraries using the below python code.

```
from scipy.stats import kurtosis
import numpy as np
```

Create an array containing nan values, to include the nan values within the array, we have used the

of Numpy using the below code.*np.nan*

`array_data = [2,4,5,6,2,6,8,5,np.nan,5,8,8]`

Compute the kurtosis of the above-created array without the parameter

using the below code.*nan_policy*

`kurtosis(array_data)`

Now, specify the parameter

with a value equal to *nan_policy *

using the below code.*omit*

`kurtosis(array_data,nan_policy = 'omit')`

Again change the parameter

with a value equal to *nan_policy *

using the below code.*propagate*

`kurtosis(array_data,nan_policy = 'propagate')`

At last change the parameter

with a value equal to *nan_policy *

using the below code.*raise*

`kurtosis(array_data,nan_policy = 'propagate')`

Refer to the concept of each parameter and see the output and how the nan value is handled.

You may also like to read the following Python SciPy tutorials.

- Python Scipy Special Module
- Python Scipy Eigenvalues
- Python Scipy ttest_ind
- Python Scipy Stats Poisson
- Python Scipy Distance Matrix
- Scipy Constants – Multiple Examples
- Python Scipy Stats Multivariate_Normal

So, in this tutorial, we have learned about the “** Python Scipy Stats Kurtosis**” and covered the following topics.

- What is Kurtosis
- Python Scipy Stats Kurtosis
- Python Scipy Stats Kurtosis Test
- Python Scipy Stats Kurtosis Fisher
- Python Scipy Stats Kurtosis Nan_policy

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.