Page 266 - AI Computer 10
P. 266
To calculate median in Python:
import statistics
num = [10,20,30,40,50,60,70,80]
m = statistics.median(num)
print(“The middle of the set of numbers is:”, m)
Output:
The middle of the set of numbers is: 45.0
u Mode: The mode is that value of observation which occurs most frequently. We can calculate the Mode
using the following formula:
where:
• L is the lower class boundary of the modal group
• f m-1 is the frequency of the group before the modal group
• f m is the frequency of the modal group
• f m+1 is the frequency of the group after the modal group
• w is the group width.
To calculate mode in Python:
import statistics
num = [10,20,30,40,50,60,60,70,70,70,80]
m = statistics.mode(num)
print(“The most frequent number is:”, m)
Output:
The most frequent number is: 70
u Variance: The term “Variance” is defined as, “The average of the squared
differences from the Mean.”
We can use the given formula to calculate the variance:
To calculate variance in Python:
import statistics
num = [10,20,30,40,50,60,60,70,70,70,80]
m = statistics.variance(num)
print(“The average of squared difference from the mean is:”, m)
Output:
The average of squared difference from the mean is: 529.090909090909
u Standard Deviation: The square root of the variance of ‘X’ is known as the Standard deviation (sigma). We
can use the given formula to calculate the standard deviation:
132
132