Answers for "variance calculation python manually"

3

numpy how to calculate variance

import numpy
numbers = [50,66,77,88,99,100]
x = numpy.var(numbers)
print(x)
Posted by: Guest on August-06-2020
0

variance calculation python manually

>>> def variance(data):
...     # Number of observations
...     n = len(data)
...     # Mean of the data
...     mean = sum(data) / n
...     # Square deviations
...     deviations = [(x - mean) ** 2 for x in data]
...     # Variance
...     variance = sum(deviations) / n
...     return variance
...

>>> variance([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])
5.76
Posted by: Guest on January-11-2022

Python Answers by Framework

Browse Popular Code Answers by Language