from matplotlib import pyplot as plt
from calculations import calculate_slope_and_intercept, calculate_error
from ..data import get_random_epoch


def launch():
    x, y = get_random_epoch()

    m, b = calculate_slope_and_intercept(x, y)

    y_hats = [b + (val * m) for val in x]

    print 'calculated slope: ' + str(m)
    print 'calculated intercept: ' + str(b)
    print 'calculated error: ' + str(calculate_error(y_hats, y))

    plt.figure(1)
    plt.xlabel('inputs')
    plt.ylabel('outputs')
    plt.title('ordinary least squares regression')
    plt.plot(x, y_hats, color='red')
    plt.scatter(x, y, color='yellowgreen', marker='.')
    plt.show()
