Understanding Medium Types | Set 2

This is one of the most important concepts in statistics, an essential subject for learning machine learning.

  • Geometric mean: As the arithmetic mean is the sum of all discrete values ​​in a set, the geometric mean is the product of discrete values ​​in a set. This is useful for a set of positive discrete values. 

    Example —

     Sequence = {1, 3, 9} product = 27 n, Total values ​​= 3 Harmonic Mean = (27) ^ (1/3) 

    Code —

    # Geometric mean

      

    import numpy as np

     
    # discrete set of numbers

    from scipy.stats.mstats import gmean

    x = gmean ([  1 , 3 , 9 ])

      
    # Greedy

    print ( "Geometric Mean is:" , x) 

    Output:

     Geometric Mean is: 3 
  • Harmonic Mean: Harmonic mean plays a role when it is necessary to calculate the average for terms that are defined in relation to any unit. This is the inverse of the mean of the inverse data. This is used when a reverse change in attitude is involved in the data. 

    Example —

     Sequence = {1, 3, 9} sum of reciprocals = 1/1 + 1/3 + 1/9 n, Total values ​​= 3 Harmonic Mean = 3 / ( sum of reciprocals) 

    Code —

    # Harmonic mean

     

    import numpy as np

     
    # discrete set of numbers

    from scipy.stats.mstats import hmean

    x = hmean ([ 1 , 3 , 9 ])

     
    # Greedy

    print ( "Harmonic Mean is:" , x) 

    Output:

     Harmonic Mean is: 2.076923076923077 
  • Relationship between arithmetic (AM), harmonic (HM) and geometric mean (GM):

    Example —

     Sequence = {1, 3, 9} sum of reciprocals = 1/1 + 1/3 + 1/9 Sum = 10 Product = 27 n, Total values ​​= 3  Arithmetic Mean < / strong> = 4.33  Geometric Mean  = 3  Harmonic Mean  = 3 / (sum of reciprocals) = 2.077