Home Â» How to Calculate Skewness & Kurtosis in Python

How to Calculate Skewness & Kurtosis in Python

In statistics,Â skewnessÂ andÂ kurtosisÂ are two ways to measure the shape of a distribution.

SkewnessÂ is a measure of the asymmetry of a distribution. This value can be positive or negative.

• A negative skew indicates that the tail is on the left side of the distribution, which extends towards more negative values.
• A positive skew indicates that the tail is on the right side of the distribution, which extends towards more positive values.
• A value of zero indicates that there is no skewness in the distribution at all, meaning the distribution is perfectly symmetrical.

KurtosisÂ is a measure of whether or not a distribution is heavy-tailed or light-tailed relative to a normal distribution.

• The kurtosis of a normal distribution is 3.
• If a given distribution has a kurtosis less than 3, it is said to beÂ playkurtic, which means it tends to produce fewer and less extreme outliers than the normal distribution.
• If a given distribution has a kurtosis greater than 3, it is said to beÂ leptokurtic, which means it tends to produce more outliers than the normal distribution.

Note:Â Some formulas (Fisherâ€™s definition) subtract 3 from the kurtosis to make it easier to compare with the normal distribution. Using this definition, a distribution would have kurtosis greater than a normal distribution if it had a kurtosis value greater than 0.

This tutorial explains how to calculate both the skewness and kurtosis of a given dataset in Python.

Example: Skewness & Kurtosis in Python

Suppose we have the following dataset:

```data = [88, 85, 82, 97, 67, 77, 74, 86, 81, 95, 77, 88, 85, 76, 81]
```

To calculate the sample skewness and sample kurtosis of this dataset, we can use the skew() andÂ kurt() functions from the Scipy Stata librarywith the following syntax:

• skew(array of values, bias=False)
• kurt(array of values, bias=False)

We use the argumentÂ bias=FalseÂ to calculate the sample skewness and kurtosis as opposed to the population skewness and kurtosis.

Here is how to use these functions for our particular dataset:

```data = [88, 85, 82, 97, 67, 77, 74, 86, 81, 95, 77, 88, 85, 76, 81]

#calculate sample skewness
skew(data, bias=False)

0.032697

#calculate sample kurtosis
kurtosis(data, bias=False)

0.118157
```

The skewness turns out to beÂ 0.032697 and the kurtosis turns out to beÂ 0.118157.

This means the distribution is slightly positively skewed and the distribution has more values in the tails compared to a normal distribution.

Additional Resource: Skewness & Kurtosis Calculator

You can also calculate the skewness for a given dataset using theÂ Statology Skewness and Kurtosis Calculator, which automatically calculates both the skewness and kurtosis for a given dataset.Â