
    0Ph`D                       d Z ddlZddlZddlmZ ddlmZmZ ddlZ	ddl
mZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/ ddiZ0 e&e	j1        dge	j1        dge	j1        dg e%dh          de	j1        dg e$eddd          g e$eddd          g e%ddh          gdg e$eddd          dgdgdgdgdgdgdd          	 d2ddddd e	j2        e3          j4        dddddd d!            Z5 e&e	j1        ge	j1        g e$eddd          g e$eddd          g e$eddd          g e%ddh          gdg e$eddd          dgdgdgdgdgdgd"d          dddd e	j2        e3          j4        dddddd#
d$            Z6ddddddd e	j2        e3          j4        dddddfd%Z7 G d& d'eee-          Z8 G d( d)e8          Z9d3d*Z:dddddd e	j2        e3          j4        dfd+Z; G d, d-e8          Z< G d. d/e<          Z= G d0 d1e9          Z>dS )4zt
Least Angle Regression algorithm. See the documentation on the
Generalized Linear Model for a complete discussion.
    N)log)IntegralReal)interpolatelinalg)get_lapack_funcs   )MultiOutputMixinRegressorMixin_fit_context)ConvergenceWarning)check_cv)Bunch
arrayfuncsas_float_arraycheck_random_state)MetadataRouterMethodMapping_raise_for_params_routing_enabledprocess_routing)HiddenInterval
StrOptionsvalidate_params)Paralleldelayed)validate_data   )LinearModelLinearRegression_preprocess_datacheck_finiteFautobooleanleftclosedlarlassoneitherverboseXyXyGrammax_iter	alpha_minmethodcopy_Xeps	copy_Gramr,   return_pathreturn_n_iterpositiveTprefer_skip_nested_validation  )r1   r2   r3   r4   r5   r6   r7   r,   r8   r9   r:   c                d    | |t          d          t          | |||d||||||	|
|||          S )a  Compute Least Angle Regression or Lasso path using the LARS algorithm.

    The optimization objective for the case method='lasso' is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    in the case of method='lar', the objective function is only known in
    the form of an implicit equation (see discussion in [1]_).

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    X : None or ndarray of shape (n_samples, n_features)
        Input data. If X is `None`, Gram must also be `None`.
        If only the Gram matrix is available, use `lars_path_gram` instead.

    y : None or ndarray of shape (n_samples,)
        Input targets.

    Xy : array-like of shape (n_features,), default=None
        `Xy = X.T @ y` that can be precomputed. It is useful
        only when the Gram matrix is precomputed.

    Gram : None, 'auto', bool, ndarray of shape (n_features, n_features),             default=None
        Precomputed Gram matrix `X.T @ X`, if `'auto'`, the Gram
        matrix is precomputed from the given X, if there are more samples
        than features.

    max_iter : int, default=500
        Maximum number of iterations to perform, set to infinity for no limit.

    alpha_min : float, default=0
        Minimum correlation along the path. It corresponds to the
        regularization parameter `alpha` in the Lasso.

    method : {'lar', 'lasso'}, default='lar'
        Specifies the returned model. Select `'lar'` for Least Angle
        Regression, `'lasso'` for the Lasso.

    copy_X : bool, default=True
        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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_Gram : bool, default=True
        If `False`, `Gram` is overwritten.

    verbose : int, default=0
        Controls output verbosity.

    return_path : bool, default=True
        If `True`, returns the entire path, else returns only the
        last point of the path.

    return_n_iter : bool, default=False
        Whether to return the number of iterations.

    positive : bool, default=False
        Restrict coefficients to be >= 0.
        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
        the stepwise Lars-Lasso algorithm are typically in congruence with the
        solution of the coordinate descent `lasso_path` function.

    Returns
    -------
    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
        is smaller.

    active : ndarray of shape (n_alphas,)
        Indices of active variables at the end of the path.

    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
        to True.

    See Also
    --------
    lars_path_gram : Compute LARS path in the sufficient stats mode.
    lasso_path : Compute Lasso path with coordinate descent.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    Lars : Least Angle Regression model a.k.a. LAR.
    LassoLarsCV : Cross-validated Lasso, using the LARS algorithm.
    LarsCV : Cross-validated Least Angle Regression model.
    sklearn.decomposition.sparse_encode : Sparse coding.

    References
    ----------
    .. [1] "Least Angle Regression", Efron et al.
           http://statweb.stanford.edu/~tibs/ftp/lars.pdf

    .. [2] `Wikipedia entry on the Least-angle regression
           <https://en.wikipedia.org/wiki/Least-angle_regression>`_

    .. [3] `Wikipedia entry on the Lasso
           <https://en.wikipedia.org/wiki/Lasso_(statistics)>`_

    Examples
    --------
    >>> from sklearn.linear_model import lars_path
    >>> from sklearn.datasets import make_regression
    >>> X, y, true_coef = make_regression(
    ...    n_samples=100, n_features=5, n_informative=2, coef=True, random_state=0
    ... )
    >>> true_coef
    array([ 0.        ,  0.        ,  0.        , 97.9..., 45.7...])
    >>> alphas, _, estimated_coef = lars_path(X, y)
    >>> alphas.shape
    (3,)
    >>> estimated_coef
    array([[ 0.     ,  0.     ,  0.     ],
           [ 0.     ,  0.     ,  0.     ],
           [ 0.     ,  0.     ,  0.     ],
           [ 0.     , 46.96..., 97.99...],
           [ 0.     ,  0.     , 45.70...]])
    NzPX cannot be None if Gram is not NoneUse lars_path_gram to avoid passing X and y.r.   r/   r0   r1   	n_samplesr2   r3   r4   r5   r6   r7   r,   r8   r9   r:   )
ValueError_lars_path_solverr-   s                 a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/linear_model/_least_angle.py	lars_pathrD   ,   sl    N 	yT%;
 
 	
 

#       r0   r1   r@   r2   r3   r4   r5   r6   r7   r,   r8   r9   r:   )
r2   r3   r4   r5   r6   r7   r,   r8   r9   r:   c                >    t          dd| |||||||||	|
||          S )a  The lars_path in the sufficient stats mode.

    The optimization objective for the case method='lasso' is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    in the case of method='lar', the objective function is only known in
    the form of an implicit equation (see discussion in [1]_).

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    Xy : ndarray of shape (n_features,)
        `Xy = X.T @ y`.

    Gram : ndarray of shape (n_features, n_features)
        `Gram = X.T @ X`.

    n_samples : int
        Equivalent size of sample.

    max_iter : int, default=500
        Maximum number of iterations to perform, set to infinity for no limit.

    alpha_min : float, default=0
        Minimum correlation along the path. It corresponds to the
        regularization parameter alpha parameter in the Lasso.

    method : {'lar', 'lasso'}, default='lar'
        Specifies the returned model. Select `'lar'` for Least Angle
        Regression, ``'lasso'`` for the Lasso.

    copy_X : bool, default=True
        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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_Gram : bool, default=True
        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
        last point of the path.

    return_n_iter : bool, default=False
        Whether to return the number of iterations.

    positive : bool, default=False
        Restrict coefficients to be >= 0.
        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
        the stepwise Lars-Lasso algorithm are typically in congruence with the
        solution of the coordinate descent lasso_path function.

    Returns
    -------
    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
        is smaller.

    active : ndarray of shape (n_alphas,)
        Indices of active variables at the end of the path.

    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
        to True.

    See Also
    --------
    lars_path_gram : Compute LARS path.
    lasso_path : Compute Lasso path with coordinate descent.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    Lars : Least Angle Regression model a.k.a. LAR.
    LassoLarsCV : Cross-validated Lasso, using the LARS algorithm.
    LarsCV : Cross-validated Least Angle Regression model.
    sklearn.decomposition.sparse_encode : Sparse coding.

    References
    ----------
    .. [1] "Least Angle Regression", Efron et al.
           http://statweb.stanford.edu/~tibs/ftp/lars.pdf

    .. [2] `Wikipedia entry on the Least-angle regression
           <https://en.wikipedia.org/wiki/Least-angle_regression>`_

    .. [3] `Wikipedia entry on the Lasso
           <https://en.wikipedia.org/wiki/Lasso_(statistics)>`_

    Examples
    --------
    >>> from sklearn.linear_model import lars_path_gram
    >>> from sklearn.datasets import make_regression
    >>> X, y, true_coef = make_regression(
    ...    n_samples=100, n_features=5, n_informative=2, coef=True, random_state=0
    ... )
    >>> true_coef
    array([ 0.        ,  0.        ,  0.        , 97.9..., 45.7...])
    >>> alphas, _, estimated_coef = lars_path_gram(X.T @ y, X.T @ X, n_samples=100)
    >>> alphas.shape
    (3,)
    >>> estimated_coef
    array([[ 0.     ,  0.     ,  0.     ],
           [ 0.     ,  0.     ,  0.     ],
           [ 0.     ,  0.     ,  0.     ],
           [ 0.     , 46.96..., 97.99...],
           [ 0.     ,  0.     , 45.70...]])
    Nr?   )rB   rF   s                rC   lars_path_gramrH      sI    z 

#   rE   c                 >  E |dk    r|rt          d          ||n|j        }|t          j        | j        |          }n|                                }||du rd}| t          d          nst          |t                    r|dk    s|du r>|du s| j        d         | j        d	         k    rt          j        | j        |           }nd}n|
r|                                }|| j        d	         }n)|j        d         }|j        ||fk    rt          d
          |r| ||                     d          } t          ||          }t          d | |||fD                       }t          |          d	k    rt          t          |                    }nt          j        }|r5t          j        |d	z   |f|          }t          j        |d	z   |          }nZt          j        ||          t          j        ||          }}t          j        dg|          t          j        dg|          }}d\  }}t#                      t          j        |          cE}t          j        |t          j                  }d}|7t          j        ||f| j                  }t-          j        d| f          \  } }!n6t          j        ||f|j                  }t-          j        d|f          \  } }!t1          d|f          \  }"|rS|d	k    rt3          d           n=t4          j                            d           t4          j                                         t          j        t          j                  j         }#t          j        |j                  j!        }$t          j        t          j                  j"        }%|(|                                }&|                                }'	 |j        r_|rt          j#        |          }(n&t          j#        t          j$        |                    }(||(         })|r|)}*nt          j%        |)          }*nd}*|r>||t          j&        f         }||         }||d	z
  t          j&        f         }||d	z
           }|*|z  |d<   |d         ||%z   k    r]tI          |d         |z
            |%k    r8|dk    r-|d         |z
  |d         |d         z
  z  }+||+||z
  z  z   |dd<   ||d<   |r|||<   n||k    s||k    rn|s|rt          j'        |)          ||<   nt          j(        |)          ||<   ||(|z   }-}, | ||(         |d                   \  ||(<   |d<   ||,         ||-         c||-<   ||,<   |}.|d	d         }| | | j        |-         | j        |,                   \  | j        |-<   | j        |,<    |!| j        |                   dz  }/t          j        | j        |         | j        d|         j                  ||d|f<   no | ||,         ||-                   \  ||,<   ||-<    | |dd|,f         |dd|-f                   \  |dd|,f<   |dd|-f<   |||f         }/||d|f         ||d|f<   |r2t-          j)        |d|d|f         ||d|f         fdd	ddtT           t          j        ||d|f         ||d|f                   }0tW          t          j,        t          j$        |/|0z
                      |	          }1|1|||f<   |1dk     r]t[          j.        d||/                                ||1fz  t`                     |.}d|d<    | ||(         |d                   \  ||(<   |d<   E1                    ||                    |d	z  }|d	k    r#t3          |dEd         ddd|d|*	           |dk    r_|dk    rY|d         |d         k     rGt[          j.        d||/                                |/                                |fz  t`                     n |"|d|d|f         |d|         d          \  }2}3|2j        d	k    r|2dk    r	d	|2d<   d}4ndt          j,        t          j2        |2|d|         z                      z  }4t          j3        |4          sd}5|d|d|f                                         }6t          j3        |4          s|6j4        dd|d	z   xx         d|5z  |	z  z  cc<    |"|6|d|         d          \  }2}3tW          t          j2        |2|d|         z            |	          }7dt          j,        |7          z  }4|5d	z  }5t          j3        |4          |2|4z  }2|Jt          j        | j        d|         j        |2          }8t          j        | j        |d         |8          }9n&t          j        |d||df         j        |2          }9t          j5        |9|$|9            tm          j7        |*|z
  |4|9z
  |#z   z            }:|rt          |:|*|4z            };n4tm          j7        |*|z   |4|9z   |#z   z            }<t          |:|<|*|4z            };d}|E          |2|#z   z  }=tm          j7        |=          }>|>|;k     r=t          j8        |=|>k              d         ddd         }?||?          ||?<   |dk    r|>};d}|d	z  }|r||j        d         k    r\~~~~dtW          d	||z
            z  }@t          j9        |||@z   |f          }d||@ d<   t          j9        |||@z             }d||@ d<   ||         }||d	z
           }n!|}|d         |d<   t          j:        |          }|E         |;|2z  z   |E<   ||;|9z  z  }|r6|dk    r/|?D ]#}Atm          j;        |d|d|f         |A           $|d	z  }Efd!|?D             }B||?D ]m}Aty          |A|          D ]Z}5 | | j        |5         | j        |5d	z                      \  | j        |5<   | j        |5d	z   <   ||5d	z            ||5         c||5<   ||5d	z   <   [n|t          j        | ddd|f         |E                   z
  }Ct          j        | j        |         |C          }Dt          j=        |D|f         }n|?D ]}Aty          |A|          D ]}}5||5d	z            ||5         c||5<   ||5d	z   <    | ||5         ||5d	z                      \  ||5<   ||5d	z   <    | |dd|5f         |dd|5d	z   f                   \  |dd|5f<   |dd|5d	z   f<   ~|'|B         t          j        |&|B         |          z
  }Dt          j=        |D|f         }t          j>        ||?          }t          j1        |d          }|d	k    r*t3          |ddd|Bd|dtI          |D          	           	|r1|d|d	z            }|d|d	z            }|r|E|j        |fS |E|j        fS |r|E||fS |E|fS )"a9  Compute Least Angle Regression or Lasso path using LARS algorithm [1]

    The optimization objective for the case method='lasso' is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    in the case of method='lar', the objective function is only known in
    the form of an implicit equation (see discussion in [1])

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    X : None or ndarray of shape (n_samples, n_features)
        Input data. Note that if X is None then Gram must be specified,
        i.e., cannot be None or False.

    y : None or ndarray of shape (n_samples,)
        Input targets.

    Xy : array-like of shape (n_features,), default=None
        `Xy = np.dot(X.T, y)` that can be precomputed. It is useful
        only when the Gram matrix is precomputed.

    Gram : None, 'auto' or array-like of shape (n_features, n_features),             default=None
        Precomputed Gram matrix `(X' * X)`, if ``'auto'``, the Gram
        matrix is precomputed from the given X, if there are more samples
        than features.

    n_samples : int or float, default=None
        Equivalent size of sample. If `None`, it will be `n_samples`.

    max_iter : int, default=500
        Maximum number of iterations to perform, set to infinity for no limit.

    alpha_min : float, default=0
        Minimum correlation along the path. It corresponds to the
        regularization parameter alpha parameter in the Lasso.

    method : {'lar', 'lasso'}, default='lar'
        Specifies the returned model. Select ``'lar'`` for Least Angle
        Regression, ``'lasso'`` for the Lasso.

    copy_X : bool, default=True
        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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_Gram : bool, default=True
        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
        last point of the path.

    return_n_iter : bool, default=False
        Whether to return the number of iterations.

    positive : bool, default=False
        Restrict coefficients to be >= 0.
        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
        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,)
        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
        is smaller.

    active : array-like of shape (n_alphas,)
        Indices of active variables at the end of the path.

    coefs : array-like 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
        to True.

    See Also
    --------
    lasso_path
    LassoLars
    Lars
    LassoLarsCV
    LarsCV
    sklearn.decomposition.sparse_encode

    References
    ----------
    .. [1] "Least Angle Regression", Efron et al.
           http://statweb.stanford.edu/~tibs/ftp/lars.pdf

    .. [2] `Wikipedia entry on the Least-angle regression
           <https://en.wikipedia.org/wiki/Least-angle_regression>`_

    .. [3] `Wikipedia entry on the Lasso
           <https://en.wikipedia.org/wiki/Lasso_(statistics)>`_

    r)   z:Positive constraint not supported for 'lar' coding method.NFz&X and Gram cannot both be unspecified.r$   Tr   r   z2The shapes of the inputs Gram and Xy do not match.Fc              3   (   K   | ]}||j         V  d S Ndtype.0as     rC   	<genexpr>z$_lars_path_solver.<locals>.<genexpr>D  s$      DDQammmmmDDrE   rM           )r   r   )swapnrm2)potrsz(Step		Added		Dropped		Active set size		C.r	   )transloweroverwrite_bgHz>zRegressors in active set degenerate. Dropping a regressor, after %i iterations, i.e. alpha=%.3e, with an active set of %i regressors, and the smallest cholesky pivot element being %.3e. Reduce max_iter or increase eps parameters.z		 r*   zEarly stopping the lars path, as the residues are small and the current value of alpha is no longer well controlled. %i iterations, alpha=%.3e, previous alpha=%.3e, with an active set of %i regressors.)rY   .      ?)decimalsoutc                 :    g | ]}                     |          S  )pop)rP   iiactives     rC   
<listcomp>z%_lars_path_solver.<locals>.<listcomp>\  s#    5552

2555rE   )?rA   sizenpdotTcopy
isinstancestrshapeminsetlennextiterfloat64zerosarraylistarangeemptyint8rN   r   get_blas_funcsr   printsysstdoutwriteflushfinfofloat32tiny	precisionr6   argmaxabsfabsnewaxis	ones_likesignsolve_triangularSOLVE_TRIANGULAR_ARGSmaxsqrtwarningswarnitemr   appendsumisfiniteflataroundr   min_poswhereresize
zeros_likecholesky_deleteranger_delete)Fr.   r/   r0   r1   r@   r2   r3   r4   r5   r6   r7   r,   r8   r9   r:   Cov
n_featuresmax_featuresdtypesreturn_dtypecoefsalphascoef	prev_coefalpha
prev_alphan_itern_activeindicessign_activedropLrT   rU   solve_choleskytiny32cov_precisionequality_tolerance	Gram_copyCov_copyC_idxC_CssmnCov_not_shortenedcvdiagleast_squares_AAiL_tmpeq_dircorr_eq_dirg1gamma_g2zz_posidxadd_featuresrc   drop_idxresidualtemprd   sF                                                                        @rC   rB   rB     sY   H 8UVVV&2		I	zfQS!nnggii|tu}}9EFFF 	D#		 46>>TT\\4<<171:
226!#q>>DDDD	 yy{{|WQZ

Yq\
:*j111QRRR !-DL FF3KKx,,LDD1aT"2DDDDDF
6{{aDLL)) z 
,*J7|LLL,*,??? HZ|444HZ|444 
 HcU,///HcU,///  FHffbi
33OFG(<rw777KD |HlL1AAA*+;aTBB
ddHlL1DDD*+;cVDD
d(aT::^ Q;;DEEEEJS!!!JXbj!!&FHSY''1M"*--1IIKK	88::I8 	 /	#	"&++..UB  GBKKA 	*62:-.E=D
BJ 67Jfqj)Iy=a8y#555558i'((+===A:: %Q-)3
1a8PQB'"y0@*AADG$a % $fXZ!7!7 K	  4(*R(8(8H%%(*H%UX-qA!%c%j#a&!9!9CJA%,QZ"GAJ
 #abb'C|!%ac!fac!f!5!5AADX''1,)+Hqs9H9~?O)P)P(IXI%&& $(4Qa#9#9 Qa)-d111a4j$qqq!t*)E)E&QQQT
DAJ8+,)-h		.A)B(IXI%&  'ixi(*+h		)*  $  ,   q9H9,-q9H91D/EFFArwrva!e}}--s33D$(Ah !d{{ C uzz||Xt<= '	 	 	 (A%)T#e*c!f%=%="E
CFMM'(+,,,MH{{4:FFF2JJJHHHVWVWX   W!
1a0H0H
 M "(z7H7H( S	T
 #    *>ixi("#[(%;4
 
 
q ""}'9'9!"M#BB rwrvmk)8)6L&LMMNNNB;r?? yy)8)+,1133+b// GOOx!|O,,,A<,,,'5~K		2$( ( ($M1 bf][(5K%KLLcRRCrws||+BFA +b//  RM<VAC		N,m<<F &XYY88KK
 &ixi&:!;!=}MMK 		+;GGGGSR+-=-F GHH 	)QV__FF#QWk1AF1J$KLLBRR((F &\M]V34"1%%6>>(1:&&q)$$B$/C !,C 00K  D! 	'Q''%Y 3q<(+B#D#DD	%&<*?)LMM()|mnn%66L+@AA)*}~~&=Dfqj)II I!!HJqM=&&D (6M+AAV 	v##  -	Fg%% H H*1YhY		-A+BBGGGGMH5555555H| P PB"2x00 P P-1T!#a&!#a!e*-E-E*AAE
5<QU^WQZ2
GAENNP rva9H9otF|DDDvac(mX66eD#I& V VB"2x00 V V5<QU^WQZ2
GAEN/3tDGT!a%[/I/I,Qa!e59T$qqq!t*d111aRSe8n5U5U2QQQT
DAENNV  )BF9X3F,M,MMeD#I&)K55K)K55K{{vvrrr888XXXs4yyyB  MIV  '&1*%l
l# 	+657F22657** 	'&$..&$&&rE   c                   b   e Zd ZU dZdgdgd edh          ej         ed          g ee	ddd          g ee
d	dd          gdgdg ee
d	dd          dgd
gd	Zeed<   dZdZdddd ej        e          j        ddddd	dZed             ZddZ ed          dd            ZdS )Larsa  Least Angle Regression model a.k.a. LAR.

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    verbose : bool or int, default=False
        Sets the verbosity amount.

    precompute : bool, 'auto' or array-like , default='auto'
        Whether to use a precomputed Gram matrix to speed up
        calculations. If set to ``'auto'`` let us decide. The Gram
        matrix can also be passed as argument.

    n_nonzero_coefs : int, default=500
        Target number of non-zero coefficients. Use ``np.inf`` for no limit.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_X : bool, default=True
        If ``True``, X will be copied; else, it may be overwritten.

    fit_path : bool, default=True
        If True the full path is stored in the ``coef_path_`` attribute.
        If you compute the solution for a large problem or many targets,
        setting ``fit_path`` to ``False`` will lead to a speedup, especially
        with a small alpha.

    jitter : float, default=None
        Upper bound on a uniform noise parameter to be added to the
        `y` values, to satisfy the model's assumption of
        one-at-a-time computations. Might help with stability.

        .. versionadded:: 0.23

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for jittering. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`. Ignored if `jitter` is None.

        .. versionadded:: 0.23

    Attributes
    ----------
    alphas_ : array-like of shape (n_alphas + 1,) or list of such arrays
        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
        is smaller. If this is a list of array-like, the length of the outer
        list is `n_targets`.

    active_ : list of shape (n_alphas,) or list of such lists
        Indices of active variables at the end of the path.
        If this is a list of list, the length of the outer list is `n_targets`.

    coef_path_ : array-like of shape (n_features, n_alphas + 1) or list             of such arrays
        The varying values of the coefficients along the path. It is not
        present if the ``fit_path`` parameter is ``False``. If this is a list
        of array-like, the length of the outer list is `n_targets`.

    coef_ : array-like of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the formulation formula).

    intercept_ : float or array-like of shape (n_targets,)
        Independent term in decision function.

    n_iter_ : array-like or int
        The number of iterations taken by lars_path to find the
        grid of alphas for each target.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    lars_path: Compute Least Angle Regression or Lasso
        path using LARS algorithm.
    LarsCV : Cross-validated Least Angle Regression model.
    sklearn.decomposition.sparse_encode : Sparse coding.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> reg = linear_model.Lars(n_nonzero_coefs=1)
    >>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1.1111, 0, -1.1111])
    Lars(n_nonzero_coefs=1)
    >>> print(reg.coef_)
    [ 0. -1.11...]
    r%   r,   r$   Nr   r&   r'   r   random_state	fit_interceptr,   
precomputen_nonzero_coefsr6   r5   fit_pathjitterr   _parameter_constraintsr)   FTr=   c       	             || _         || _        || _        || _        || _        || _        || _        || _        |	| _        d S rL   r   )
selfr   r,   r   r   r6   r5   r   r   r   s
             rC   __init__zLars.__init__  sL     +$. (rE   c                     t          | d          sW| du s9| dk    r|j        d         |j        d         k    s| dk    r+|j        d         dk    rt          j        |j        |          } | S )N	__array__Tr$   r   r   )hasattrrm   rg   rh   ri   )r   r.   r/   s      rC   	_get_gramzLars._get_gram,  sp    
K00 	(4f$$agaj)@)@f$$aQJrE   c                    |j         d         }t          ||| j        | j                  \  }}}}	}
|j        dk    r|ddt
          j        f         }|j         d         }|                     | j        ||          }g | _	        g | _
        t          j        ||f|j                  | _        |rXg | _        g | _        t!          |          D ]}|dn|dd|f         }t#          ||dd|f         ||| j        d|| j        t'          d| j        dz
            || j        dd| j                  \  }}}}| j	                            |           | j                            |           | j
                            |           | j                            |           |dddf         | j        |<   |dk    rOd	 | j	        | j        | j        | j        fD             \  | _	        | _        | _        | _        | j
        d         | _
        nt!          |          D ]}|dn|dd|f         }t#          ||dd|f         ||| j        d|| j        t'          d| j        dz
            || j        d
d| j                  \  }}| j        |<   }| j	                            |           | j
                            |           |dk    r$| j	        d         | _	        | j
        d         | _
        |                     ||	|
           | S )z=Auxiliary method to fit the model using X, y as training datar   r   rj   NrM   Tr   )r1   r0   r5   r7   r3   r4   r,   r2   r6   r8   r9   r:   r[   c                     g | ]
}|d          S )r   ra   rO   s     rC   re   zLars._fit.<locals>.<listcomp>f  s2     K K K aDK K KrE   F)rm   r"   r   r5   ndimrg   r   r   r   alphas_n_iter_rx   rN   coef_active_
coef_path_r   rD   r4   r   r,   r6   r:   r   _set_intercept)r   r.   r/   r2   r   r   r0   r   X_offsety_offsetX_scale	n_targetsr1   kthis_Xyr   rd   	coef_pathr   r   s                       rC   _fitz	Lars._fit7  s?   WQZ
,<q 2-
 -
 -
)1h' 6Q;;!!!RZ- AGAJ	~~doq!44Xy*5QWEEE
 8	/DL DO9%% 1 1"$*$$"QQQT(5>aaadG;"#;4<!#344% $"&!]6 6 62	7  ##F+++##F+++##G,,,&&y111 )!!!R% 0
1A~~K K"lDL$/4:VK K KGdlDOTZ  $|A9%% - -"$*$$"QQQT(4=aaadG;"#;4<!#344% %"&!]5 5 514:a='  ##F+++##G,,,,A~~#|A#|AHh888rE   r;   c                 l   t          | ||ddd          \  }}t          | dd          }t          | d          r
d}| j        }n| j        }| j        Bt          | j                  }|                    | j        t          |                    }||z   }| 
                    ||||| j        |           | S )	aU  Fit the model using X, y as training data.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data.

        y : array-like of shape (n_samples,) or (n_samples, n_targets)
            Target values.

        Xy : array-like of shape (n_features,) or (n_features, n_targets),                 default=None
            Xy = np.dot(X.T, y) that can be precomputed. It is useful
            only when the Gram matrix is precomputed.

        Returns
        -------
        self : object
            Returns an instance of self.
        T)force_writeable	y_numericmulti_outputr   rS   r   N)highrf   )r2   r   r   r0   )r   getattrr   r   r2   r   r   r   uniformrp   r   r   )r   r.   r/   r0   r   r2   rngnoises           rC   fitzLars.fit  s    , !Q4
 
 
1 gs++4*++ 	%E+HH}H;"$T%677CKKT[s1vvK>>EE	A		] 	 	
 	
 	
 rE   rL   )__name__
__module____qualname____doc__r   rg   ndarrayr   r   r   r   r   dict__annotations__r4   r:   r   floatr6   r   staticmethodr   r   r   r   ra   rE   rC   r   r     s}        k k\ $; **fX"6"6
FF4LLQ$HXq$vFFFGq$v6667+K8D!T&9994@'(
$ 
$D 
 
 
 FH
 BHUOO) ) ) ) ).   \N N N N` \555/ / / 65/ / /rE   r   c                       e Zd ZU dZi ej         eeddd          g eeddd          gdgdZe	e
d<   e                    d	           d
Z	 ddddd ej        e          j        dddddd
dZdS )	LassoLarsa|  Lasso model fit with Least Angle Regression a.k.a. Lars.

    It is a Linear Model trained with an L1 prior as regularizer.

    The optimization objective for Lasso is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    alpha : float, default=1.0
        Constant that multiplies the penalty term. Defaults to 1.0.
        ``alpha = 0`` is equivalent to an ordinary least square, solved
        by :class:`LinearRegression`. For numerical reasons, using
        ``alpha = 0`` with the LassoLars object is not advised and you
        should prefer the LinearRegression object.

    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    verbose : bool or int, default=False
        Sets the verbosity amount.

    precompute : bool, 'auto' or array-like, default='auto'
        Whether to use a precomputed Gram matrix to speed up
        calculations. If set to ``'auto'`` let us decide. The Gram
        matrix can also be passed as argument.

    max_iter : int, default=500
        Maximum number of iterations to perform.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_X : bool, default=True
        If True, X will be copied; else, it may be overwritten.

    fit_path : bool, default=True
        If ``True`` the full path is stored in the ``coef_path_`` attribute.
        If you compute the solution for a large problem or many targets,
        setting ``fit_path`` to ``False`` will lead to a speedup, especially
        with a small alpha.

    positive : bool, default=False
        Restrict coefficients to be >= 0. Be aware that you might want to
        remove fit_intercept which is set True by default.
        Under the positive restriction 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 the stepwise Lars-Lasso
        algorithm are typically in congruence with the solution of the
        coordinate descent Lasso estimator.

    jitter : float, default=None
        Upper bound on a uniform noise parameter to be added to the
        `y` values, to satisfy the model's assumption of
        one-at-a-time computations. Might help with stability.

        .. versionadded:: 0.23

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for jittering. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`. Ignored if `jitter` is None.

        .. versionadded:: 0.23

    Attributes
    ----------
    alphas_ : array-like of shape (n_alphas + 1,) or list of such arrays
        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
        is smaller. If this is a list of array-like, the length of the outer
        list is `n_targets`.

    active_ : list of length n_alphas or list of such lists
        Indices of active variables at the end of the path.
        If this is a list of list, the length of the outer list is `n_targets`.

    coef_path_ : array-like of shape (n_features, n_alphas + 1) or list             of such arrays
        If a list is passed it's expected to be one of n_targets such arrays.
        The varying values of the coefficients along the path. It is not
        present if the ``fit_path`` parameter is ``False``. If this is a list
        of array-like, the length of the outer list is `n_targets`.

    coef_ : array-like of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the formulation formula).

    intercept_ : float or array-like of shape (n_targets,)
        Independent term in decision function.

    n_iter_ : array-like or int
        The number of iterations taken by lars_path to find the
        grid of alphas for each target.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    lars_path : Compute Least Angle Regression or Lasso
        path using LARS algorithm.
    lasso_path : Compute Lasso path with coordinate descent.
    Lasso : Linear Model trained with L1 prior as
        regularizer (aka the Lasso).
    LassoCV : Lasso linear model with iterative fitting
        along a regularization path.
    LassoLarsCV: Cross-validated Lasso, using the LARS algorithm.
    LassoLarsIC : Lasso model fit with Lars using BIC
        or AIC for model selection.
    sklearn.decomposition.sparse_encode : Sparse coding.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> reg = linear_model.LassoLars(alpha=0.01)
    >>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1, 0, -1])
    LassoLars(alpha=0.01)
    >>> print(reg.coef_)
    [ 0.         -0.955...]
    r   Nr&   r'   r%   )r   r2   r:   r   r   r*   r]   TFr$   r=   )
r   r,   r   r2   r6   r5   r   r:   r   r   c       
             || _         || _        || _        || _        |	| _        || _        || _        || _        || _        |
| _	        || _
        d S rL   )r   r   r2   r,   r:   r   r5   r6   r   r   r   )r   r   r   r,   r   r2   r6   r5   r   r:   r   r   s               rC   r   zLassoLars.__init__Q  sY     
*  $ (rE   )r]   )r   r   r   r  r   r   r   r   r   r  r  rb   r4   rg   r   r  r6   r   ra   rE   rC   r  r    s         J JX$

%$(4D8889Xh4???@K	$ $ $D    0111F ) BHUOO) ) ) ) ) ) )rE   r  c                 J    |s| j         j        s|                                 S | S rL   )flags	writeablerj   )ru   rj   s     rC   _check_copy_and_writeabler  q  s)     5;( zz||LrE   c                    t          | |          } t          ||          }t          ||          }t          ||          }|rb|                     d          }| |z  } ||z  }|                    d          }t          |d          }||z  }t          |d          }||z  }t          | ||dd|t	          d|dz
            |	|
|
  
        \  }}}t          j        ||          |ddt
          j        f         z
  }||||j        fS )ab
  Compute the residues on left-out data for a full LARS path

    Parameters
    -----------
    X_train : array-like of shape (n_samples, n_features)
        The data to fit the LARS on

    y_train : array-like of shape (n_samples,)
        The target variable to fit LARS on

    X_test : array-like of shape (n_samples, n_features)
        The data to compute the residues on

    y_test : array-like of shape (n_samples,)
        The target variable to compute the residues on

    Gram : None, 'auto' or array-like of shape (n_features, n_features),             default=None
        Precomputed Gram matrix (X' * X), if ``'auto'``, the Gram
        matrix is precomputed from the given X, if there are more samples
        than features

    copy : bool, default=True
        Whether X_train, X_test, y_train and y_test should be copied;
        if False, they may be overwritten.

    method : {'lar' , 'lasso'}, default='lar'
        Specifies the returned model. Select ``'lar'`` for Least Angle
        Regression, ``'lasso'`` for the Lasso.

    verbose : bool or int, default=False
        Sets the amount of verbosity

    fit_intercept : bool, default=True
        whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    positive : bool, default=False
        Restrict coefficients to be >= 0. Be aware that you might want to
        remove fit_intercept which is set True by default.
        See reservations for using this option in combination with method
        'lasso' for expected small values of alpha in the doc of LassoLarsCV
        and LassoLarsIC.

    max_iter : int, default=500
        Maximum number of iterations to perform.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    Returns
    --------
    alphas : array-like of shape (n_alphas,)
        Maximum of covariances (in absolute value) at each iteration.
        ``n_alphas`` is either ``max_iter`` or ``n_features``, whichever
        is smaller.

    active : list
        Indices of active variables at the end of the path.

    coefs : array-like of shape (n_features, n_alphas)
        Coefficients along the path

    residues : array-like of shape (n_alphas, n_samples)
        Residues of the prediction on the test data
    r   axisFrj   r   )r1   r5   r7   r4   r,   r2   r6   r:   N)	r  meanr   rD   r   rg   rh   r   ri   )X_trainy_trainX_testy_testr1   rj   r4   r,   r   r2   r6   r:   X_meany_meanr   rd   r   residuess                     rC   _lars_path_residuesr  w  s:   j (66G'66G&vt44F&vt44F 1%%6&1%% u5556U333&%Aw{##  FFE vfe$$vaaam'<<H65(*,,rE   c            
       :    e Zd ZU dZi ej         eeddd          gdg eeddd          gedgdZee	d	<   d
D ]Z
e                    e
           dZddddddd ej        e          j        dd	 fd
Z fdZ ed          d             Zd Z xZS )LarsCVaw  Cross-validated Least Angle Regression model.

    See glossary entry for :term:`cross-validation estimator`.

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    verbose : bool or int, default=False
        Sets the verbosity amount.

    max_iter : int, default=500
        Maximum number of iterations to perform.

    precompute : bool, 'auto' or array-like , default='auto'
        Whether to use a precomputed Gram matrix to speed up
        calculations. If set to ``'auto'`` let us decide. The Gram matrix
        cannot be passed as argument since we will use only subsets of X.

    cv : int, cross-validation generator or an iterable, default=None
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 5-fold cross-validation,
        - integer, to specify the number of folds.
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, :class:`~sklearn.model_selection.KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.22
            ``cv`` default value if None changed from 3-fold to 5-fold.

    max_n_alphas : int, default=1000
        The maximum number of points on the path used to compute the
        residuals in the cross-validation.

    n_jobs : int or None, default=None
        Number of CPUs to use during the cross validation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_X : bool, default=True
        If ``True``, X will be copied; else, it may be overwritten.

    Attributes
    ----------
    active_ : list of length n_alphas or list of such lists
        Indices of active variables at the end of the path.
        If this is a list of lists, the outer list length is `n_targets`.

    coef_ : array-like of shape (n_features,)
        parameter vector (w in the formulation formula)

    intercept_ : float
        independent term in decision function

    coef_path_ : array-like of shape (n_features, n_alphas)
        the varying values of the coefficients along the path

    alpha_ : float
        the estimated regularization parameter alpha

    alphas_ : array-like of shape (n_alphas,)
        the different values of alpha along the path

    cv_alphas_ : array-like of shape (n_cv_alphas,)
        all the values of alpha along the path for the different folds

    mse_path_ : array-like of shape (n_folds, n_cv_alphas)
        the mean square error on left-out for each fold along the path
        (alpha values given by ``cv_alphas``)

    n_iter_ : array-like or int
        the number of iterations run by Lars with the optimal alpha.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    lars_path : Compute Least Angle Regression or Lasso
        path using LARS algorithm.
    lasso_path : Compute Lasso path with coordinate descent.
    Lasso : Linear Model trained with L1 prior as
        regularizer (aka the Lasso).
    LassoCV : Lasso linear model with iterative fitting
        along a regularization path.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    LassoLarsIC : Lasso model fit with Lars using BIC
        or AIC for model selection.
    sklearn.decomposition.sparse_encode : Sparse coding.

    Notes
    -----
    In `fit`, once the best parameter `alpha` is found through
    cross-validation, the model is fit again using the entire training set.

    Examples
    --------
    >>> from sklearn.linear_model import LarsCV
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(n_samples=200, noise=4.0, random_state=0)
    >>> reg = LarsCV(cv=5).fit(X, y)
    >>> reg.score(X, y)
    0.9996...
    >>> reg.alpha_
    np.float64(0.2961...)
    >>> reg.predict(X[:1,])
    array([154.3996...])
    r   Nr&   r'   	cv_objectr   )r2   cvmax_n_alphasn_jobsr   )r   r   r   r   r)   TFr=   r$     )	r   r,   r2   r   r  r  r   r6   r5   c       	   	          || _         || _        || _        || _        t	                                          |||d||	d           d S )Nr=   T)r   r,   r   r   r6   r5   r   )r2   r  r  r   superr   )r   r   r,   r2   r   r  r  r   r6   r5   	__class__s             rC   r   zLarsCV.__init__  sb     !('! 	 	
 	
 	
 	
 	
rE   c                 `    t                                                      }d|j        _        |S NFr#  __sklearn_tags__target_tagsr   r   tagsr$  s     rC   r(  zLarsCV.__sklearn_tags__  (    ww''))(-%rE   r;   c                 @    t          | d           t           dd          \  t           j                  t           j                  t	           j        d          }t                      rt           dfi |}nt          t          i                     } j	        t          d	          r#t          j        d
 j        j        z             d t           j         j                   fd |j        fi |j        j        D                       }t)          j        t-          t/          |           d                   }t)          j        |          }t3          t5          dt3          t7          |          t9           j                  z                                }|dd|         }t)          j        t7          |          t7          |          f          }	t?          |          D ]\  }
\  }}}}|ddd         }|ddd         }|d         dk    r:t(          j         d|f         }t(          j         |dt(          j!        f         |f         }|d         |d         k    r@t(          j         ||d         f         }t(          j         ||dt(          j!        f         f         } tE          j#        ||d          |          }|dz  }t)          j$        |d          |	dd|
f<   t)          j%        t)          j&        |	          d          }||         }|	|         }	t)          j'        |	$                    d                    }||         }| _(        | _)        |	 _*         +                     j,        |dd            S )a  Fit the model using X, y as training data.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data.

        y : array-like of shape (n_samples,)
            Target values.

        **params : dict, default=None
            Parameters to be passed to the CV splitter.

            .. versionadded:: 1.4
                Only available if `enable_metadata_routing=True`,
                which can be set by using
                ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>` for
                more details.

        Returns
        -------
        self : object
            Returns an instance of self.
        r   Tr   r   r  F)
classifier)split)splitterr   zXParameter "precompute" cannot be an array in %s. Automatically switch to "auto" instead.r$   )r   r,   c              3      K   | ]w\  }} t          t                    |         |         |         |         d j        t          dj        dz
            j        j        j        j                  V  xdS )Fr   r   )r1   rj   r4   r,   r   r2   r6   r:   N)	r   r  r4   r   r,   r   r2   r6   r:   )rP   traintestr1   r.   r   r/   s      rC   rR   zLarsCV.fit.<locals>.<genexpr>  s       F
 F
 t )G'((%%$${At|a/00"0H  F
 F
 F
 F
 F
 F
rE   r   r   Nr[   r  r	   )r2   r   r0   r   )-r   r   r   r5   r   r  r   r   r   r   r   r   r   r$  r   r   r   r,   r0  r1  rg   concatenaterv   zipuniqueintr   rp   r  r  rx   	enumerater   r   r   interp1dr  allr   argminalpha_
cv_alphas_	mse_path_r   r2   )r   r.   r/   paramsr  routed_paramscv_paths
all_alphasstridemse_pathindexr   r   r  this_residuesmaski_best_alpha
best_alphar1   s   ```               @rC   r   z
LarsCV.fit  s   6 	&$...T1aNNN114;///14;/// dg%000 	<+D%BB6BBMM!5r???;;;M 4%% 	M>@D@WX   DE84;EEE F
 F
 F
 F
 F
 F
 F
  (rx1MM0F0LMMF
 F
 F
 
 
" ^Dh$8$8$;<<
Yz**
SCJ%8I2J2J JKKLLMM&)
8S__c(mm<==/8/B/B 	A 	A+E+FAq(DDbD\F"~HayA~~q&y)5!RZ-!8(!BCbzZ^++vz"~5658B
N+C!CDJK0JJJ:VVMaM!#R!@!@!@HQQQXvbk(++"555%
D>yB!7!788-
 !$!
 			] 	 	
 	
 	
 rE   c                     t          | j        j                                      t	          | j                  t                                          dd                    }|S )aj  Get metadata routing of this object.

        Please check :ref:`User Guide <metadata_routing>` on how the routing
        mechanism works.

        .. versionadded:: 1.4

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        )ownerr   r0  )callercallee)r1  method_mapping)r   r$  r   addr   r  r   )r   routers     rC   get_metadata_routingzLarsCV.get_metadata_routing  s]      dn&=>>>BBdg&&(??..eG.LL C 
 
 rE   )r   r   r   r  r   r   r   r   r  r  	parameterrb   r4   rg   r   r  r6   r   r(  r   r   rR  __classcell__r$  s   @rC   r  r    sp        F FP$

%$Xh4???@m!(AtFCCCDT"$ $ $D    O . .	""9----F
 BHUOO
 
 
 
 
 
 
6    
 \555n n 65n`      rE   r  c                   v    e Zd ZdZi ej        ddgiZdZddddd	d
d	 ej        e	          j
        ddd
dZd	S )LassoLarsCVa  Cross-validated Lasso, using the LARS algorithm.

    See glossary entry for :term:`cross-validation estimator`.

    The optimization objective for Lasso is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    Read more in the :ref:`User Guide <least_angle_regression>`.

    Parameters
    ----------
    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    verbose : bool or int, default=False
        Sets the verbosity amount.

    max_iter : int, default=500
        Maximum number of iterations to perform.

    precompute : bool or 'auto' , default='auto'
        Whether to use a precomputed Gram matrix to speed up
        calculations. If set to ``'auto'`` let us decide. The Gram matrix
        cannot be passed as argument since we will use only subsets of X.

    cv : int, cross-validation generator or an iterable, default=None
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 5-fold cross-validation,
        - integer, to specify the number of folds.
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, :class:`~sklearn.model_selection.KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.22
            ``cv`` default value if None changed from 3-fold to 5-fold.

    max_n_alphas : int, default=1000
        The maximum number of points on the path used to compute the
        residuals in the cross-validation.

    n_jobs : int or None, default=None
        Number of CPUs to use during the cross validation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_X : bool, default=True
        If True, X will be copied; else, it may be overwritten.

    positive : bool, default=False
        Restrict coefficients to be >= 0. Be aware that you might want to
        remove fit_intercept which is set True by default.
        Under the positive restriction the model coefficients do 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 the stepwise Lars-Lasso
        algorithm are typically in congruence with the solution of the
        coordinate descent Lasso estimator.
        As a consequence using LassoLarsCV only makes sense for problems where
        a sparse solution is expected and/or reached.

    Attributes
    ----------
    coef_ : array-like of shape (n_features,)
        parameter vector (w in the formulation formula)

    intercept_ : float
        independent term in decision function.

    coef_path_ : array-like of shape (n_features, n_alphas)
        the varying values of the coefficients along the path

    alpha_ : float
        the estimated regularization parameter alpha

    alphas_ : array-like of shape (n_alphas,)
        the different values of alpha along the path

    cv_alphas_ : array-like of shape (n_cv_alphas,)
        all the values of alpha along the path for the different folds

    mse_path_ : array-like of shape (n_folds, n_cv_alphas)
        the mean square error on left-out for each fold along the path
        (alpha values given by ``cv_alphas``)

    n_iter_ : array-like or int
        the number of iterations run by Lars with the optimal alpha.

    active_ : list of int
        Indices of active variables at the end of the path.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    lars_path : Compute Least Angle Regression or Lasso
        path using LARS algorithm.
    lasso_path : Compute Lasso path with coordinate descent.
    Lasso : Linear Model trained with L1 prior as
        regularizer (aka the Lasso).
    LassoCV : Lasso linear model with iterative fitting
        along a regularization path.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    LassoLarsIC : Lasso model fit with Lars using BIC
        or AIC for model selection.
    sklearn.decomposition.sparse_encode : Sparse coding.

    Notes
    -----
    The object solves the same problem as the
    :class:`~sklearn.linear_model.LassoCV` object. However, unlike the
    :class:`~sklearn.linear_model.LassoCV`, it find the relevant alphas values
    by itself. In general, because of this property, it will be more stable.
    However, it is more fragile to heavily multicollinear datasets.

    It is more efficient than the :class:`~sklearn.linear_model.LassoCV` if
    only a small number of features are selected compared to the total number,
    for instance if there are very few samples compared to the number of
    features.

    In `fit`, once the best parameter `alpha` is found through
    cross-validation, the model is fit again using the entire training set.

    Examples
    --------
    >>> from sklearn.linear_model import LassoLarsCV
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(noise=4.0, random_state=0)
    >>> reg = LassoLarsCV(cv=5).fit(X, y)
    >>> reg.score(X, y)
    0.9993...
    >>> reg.alpha_
    np.float64(0.3972...)
    >>> reg.predict(X[:1,])
    array([-78.4831...])
    r:   r%   r*   TFr=   r$   Nr!  
r   r,   r2   r   r  r  r   r6   r5   r:   c       
             || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        d S rL   rX  )r   r   r,   r2   r   r  r  r   r6   r5   r:   s              rC   r   zLassoLarsCV.__init__  sP     + $( rE   )r   r   r   r  r  r   r4   rg   r   r  r6   r   ra   rE   rC   rW  rW  '  s        ` `D

'YK 
 F
 BHUOO! ! ! ! ! ! !rE   rW  c            
       *    e Zd ZU dZi ej         eddh          g eeddd          dgdZe	e
d	<   d
D ]Ze                    e           	 ddddd ej        e          j        dddddZ fdZ ed          dd            Zd Z xZS )LassoLarsICa  Lasso model fit with Lars using BIC or AIC for model selection.

    The optimization objective for Lasso is::

    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

    AIC is the Akaike information criterion [2]_ and BIC is the Bayes
    Information criterion [3]_. Such criteria are useful to select the value
    of the regularization parameter by making a trade-off between the
    goodness of fit and the complexity of the model. A good model should
    explain well the data while being simple.

    Read more in the :ref:`User Guide <lasso_lars_ic>`.

    Parameters
    ----------
    criterion : {'aic', 'bic'}, default='aic'
        The type of criterion to use.

    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    verbose : bool or int, default=False
        Sets the verbosity amount.

    precompute : bool, 'auto' or array-like, default='auto'
        Whether to use a precomputed Gram matrix to speed up
        calculations. If set to ``'auto'`` let us decide. The Gram
        matrix can also be passed as argument.

    max_iter : int, default=500
        Maximum number of iterations to perform. Can be used for
        early stopping.

    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
        optimization-based algorithms, this parameter does not control
        the tolerance of the optimization.

    copy_X : bool, default=True
        If True, X will be copied; else, it may be overwritten.

    positive : bool, default=False
        Restrict coefficients to be >= 0. Be aware that you might want to
        remove fit_intercept which is set True by default.
        Under the positive restriction the model coefficients do 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 the stepwise Lars-Lasso
        algorithm are typically in congruence with the solution of the
        coordinate descent Lasso estimator.
        As a consequence using LassoLarsIC only makes sense for problems where
        a sparse solution is expected and/or reached.

    noise_variance : float, default=None
        The estimated noise variance of the data. If `None`, an unbiased
        estimate is computed by an OLS model. However, it is only possible
        in the case where `n_samples > n_features + fit_intercept`.

        .. versionadded:: 1.1

    Attributes
    ----------
    coef_ : array-like of shape (n_features,)
        parameter vector (w in the formulation formula)

    intercept_ : float
        independent term in decision function.

    alpha_ : float
        the alpha parameter chosen by the information criterion

    alphas_ : array-like of shape (n_alphas + 1,) or list of such arrays
        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
        is smaller. If a list, it will be of length `n_targets`.

    n_iter_ : int
        number of iterations run by lars_path to find the grid of
        alphas.

    criterion_ : array-like of shape (n_alphas,)
        The value of the information criteria ('aic', 'bic') across all
        alphas. The alpha which has the smallest information criterion is
        chosen, as specified in [1]_.

    noise_variance_ : float
        The estimated noise variance from the data used to compute the
        criterion.

        .. versionadded:: 1.1

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    lars_path : Compute Least Angle Regression or Lasso
        path using LARS algorithm.
    lasso_path : Compute Lasso path with coordinate descent.
    Lasso : Linear Model trained with L1 prior as
        regularizer (aka the Lasso).
    LassoCV : Lasso linear model with iterative fitting
        along a regularization path.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    LassoLarsCV: Cross-validated Lasso, using the LARS algorithm.
    sklearn.decomposition.sparse_encode : Sparse coding.

    Notes
    -----
    The number of degrees of freedom is computed as in [1]_.

    To have more details regarding the mathematical formulation of the
    AIC and BIC criteria, please refer to :ref:`User Guide <lasso_lars_ic>`.

    References
    ----------
    .. [1] :arxiv:`Zou, Hui, Trevor Hastie, and Robert Tibshirani.
            "On the degrees of freedom of the lasso."
            The Annals of Statistics 35.5 (2007): 2173-2192.
            <0712.0881>`

    .. [2] `Wikipedia entry on the Akaike information criterion
            <https://en.wikipedia.org/wiki/Akaike_information_criterion>`_

    .. [3] `Wikipedia entry on the Bayesian information criterion
            <https://en.wikipedia.org/wiki/Bayesian_information_criterion>`_

    Examples
    --------
    >>> from sklearn import linear_model
    >>> reg = linear_model.LassoLarsIC(criterion='bic')
    >>> X = [[-2, 2], [-1, 1], [0, 0], [1, 1], [2, 2]]
    >>> y = [-2.2222, -1.1111, 0, -1.1111, -2.2222]
    >>> reg.fit(X, y)
    LassoLarsIC(criterion='bic')
    >>> print(reg.coef_)
    [ 0.  -1.11...]
    aicbicr   Nr&   r'   )	criterionnoise_variancer   )r   r   r   r   TFr$   r=   )r   r,   r   r2   r6   r5   r:   r_  c                    || _         || _        || _        || _        || _        || _        || _        || _        d| _        |	| _	        d S )NT)
r^  r   r:   r2   r,   r5   r   r6   r   r_  )
r   r^  r   r,   r   r2   r6   r5   r:   r_  s
             rC   r   zLassoLarsIC.__init__  sR     #*  $,rE   c                 `    t                                                      }d|j        _        |S r&  r'  r*  s     rC   r(  zLassoLarsIC.__sklearn_tags__  r,  rE   r;   c                     || j         }t          | ||dd          \  }}t          ||| j        |          \  }}}}}| j        }t          ||||ddd| j        | j        | j        d| j	                  \  }}	}
| _
        |j        d         }| j        d	k    rd
}n2| j        dk    rt          |          }nt          d| j                  |ddt          j        f         t          j        ||
          z
  }t          j        |d
z  d          }t          j        |
j        d         t(                    }t+          |
j                  D ]e\  }}t          j        |          t          j        |j                  j        k    }t          j        |          sNt          j        |          ||<   f|| _        | j        #|                     ||| j	                  | _        n| j        | _        |t          j        d
t          j        z  | j        z            z  || j        z  z   ||z  z   | _         t          j!        | j                   }||         | _"        |
dd|f         | _#        | $                    |||           | S )a]  Fit the model using X, y as training data.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data.

        y : array-like of shape (n_samples,)
            Target values. Will be cast to X's dtype if necessary.

        copy_X : bool, default=None
            If provided, this parameter will override the choice
            of copy_X made at instance creation.
            If ``True``, X will be copied; else, it may be overwritten.

        Returns
        -------
        self : object
            Returns an instance of self.
        NTr.  r   rS   r*   )
r1   r5   r7   r3   r4   r,   r2   r6   r9   r:   r   r\  r	   r]  z+criterion should be either bic or aic, got r  r   rM   )r:   )%r5   r   r"   r   r   rD   r,   r2   r6   r:   r   rm   r^  r   rA   rg   r   rh   r   rt   r8  r9  ri   r   r   rN   anyr   r_  _estimate_noise_variancenoise_variance_pi
criterion_r<  r=  r   r   )r   r.   r/   r5   XmeanymeanXstdr1   r   r   r   r@   criterion_factor	residualsresiduals_sum_squaresdegrees_of_freedomr   r   rH  n_bests                       rC   r   zLassoLarsIC.fit  s   , >[FT1aNNN1#3q 2$
 $
 $
 1eUD /8L]]0
 0
 0
,J GAJ	>U"" ^u$$"9~~PdnPP   aaam$rva'<'<<	 "y!|! < < <Xj&6q&9EEE .. 	1 	1GAt6$<<"(4:"6"6"::D6$<<  %'F4LLq!!&#'#@#@1t} $A $ $D   $(#6D  q25y4+??@@@#d&::;!334 	
 4?++fo6	*
E5$///rE   c                 t   |j         d         |j         d         | j        z   k    rt          d| j        j         d          t          |d          }|                    ||                              |          }t          j	        ||z
  dz            |j         d         |j         d         z
  | j        z
  z  S )an  Compute an estimate of the variance with an OLS model.

        Parameters
        ----------
        X : ndarray of shape (n_samples, n_features)
            Data to be fitted by the OLS model. We expect the data to be
            centered.

        y : ndarray of shape (n_samples,)
            Associated target.

        positive : bool, default=False
            Restrict coefficients to be >= 0. This should be inline with
            the `positive` parameter from `LassoLarsIC`.

        Returns
        -------
        noise_variance : float
            An estimator of the noise variance of an OLS model.
        r   r   zYou are using z in the case where the number of samples is smaller than the number of features. In this setting, getting a good estimate for the variance of the noise is not possible. Provide an estimate of the noise variance in the constructor.F)r:   r   r	   )
rm   r   rA   r$  r   r!   r   predictrg   r   )r   r.   r/   r:   	ols_modely_preds         rC   rd  z$LassoLarsIC._estimate_noise_variance	  s    * 71:d&8888!8      %heLLL	q!$$,,Q//vq6za'((GAJ#d&88
 	
rE   )r\  rL   )r   r   r   r  r  r   r   r   r   r  r  rS  rb   rg   r   r  r6   r   r(  r   r   rd  rT  rU  s   @rC   r[  r[    s^        W Wr$

*$ j%001#8D!T&AAA4H$ $ $D    E . .	""9---- - BHUOO- - - - -0    
 \555X X X 65Xt"
 "
 "
 "
 "
 "
 "
rE   r[  rL   )F)?r  r|   r   mathr   numbersr   r   numpyrg   scipyr   r   scipy.linalg.lapackr   baser
   r   r   
exceptionsr   model_selectionr   utilsr   r   r   r   utils._metadata_requestsr   r   r   r   r   utils._param_validationr   r   r   r   utils.parallelr   r   utils.validationr   _baser    r!   r"   r   r  r   r  r6   rD   rH   rB   r   r  r  r  r  rW  r[  ra   rE   rC   <module>r     s    


        " " " " " " " "     % % % % % % % % 0 0 0 0 0 0 A A A A A A A A A A + + + + + + & & & & & &                         T S S S S S S S S S S S . . . . . . . . , , , , , , B B B B B B B B B B'/  j$j$z4 VH%%y"*dCXh4???@htQV<<<=:ug.//0+q$y9994@[;!{#K   #'#  , i
 
i i i i' &iX zlhxD@@@AXh4???@htQV<<<=:ug.//0+q$y9994@[;!{#K  #'!  . [ [ [ [% $[B 	v' v' v' v'z_ _ _ _ _^[ _ _ _D	p) p) p) p) p) p) p) p)n    
	q- q- q- q-hy y y y yT y y yx	A! A! A! A! A!& A! A! A!L}
 }
 }
 }
 }
) }
 }
 }
 }
 }
rE   