File: test_polynomial_learner.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 (29 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (2)
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
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring

import unittest
import numpy as np

from Orange.data import Table, ContinuousVariable, Domain
from Orange.regression import LinearRegressionLearner, PolynomialLearner
from Orange.evaluation import TestOnTrainingData, RMSE

class TestPolynomialLearner(unittest.TestCase):
    def test_PolynomialLearner(self):
        x = np.array([0.172, 0.167, 0.337, 0.420, 0.355, 0.710, 0.801, 0.876])
        y = np.array([0.784, 0.746, 0.345, 0.363, 0.366, 0.833, 0.490, 0.445])

        data = Table.from_numpy(None, x.reshape(-1, 1), y)
        data.domain = Domain([ContinuousVariable('x')],
                             class_vars=[ContinuousVariable('y')])

        linear = LinearRegressionLearner()
        polynomial2 = PolynomialLearner(linear, degree=2)
        polynomial3 = PolynomialLearner(linear, degree=3)

        tt = TestOnTrainingData()
        res = tt(data, [linear, polynomial2, polynomial3])
        rmse = RMSE(res)

        self.assertGreater(rmse[0], rmse[1])
        self.assertGreater(rmse[1], rmse[2])