def compute_error_for_line_given_points(b, m, points):
    """Error function (also called a cost function).

    It measures how "good" a given line is.

    This function will take in a (m,b) pair and return an
    error value based on how well the line fits our data.
    To compute this error for a given line, we'll iterate through each (x,y)
    point in our data set and sum the square distances between each point's y
    value and the candidate line's y value (computed at mx + b).

    Lines that fit our data better (where better is defined by our error
    function) will result in lower error values.

    """
    total_error = 0
    for x, y in points:
        total_error += (y - (m * x + b)) ** 2
    return total_error / float(len(points))