Exemple #1
0
    def test_linear_regression_skip_zeroes(self):
        s1 = series_factory()
        s2 = series_factory()

        Row.objects.create(series=s1, timestamp=datetime.now(), value=1.0)
        Row.objects.create(series=s1, timestamp=datetime.now(), value=2.0)
        Row.objects.create(series=s1, timestamp=datetime.now(), value=0.0)
        Row.objects.create(series=s1, timestamp=datetime.now(), value=4.0)
        Row.objects.create(series=s1, timestamp=datetime.now(), value=5.0)

        Row.objects.create(series=s2, timestamp=datetime.now(), value=1.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=2.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=3.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=4.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=5.0)

        lsp = LimitedSeriesPair(s1, s2, skip_zeroes=True)
        r = lsp.linear_regression()
        # dict(a=a, b=b, rr=rr, ss=ss, var_a=var_a, var_b=var_b)
        self.assertEqual(r['a'], 1.0)
        self.assertEqual(r['b'], 0.0)
        self.assertEqual(r['rr'], 1.0)
        self.assertEqual(r['ss'], 0.0)
        self.assertEqual(r['var_a'], 0.0)
        self.assertEqual(r['var_b'], 0.0)
Exemple #2
0
    def test_linear_regression_divide_by_zero(self):
        s1 = series_factory()
        s2 = series_factory()

        Row.objects.create(series=s1, timestamp=datetime.now(), value=0.0)
        Row.objects.create(series=s1, timestamp=datetime.now(), value=0.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=0.0)
        Row.objects.create(series=s2, timestamp=datetime.now(), value=0.0)

        lsp = LimitedSeriesPair(s1, s2)
        r = lsp.linear_regression()
        self.assertEqual(r, None)