#NEWLINE# def _lars_path_residues( X_train , y_train , X_test , y_test , Gram = None , copy = True , method = 'lars' , verbose = False , fit_intercept = True , normalize = True , max_iter = 500 , eps = np . finfo ( np . float ) . eps , positive = False ) : #NEWLINE# #INDENT# "Compute the residues on left-out data for a full LARS path\n\n    Parameters\n    -----------\n    X_train : array, shape (n_samples, n_features)\n        The data to fit the LARS on\n\n    y_train : array, shape (n_samples)\n        The target variable to fit LARS on\n\n    X_test : array, shape (n_samples, n_features)\n        The data to compute the residues on\n\n    y_test : array, shape (n_samples)\n        The target variable to compute the residues on\n\n    Gram : None, 'auto', array, shape: (n_features, n_features), optional\n        Precomputed Gram matrix (X' * X), if ``'auto'``, the Gram\n        matrix is precomputed from the given X, if there are more samples\n        than features\n\n    copy : boolean, optional\n        Whether X_train, X_test, y_train and y_test should be copied;\n        if False, they may be overwritten.\n\n    method : 'lar' | 'lasso'\n        Specifies the returned model. Select ``'lar'`` for Least Angle\n        Regression, ``'lasso'`` for the Lasso.\n\n    verbose : integer, optional\n        Sets the amount of verbosity\n\n    fit_intercept : boolean\n        whether to calculate the intercept for this model. If set\n        to false, no intercept will be used in calculations\n        (e.g. data is expected to be already centered).\n\n    positive : boolean (default=False)\n        Restrict coefficients to be >= 0. Be aware that you might want to\n        remove fit_intercept which is set True by default.\n        See reservations for using this option in combination with method\n        'lasso' for expected small values of alpha in the doc of LassoLarsCV\n        and LassoLarsIC.\n\n    normalize : boolean, optional, default False\n        If True, the regressors X will be normalized before regression.\n        This parameter is ignored when `fit_intercept` is set to False.\n        When the regressors are normalized, note that this makes the\n        hyperparameters learnt more robust and almost independent of the number\n        of samples. The same property is not valid for standardized data.\n        However, if you wish to standardize, please use\n        `preprocessing.StandardScaler` before calling `fit` on an estimator\n        with `normalize=False`.\n\n    max_iter : integer, optional\n        Maximum number of iterations to perform.\n\n    eps : float, optional\n        The machine-precision regularization in the computation of the\n        Cholesky diagonal factors. Increase this for very ill-conditioned\n        systems. Unlike the ``tol`` parameter in some iterative\n        optimization-based algorithms, this parameter does not control\n        the tolerance of the optimization.\n\n\n    Returns\n    --------\n    alphas : array, shape (n_alphas,)\n        Maximum of covariances (in absolute value) at each iteration.\n        ``n_alphas`` is either ``max_iter`` or ``n_features``, whichever\n        is smaller.\n\n    active : list\n        Indices of active variables at the end of the path.\n\n    coefs : array, shape (n_features, n_alphas)\n        Coefficients along the path\n\n    residues : array, shape (n_alphas, n_samples)\n        Residues of the prediction on the test data\n    " #NEWLINE# X_train = _check_copy_and_writeable ( X_train , copy ) #NEWLINE# y_train = _check_copy_and_writeable ( y_train , copy ) #NEWLINE# X_test = _check_copy_and_writeable ( X_test , copy ) #NEWLINE# y_test = _check_copy_and_writeable ( y_test , copy ) #NEWLINE# if fit_intercept : #NEWLINE# #INDENT# X_mean = X_train . mean ( axis = 0 ) #NEWLINE# X_train -= X_mean #NEWLINE# X_test -= X_mean #NEWLINE# y_mean = y_train . mean ( axis = 0 ) #NEWLINE# y_train = as_float_array ( eps , copy = False ) #NEWLINE# y_train -= y_mean #NEWLINE# y_test = as_float_array ( y_test , copy = False ) #NEWLINE# y_test -= y_mean #NEWLINE# #UNINDENT# if normalize : #NEWLINE# #INDENT# norms = np . sqrt ( np . sum ( ( X_train ** 2 ) , axis = 0 ) ) #NEWLINE# nonzeros = np . flatnonzero ( norms ) #NEWLINE# X_train [ : , nonzeros ] /= norms [ nonzeros ] #NEWLINE# #UNINDENT# ( alphas , active , coefs ) = lars_path ( X_train , y_train , Gram = Gram , copy_X = False , copy_Gram = False , method = method , verbose = max ( 0 , ( verbose - 1 ) ) , max_iter = max_iter , eps = eps , positive = positive ) #NEWLINE# if normalize : #NEWLINE# #INDENT# coefs [ nonzeros ] /= norms [ nonzeros ] [ : , np . newaxis ] #NEWLINE# #UNINDENT# residues = ( np . dot ( X_test , coefs ) - y_test [ : , np . newaxis ] ) #NEWLINE# return ( alphas , active , coefs , residues . T )