Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

ML | Raw and Central Moments

  • Difficulty Level : Expert
  • Last Updated : 26 Jul, 2019

Moments are a set of statistical parameters which are used to describe different characteristics and feature of a frequency distribution i.e. central tendency, dispersion, symmetry, and peakedness (hump) of the frequency curve.

For Ungrouped data i.e. discrete data, observations on a variable X are obtained as x_1, x_2, x_3, ...., x_n, For Grouped data i.e. continuous data, observations on a variable X are obtained and tabulated in K class intervals in a frequency table. The mid points of the inervals are denoted by x_1, x_2, x_3, ...., x_n which occur with frequencies f_1, f_2, f_3, ...., f_n respectively and n=f_1, f_2, f_3, ...., f_n.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Class IntervalsMid Points (x_i)Absolute Frequency (f_i)
c_1 - c_2x_1 = (c_1 + c_2)/2f_1
c_2 - c_3x_2 = (c_2 + c_3)/2f_2
c_3 - c_4x_3 = (c_3 + c_4)/2f_3
c_k_-_1 - c_kx_k = (c_k_-_1 + c_k)/2f_k

Moments about an arbitrary point A
The r^t^h moment of a variable X about any arbitrary point A on the observations x_1, x_2, x_3, ...., x_n is defined as:



For ungrouped data  \mu^'_r = \frac{1}{n}\sum_{i=1}^{n}(x_i - A)^r

For grouped data  \mu^'_r = \frac{1}{n}\sum_{i=1}^{n}f_i(x_i - A)^r

where
 n = \sum_{i=1}^{k}f_i

 
Moment about any arbitrary point in Python –

Consider the given data points. Following are the time (in hours) spent by 20 different persons at GeeksforGeeks portal every week.

15, 25, 18, 36, 40, 28, 30, 32, 23, 22, 21, 27, 31, 20, 14, 10, 33, 11, 7, 13




# data points
time = [15, 25, 18, 36, 40, 28, 30, 32, 23, 22
        21, 27, 31, 20, 14, 10, 33, 11, 7, 13]
  
# Arbitrary point 
A = 22
  
# Moment for r = 1
moment = (sum([(item-A) for item in time]))/len(time)

Raw Moments –

The r^t^h moment around origin A = 0 known as raw moment and is defined as:

For ungrouped data, \mu^'_r = \frac{1}{n}\sum_{i=1}^{n}x_i^r
For grouped data,  \mu^'_r = \frac{1}{n}\sum_{i=1}^{n}f_i x_i^r

where, n = \sum_{i=1}^{k}f_i



Notes:

-> We can find first raw moment (\mu^'_1) just by replacing r with 1 and second raw moment (\mu^'_2) just by replacing r with 2 and so on.
-> When r = 0 the moment \mu^'_0 = 1 for both grouped and ungrouped data.

 
Raw moment in Python –




# data points
time = [15, 25, 18, 36, 40, 28, 30, 32, 23,
       22, 21, 27, 31, 20, 14, 10, 33, 11, 7, 13]
  
  
# Moment for r = 1
moment = sum(time)/len(time)

Central Moments –

The moments of a variable X about the arithmetic mean (\overline{x}) are known as central moments and defined as:

For ungrouped data,\mu_r = \frac{1}{n}\sum_{i=1}^{n}(x_i-\overline{x})^r

For grouped data,\mu_r = \frac{1}{n}\sum_{i=1}^{n}f_i (x_i-\overline{x})^r

where n = \sum_{i=1}^{k}f_i and  \overline{x} = \sum_{i=1}^{k}f_ix_i

Notes:

-> We can find first raw moment (\mu_1) just by replacing r with 1 and second raw moment (\mu_2) just by replacing r with 2 and so on.
-> When r = 0 the moment \mu_0 = 1, and when r = 1 the moment \mu_1 = 0 for both grouped and ungrouped data.




# data points
time = [15, 25, 18, 36, 40, 28, 30, 32, 23, 22,
       21, 27, 31, 20, 14, 10, 33, 11, 7, 13]
  
# Mean 
A = sum(time)/len(time)
  
# Moment for r = 1
moment = (sum([(item-A) for item in time]))/len(time)

 
Relationship between Raw and Central moments –




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!