raju
raju

Reputation: 6936

Calculate Sample variance of a dataset using numpy

I have simple data: 1,2,3,4,5

I want to calculate sample variance using numpy, but numpy.var([1,2,3,4,5]), gives population variance.

Can any one plz help in how to get sample variance.

Upvotes: 2

Views: 3934

Answers (1)

DYZ
DYZ

Reputation: 57033

From https://machinelearningmastery.com/introduction-to-expected-value-variance-and-covariance/:

In NumPy, the variance can be calculated for a vector or a matrix using the var() function. By default, the var() function calculates the population variance. To calculate the sample variance, you must set the ddof argument to the value 1.

Upvotes: 7

Related Questions