diff --git a/sklearn/linear_model/_least_angle.py b/sklearn/linear_model/_least_angle.py index 2a6d264da73e6..b871eb2676fa1 100644 --- a/sklearn/linear_model/_least_angle.py +++ b/sklearn/linear_model/_least_angle.py @@ -203,6 +203,24 @@ def lars_path( ) +@validate_params( + { + "Xy": [np.ndarray], + "Gram": [np.ndarray], + "n_samples": [Interval(Integral, 0, None, closed="left")], + "max_iter": [Interval(Integral, 0, None, closed="left")], + "alpha_min": [Interval(Real, 0, None, closed="left")], + "method": [StrOptions({"lar", "lasso"})], + "copy_X": ["boolean"], + "eps": [Interval(Real, 0, None, closed="neither"), None], + "copy_Gram": ["boolean"], + "verbose": ["verbose"], + "return_path": ["boolean"], + "return_n_iter": ["boolean"], + "positive": ["boolean"], + }, + prefer_skip_nested_validation=True, +) def lars_path_gram( Xy, Gram, @@ -232,13 +250,13 @@ def lars_path_gram( Parameters ---------- - Xy : array-like of shape (n_features,) or (n_features, n_targets) - Xy = np.dot(X.T, y). + Xy : ndarray of shape (n_features,) or (n_features, n_targets) + `Xy = X.T @ y`. - Gram : array-like of shape (n_features, n_features) - Gram = np.dot(X.T * X). + Gram : ndarray of shape (n_features, n_features) + `Gram = X.T @ X`. - n_samples : int or float + n_samples : int Equivalent size of sample. max_iter : int, default=500 @@ -249,27 +267,27 @@ def lars_path_gram( regularization parameter alpha parameter in the Lasso. method : {'lar', 'lasso'}, default='lar' - Specifies the returned model. Select ``'lar'`` for Least Angle + Specifies the returned model. Select `'lar'` for Least Angle Regression, ``'lasso'`` for the Lasso. copy_X : bool, default=True - If ``False``, ``X`` is overwritten. + If `False`, `X` is overwritten. eps : float, default=np.finfo(float).eps The machine-precision regularization in the computation of the Cholesky diagonal factors. Increase this for very ill-conditioned - systems. Unlike the ``tol`` parameter in some iterative + systems. Unlike the `tol` parameter in some iterative optimization-based algorithms, this parameter does not control the tolerance of the optimization. copy_Gram : bool, default=True - If ``False``, ``Gram`` is overwritten. + If `False`, `Gram` is overwritten. verbose : int, default=0 Controls output verbosity. return_path : bool, default=True - If ``return_path==True`` returns the entire path, else returns only the + If `return_path==True` returns the entire path, else returns only the last point of the path. return_n_iter : bool, default=False @@ -280,26 +298,26 @@ def lars_path_gram( This option is only allowed with method 'lasso'. Note that the model coefficients will not converge to the ordinary-least-squares solution for small values of alpha. Only coefficients up to the smallest alpha - value (``alphas_[alphas_ > 0.].min()`` when fit_path=True) reached by + value (`alphas_[alphas_ > 0.].min()` when `fit_path=True`) reached by the stepwise Lars-Lasso algorithm are typically in congruence with the solution of the coordinate descent lasso_path function. Returns ------- - alphas : array-like of shape (n_alphas + 1,) + alphas : ndarray of shape (n_alphas + 1,) Maximum of covariances (in absolute value) at each iteration. - ``n_alphas`` is either ``max_iter``, ``n_features`` or the - number of nodes in the path with ``alpha >= alpha_min``, whichever + `n_alphas` is either `max_iter`, `n_features` or the + number of nodes in the path with `alpha >= alpha_min`, whichever is smaller. - active : array-like of shape (n_alphas,) + active : ndarray of shape (n_alphas,) Indices of active variables at the end of the path. - coefs : array-like of shape (n_features, n_alphas + 1) + coefs : ndarray of shape (n_features, n_alphas + 1) Coefficients along the path. n_iter : int - Number of iterations run. Returned only if return_n_iter is set + Number of iterations run. Returned only if `return_n_iter` is set to True. See Also diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index 614b54467d397..bd20de37d405e 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -202,6 +202,7 @@ def _check_function_param_validation( "sklearn.isotonic.isotonic_regression", "sklearn.linear_model.enet_path", "sklearn.linear_model.lars_path", + "sklearn.linear_model.lars_path_gram", "sklearn.linear_model.lasso_path", "sklearn.linear_model.orthogonal_mp", "sklearn.linear_model.orthogonal_mp_gram",