Exemplo n.º 1
0
 def test_mode(self):
     self.assertEqual(calculate.mode([1,2,3,2]), 2.0)
     self.assertEqual(calculate.mode([1,2,3]), None)
     self.assertEqual(calculate.mode([2,2,2]), 2.0)
     with self.assertRaises(TypeError):
         calculate.median([None, 1, 2])
         calculate.median(['a', 1, 2])
def summary_stats(data_list):
    """
    Accepts a sample of numbers and returns a pretty
    print out of a variety of descriptive statistics.
    """
    mean = calculate.mean(data_list)
    median = calculate.median(data_list)
    mode = calculate.mode(data_list)
    n = len(data_list)
    max_ = max(data_list)
    min_ = min(data_list)
    range_ = calculate.range(data_list)
    standard_deviation = calculate.standard_deviation(data_list)
    
    print """
Summary statistics
==================

n:        %s
max:        %s
min:        %s
range:        %s
mean:        %s
median:        %s
mode:        %s
std:        %s
""" % (n, max_, min_, range_, mean, median, mode, standard_deviation)
Exemplo n.º 3
0
def summary_stats(data_list):
    """
    Accepts a sample of numbers and returns a pretty
    print out of a variety of descriptive statistics.
    """
    mean = calculate.mean(data_list)
    median = calculate.median(data_list)
    mode = calculate.mode(data_list)
    n = len(data_list)
    max_ = max(data_list)
    min_ = min(data_list)
    range_ = calculate.range(data_list)
    standard_deviation = calculate.standard_deviation(data_list)
    variation_coefficient = calculate.variation_coefficient(data_list)

    table = ptable.indent(
        [
            ['Statistic', 'Value'],
            ['n', str(n)],
            ['mean', str(mean)],
            ['median', str(median)],
            ['mode', str(mode)],
            ['maximum', str(max_)],
            ['minimum', str(min_)],
            ['range', str(range_)],
            ['standard deviation', str(standard_deviation)],
            ['variation coefficient', str(variation_coefficient)],
        ],
        hasHeader=True,
        separateRows=False,
        prefix="| ", postfix=" |",
    )
    print(table)
Exemplo n.º 4
0
 def test_median(self):
     self.assertEqual(calculate.median([1, 3, 2]), 2.0)
     self.assertEqual(calculate.median([1, 2, 3, 4]), 2.5)
     self.assertRaises(TypeError, calculate.median, [None, 1, 2])
     self.assertRaises(ValueError, calculate.median, ['a', 1, 2])
Exemplo n.º 5
0
 def test_median(self):
     self.assertEqual(calculate.median([1, 3, 2]), 2.0)
     self.assertEqual(calculate.median([1, 2, 3, 4]), 2.5)
     self.assertRaises(TypeError, calculate.median, [None, 1, 2])
     self.assertRaises(ValueError, calculate.median, ['a', 1, 2])
Exemplo n.º 6
0
 def test_median(self):
     self.assertEqual(calculate.median([1,3,2]), 2.0)
     self.assertEqual(calculate.median([1,2,3,4]), 2.5)
     with self.assertRaises(TypeError):
         calculate.median([None, 1, 2])
         calculate.median(['a', 1, 2])