def test_linear_regression_numpy(self):
""" Test the linear regression using numpy (if installed). """
# test that numpy is installed
try:
import numpy
numpy.__name__
except ImportError:
raise unittest.SkipTest('cannot test as optional numpy is not installed')
# perform the test with numpy
from supvisors.utils import get_linear_regression, get_simple_linear_regression
xdata = [2, 4, 6, 8, 10, 12]
ydata = [3, 4, 5, 6, 7, 8]
# test linear regression
a, b = get_linear_regression(xdata, ydata)
self.assertAlmostEqual(0.5, a)
self.assertAlmostEqual(2.0, b)
# test simple linear regression
a, b = get_simple_linear_regression(ydata)
self.assertAlmostEqual(1.0, a)
self.assertAlmostEqual(3.0, b)
评论列表
文章目录