Skip to content

Commit

Permalink
MAINT Parameters validation for lars_path_gram (scikit-learn#26380)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Thomas J. Fan <[email protected]>
  • Loading branch information
3 people committed Jul 7, 2023
1 parent 3a291fc commit d5a3546
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
52 changes: 35 additions & 17 deletions sklearn/linear_model/_least_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d5a3546

Please sign in to comment.