Moments

In [7]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as sp
In [8]:
vals = np.random.normal(0, 0.5, 10000)
plt.hist(vals, 50)
plt.show()
output png

Moment I: Mean

The first moment is the mean.
This particular example should average out to about 0

In [9]:
np.mean(vals)
Out [9]:
0.0015974486926114652

Moment II: Variance

The spread between numbers in a dataset.

In [10]:
np.var(vals)
Out [10]:
0.2521335391838227

Moment III: Skew

How "lopsided" or "asymmetrical" a dataset's distribution is.
0 skew is symmetrical. Normal distributions have a 0 value.
Positive skew refers to data where the "right" side of the data beyond it's peak is longer than the left.
Negative skew refers to data where the "left" side of the data beyond it's peak is longer than the right.

In [11]:
sp.skew(vals)
Out [11]:
0.01600702657462597

Moment IV: kurtosis

The definition of Kurtosis seems a bit convoluted.
Kurtosis can help differentiate between distributions.
A dataset with normal distribution has a kurtosis value of 3. This is called mesokurtic.
A dataset with kurtosis > 3 are called leptokurtic. These have a longer tail than normal distributions. These are "pointier" at their peak.
Distributions with kurtosis < 3 are called platykurtic. These have even longer tails than leptokurtic, and are "broader" at their peak.
Kurtosis ranges from 1 to Infinity.

In [12]:
sp.kurtosis(vals)
Out [12]:
0.07101970704798699
Page Tags:
python
data-science
jupyter
learning
numpy