File: test_scoring.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (34 lines) | stat: -rw-r--r-- 989 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import unittest

import numpy as np

from Orange.evaluation import MAPE
from Orange.evaluation.scoring import SMAPE


class TestScoring(unittest.TestCase):
    def test_mape(self):
        f = MAPE.__wraps__
        exp = np.array([100, -200, 300, 60])
        pred = np.array([110, -180, 340, 60])
        self.assertEqual(f(exp, pred), (10 / 100 + 20 / 200 + 40 / 300) / 4 * 100)

        exp = np.array([0, 200, 300])
        self.assertEqual(f(exp, pred), np.inf)

    def test_smape(self):
        f = SMAPE.__wraps__
        exp = np.array([100, -200, 300, 60, 80])
        pred = np.array([110, -180, -340, 60, 50])
        self.assertEqual(
            f(exp, pred),
            2 * (10 / 210 + 20 / 380 + 640 / 640 + 0 / 120 + 30 / 130) / 5 * 100)

        exp = np.array([0, -200, 300, 60, 80])
        self.assertEqual(
            f(exp, pred),
            2 * (110 / 110 + 20 / 380 + 640 / 640 + 0 / 120 + 30 / 130) / 5 * 100)


if __name__ == '__main__':
    unittest.main()