mercredi 30 septembre 2015

Variance using Gaussian distribution Python

I have a code which calculates the square of a number using Gaussian distribution in python. Now my task is to calculate the variance for the same. But when I try, i keep getting error. The code is as follows:

import random
def generate_data(size):
    n = 5
    m =0.5
    mu, sigma = n ** 2, m/3
    return [random.gauss(mu, sigma) for _ in range(size)]


def average(ls):
    avg =  sum(ls) / len(ls)
    variance = (sum(ls) - sum(avg)) ** 2 / len(ls)

    return variance

I am not good in statistics, so I might be wrong with the formula too. and I am also a beginner in python.The error I get is

'float' object is not iterable 




Aucun commentaire:

Enregistrer un commentaire