Prerequisite : Python statistics | variance()
pvariance() function helps to calculate the variance of an entire, rather than that of a sample. The only difference between
pvariance() is that while using variance(), only the sample mean is taken into consideration, while during pvariance(), the mean of entire population is taken into consideration.
Population variance is just similar to sample variance, it tells how data points in a specific population are spread out. It is the average of the distance from the data-points to the mean of the data-set, squared. The population variance is a parameter of the population and is not dependent on research methods or sampling practices.
Syntax :pvariance( [data], mu)
[data] : An iterable with real valued numbers.
mu (optional): Takes actual mean of data-set/ population as value.
Returnype :Returns the actual population variance of the values passed as parameter.
StatisticsError is raised for data-set less than 2-values passed as parameter.
Impossible values when the value provided as mu doesn’t match actual mean of the data-set.
Code #1 :
Population variance is 0.6658984375
Code #2 : Demonstrates pvariance() on a different range of population trees.
Population variance of set 1 is 7.913043478260869 Population variance of set 2 is 7.204152249134948 Population variance of set 3 is 103889/360000 Population variance of set 4 is 21.767923875432526
Code #3 : Demonstrates the use of mu parameter.
Population Variance is 14.30385015608741
Code #4 : Demonstrate the difference between pvariance() and variance()
Variance of the whole popuation is 0.6127751479289941 Variance of the sample from population is 0.8286277777777779 Difference in Population variance and Sample variance is 0.21585262984878373
Note : We can see from the above sample example that Population Variance and Sample Variance doesn’t differ by a huge value.
Code #5 : Demonstrates StatisticsError
Traceback (most recent call last): File "/home/fa112e1405f09970eeddd48214318a3c.py", line 10, in print(statistics.pvariance(pop)) File "/usr/lib/python3.5/statistics.py", line 603, in pvariance raise StatisticsError('pvariance requires at least one data point') statistics.StatisticsError: pvariance requires at least one data point
The applications of Population Variance is much similar to Sample Variance, although the range of population variance is much larger than sample variance. Population variance is only to be used when the variance of an entire population is to be calculated, otherwise for calculating the variance of a sample, variance() is preferred. Population Variance is a very important tool in Statistics and handling huge amounts of data. Like, when the omniscient mean is unknown (sample mean) then variance is used as biased estimator.
- Python statistics | median_grouped()
- Python statistics | mean() function
- Python statistics | median_low()
- Python statistics | harmonic_mean()
- Python statistics | variance()
- Python statistics | stdev()
- Python statistics | median()
- Python statistics | median_high()
- Python - Lomax Distribution in Statistics
- Python - Log Normal Distribution in Statistics
- Python - Student’s t Distribution in Statistics
- Python - Log Laplace Distribution in Statistics
- Python - Von Mises Distribution in Statistics
- Python - Logistic Distribution in Statistics
- Python - Trapezoidal Distribution in Statistics
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet