Page 470 - AI Ver 3.0 class 10_Flipbook
P. 470

To calculate median in Python with even number of values:

                 [1]:   import statistics
                        marks=[40, 45,34,41,46,47,39,38,48,45,34,41,39,39]
                        m=statistics.median(marks)
                        print("the middle value of the sorted marks in class :",m)
                        the middle value of the sorted marks in class : 40.5

              Mode

              It is the most frequent value in a given dataset.

              There is no formula for this:
              Mode = The value in the data set that occurs most frequently

              To calculate mode in Python:

                 [1]:   import statistics
                        marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
                        m=statistics.mode(marks)
                        print("the most frequent marks :",m)
                        the most frequent marks : 39


              Standard Deviation

              It is the measure of dispersion of a set of data from its mean. The higher the dispersion of the data, the greater
              is the standard deviation and vice versa.
                                                      (x - mean) 2
                   The formula for calculation:   =
                                                         n
              To calculate Standard Deviation in Python:

                 [1]:   import statistics
                        marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
                        m=statistics.stdev(marks)
                        print("the standard deviation of marks :",round(m,2))
                        the standard deviation of marks : 4.66

              Variance


              It means how far each number in the given dataset is from the mean value. It is calculated as the average of the
              squares of the differences between an individual value and the expected value or average squared deviation of
              each number from the mean of a given data set.
                                                                           (x - μ) 2
              The formula for calculation for variance is:           2 =
                                                                            n
              To calculate Variance in Python:


                 [1]:   import statistics
                        marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
                        m=statistics.variance(marks)
                        print("the variance of marks :",round(m,2))

                        the variance of marks : 21.69


                    468     Touchpad Artificial Intelligence (Ver. 3.0)-X
   465   466   467   468   469   470   471   472   473   474   475