def cost(row, coef, intercept):
    """
    Computes the square error given the row.
    """
    X, y = row # extract the dependent and independent vals from the tuple.

    # Compute the predicted value based on the linear model
    yhat = sum([b*x for (b,x) in zip(coef.value, X)]) + intercept.value

    # Compute the square error of the prediction
    return (y - yhat) ** 2