import unittest

import numpy as np

import Orange


class SGDRegressionTest(unittest.TestCase):
    def test_SGDRegression(self):
        nrows = 500
        ncols = 5
        x = np.sort(10 * np.random.rand(nrows, ncols))
        y = np.sum(np.sin(x), axis=1).reshape(nrows, 1)
        x1, x2 = np.split(x, 2)
        y1, y2 = np.split(y, 2)
        t = Orange.data.Table(x1, y1)
        learn = Orange.regression.SGDRegressionLearner()
        clf = learn(t)
        z = clf(x2)
        self.assertTrue((abs(z.reshape(-1, 1) - y2) < 4.0).all())

import unittest

import numpy as np

import Orange


class SGDRegressionTest(unittest.TestCase):
    def test_SGDRegression(self):
        nrows, ncols = 500, 5
        X = np.random.rand(nrows, ncols)
        y = X.dot(np.random.rand(ncols))
        data = Orange.data.Table(X, y)
        sgd = Orange.regression.SGDRegressionLearner()
        res = Orange.evaluation.CrossValidation(data, [sgd], k=3)
        self.assertTrue(Orange.evaluation.RMSE(res)[0] < 0.1)

Improve (fix) SGD test.