def makeRandomList(number, mean): 
    """ Make a list of 'number' random numbers with mean 'mean' """
    print 'makeRandomList(%3d,%4d)' % (number, int(mean)),
    assert(number >= 10)
    assert(mean >= 10)
    sequence = []
    for i in range(number):
        r = randomPositiveIntegerVariate(mean, statistics.getMean(sequence))
        sequence.append(r)
       
    random.shuffle(sequence)
    
    excess = sum(sequence) - number * mean
    print 'number', number,
    print 'mean', mean,
    print 'excess', excess,
    delta = 1 if excess >= 0 else -1
    i = 0
    while abs(excess) > 1.0:
        if sequence[i] - delta >= 0:
            sequence[i] = sequence[i] - delta
            excess = excess - delta
        i = (i+1) % number
        # print i,excess, '--',
    assert(abs(sum(sequence) - number * mean) <= 1.0)
    print '*'
    return sequence
def makeRandomList(number, mean):
    """ Make a list of 'number' random numbers with mean 'mean' """
    print 'makeRandomList(%3d,%4d)' % (number, int(mean)),
    assert (number >= 10)
    assert (mean >= 10)
    sequence = []
    for i in range(number):
        r = randomPositiveIntegerVariate(mean, statistics.getMean(sequence))
        sequence.append(r)

    random.shuffle(sequence)

    excess = sum(sequence) - number * mean
    print 'number', number,
    print 'mean', mean,
    print 'excess', excess,
    delta = 1 if excess >= 0 else -1
    i = 0
    while abs(excess) > 1.0:
        if sequence[i] - delta >= 0:
            sequence[i] = sequence[i] - delta
            excess = excess - delta
        i = (i + 1) % number
        # print i,excess, '--',
    assert (abs(sum(sequence) - number * mean) <= 1.0)
    print '*'
    return sequence
Exemple #3
0
def getDaysOfWeekToKeep(vector, threshold=0.2):
    """ Given a vector of daily values, determines which days are outliers
        based on threshold * median
        Returns days in week to keep """
    if False:
        average_for_day = []  
        for day in range(7):
            day_vector = [vector[i] for i in range(day, (len(vector)//7)*7, 7)]
            average_for_day.append(getMean(day_vector))
    else:
        average_for_day = [statistics.getMean([vector[i] for i in range(day, (len(vector)//7)*7, 7)]) for day in range(7)]   
    median_day = sorted(average_for_day)[3]
    return [day for day in range(7) if average_for_day[day] >= median_day*threshold]
Exemple #4
0
import statistics

userInput = input("Enter list to evaluate (separated by ',' ): ")
listStr = userInput.split(",")
listNumbers = list(map(int, listStr))

nQuartil = statistics.getNquartil(3, listNumbers)
nPercent = statistics.getNpercentil(75, listNumbers)
mean = statistics.getMean(listNumbers)
sD = statistics.getStandarDeviation(listNumbers)
med = statistics.getMedian(listNumbers)
print("Sample mean : " + str(mean))
print("Sample standard deviation : " + str(sD))
print("Sample median : " + str(med))
print("3 quartil : " + str(nQuartil))
print("75 percentil : " + str(nPercent))