def fit_select_best ( X , y ) : models = [ fit ( X , y ) for fit in [ fit_linear , fit_quadratic ] ] errors = map ( lambda model : mse ( y , model . predict ( X ) ) , models ) return min ( zip ( models , errors ) , key = itemgetter ( 1 ) ) [ 0 ]
python code example least squares best fit
Selects the best fit of the estimators already implemented by choosing the model with the smallest mean square error metric for the trained values .
def fit_select_best(X, y):
    """
    Selects the best fit of the estimators already implemented by choosing the
    model with the smallest mean square error metric for the trained values.
    """
    models = [fit(X,y) for fit in [fit_linear, fit_quadratic]]
    errors = map(lambda model: mse(y, model.predict(X)), models)

    return min(zip(models, errors), key=itemgetter(1))[0]