
    sg                       d dl Z d dlZd dlZd dlmZmZ d dlmZ d dl mZm	Z	 d dl
Zd dlmZ d dl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mZmZ ddlmZmZmZm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z7 ddl8m9Z9m:Z:m;Z; dAdZ<	 	 	 	 	 	 	 dBdZ= e$ddgddg e"e	d dd      g e"eddd      gddg e#d h      d!dgddgd!gddgd"gd!gd!gd#d$      dddd dddd%d%d%d&
d'       Z> e$ddgddg e"e	d(dd)      g e"e	d(dd      g e"eddd      gddg e#d h      d!dgddgd!gddgd"gd!gd!gd!gd*d$      d+dddd dddd%d%d%dd,d-       Z? G d. d/eee9      Z@ G d0 d1e@      ZA	 	 	 	 dCd2ZB G d3 d4ee9e      ZC G d5 d6eeC      ZD G d7 d8eeC      ZE G d9 d:eA      ZF G d; d<eF      ZG G d= d>eeC      ZH G d? d@eeC      ZIy)D    N)ABCabstractmethod)partial)IntegralReal)effective_n_jobs)sparse)metadata_routing   )MultiOutputMixinRegressorMixin_fit_context)check_cv)Bunchcheck_arraycheck_scalar)MetadataRouterMethodMapping_raise_for_paramsget_routing_for_object)Interval
StrOptionsvalidate_params)safe_sparse_dot)_routing_enabledprocess_routing)Paralleldelayed)_check_sample_weightcheck_consistent_lengthcheck_is_fittedcheck_random_statecolumn_or_1dhas_fit_parametervalidate_data   )_cd_fast)LinearModel_pre_fit_preprocess_datac                 f   |dvrt        dj                  |            t        j                  |       }t        j                  |      }|d|dk(  rdnd}|r| j	                  |d      } nt        j                  | |      } |r|j	                  |      }| |fS t        j                  ||      }| |fS )	a  Change the order of X and y if necessary.

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

    y : ndarray of shape (n_samples,)
        Target values.

    order : {None, 'C', 'F'}
        If 'C', dense arrays are returned as C-ordered, sparse matrices in csr
        format. If 'F', dense arrays are return as F-ordered, sparse matrices
        in csc format.

    Returns
    -------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Training data with guaranteed order.

    y : ndarray of shape (n_samples,)
        Target values with guaranteed order.
    )NCFz<Unknown value for order. Got {} instead of None, 'C' or 'F'.r-   csccsrF)copyorder)
ValueErrorformatr	   issparseasformatnpasarray)Xyr2   sparse_Xsparse_ysparse_formats         [/var/www/html/venv/lib/python3.12/site-packages/sklearn/linear_model/_coordinate_descent.py
_set_orderr?   0   s    0 $$JQQRWX
 	
 q!Hq!H!&#5

=u
5A

1E*A

=)A a4K 

1E*Aa4K          ?TMbP?d   c	                    |dk(  rt        d      ||}	nt        | ||||d      \  } }}
}}|+|j                  dkD  r||j                  dd      z  }n||z  }n|}t	        j
                  |       r2t        | j                  |d	      t        j                  |      |
z  z
  }	n t        j                  | j                  |      }	|	j                  dk(  r|	ddt        j                  f   }	||j                         }n| j                  d   }t        j                  t        j                  |	d
z  d            j                         ||z  z  }|t        j                  t        j                         j"                  k  rAt        j$                  |t        j                  t        j                         j"                        S t        j&                  |||z  |      S )a  Compute the grid of alpha values for elastic net parameter search

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Training data. Pass directly as Fortran-contiguous data to avoid
        unnecessary memory duplication

    y : ndarray of shape (n_samples,) or (n_samples, n_outputs)
        Target values

    Xy : array-like of shape (n_features,) or (n_features, n_outputs),         default=None
        Xy = np.dot(X.T, y) that can be precomputed.

    l1_ratio : float, default=1.0
        The elastic net mixing parameter, with ``0 < l1_ratio <= 1``.
        For ``l1_ratio = 0`` the penalty is an L2 penalty. (currently not
        supported) ``For l1_ratio = 1`` it is an L1 penalty. For
        ``0 < l1_ratio <1``, the penalty is a combination of L1 and L2.

    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``

    n_alphas : int, default=100
        Number of alphas along the regularization path

    fit_intercept : bool, default=True
        Whether to fit an intercept or not

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

    sample_weight : ndarray of shape (n_samples,), default=None
    r   zAutomatic alpha grid generation is not supported for l1_ratio=0. Please supply a grid by providing your estimator with the appropriate `alphas=` argument.NF)fit_interceptr0   sample_weightcheck_inputr&   Tdense_outputr   axis)num)r3   r*   ndimreshaper	   r5   r   Tr7   sumdotnewaxisshapesqrtmaxfinfofloat64
resolutionfull	geomspace)r9   r:   Xyl1_ratiorE   epsn_alphascopy_XrF   XywX_offset_yw	n_samples	alpha_maxs                  r>   _alpha_gridrg   _   s   ^ 1}
 	
 
~/'' 
1h1 $vvz..r155&B??1!!##r=r
X@UUC&&b/C
xx1}!RZZ-  !%%'	GGAJ	sAvA./335X9MNIBHHRZZ(333wwx"**!5!@!@AA<<	9s?AAr@   
array-likezsparse matrixneitherclosedleftautobooleanverbose)r9   r:   r^   r_   alphas
precomputer\   r`   	coef_initro   return_n_iterpositiveprefer_skip_nested_validationF)
r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   c       
         4    t        | |fd||||||||	||
d|S )a  Compute Lasso path with coordinate descent.

    The Lasso optimization function varies for mono and multi-outputs.

    For mono-output tasks it is::

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

    For multi-output tasks it is::

        (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21

    Where::

        ||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

    i.e. the sum of norm of each row.

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

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Training data. Pass directly as Fortran-contiguous data to avoid
        unnecessary memory duplication. If ``y`` is mono-output then ``X``
        can be sparse.

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

    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If ``None`` alphas are set automatically.

    precompute : 'auto', bool or array-like of shape             (n_features, n_features), 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.

    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.

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

    coef_init : array-like of shape (n_features, ), default=None
        The initial values of the coefficients.

    verbose : bool or int, default=False
        Amount of verbosity.

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

    positive : bool, default=False
        If set to True, forces coefficients to be positive.
        (Only allowed when ``y.ndim == 1``).

    **params : kwargs
        Keyword arguments passed to the coordinate descent solver.

    Returns
    -------
    alphas : ndarray of shape (n_alphas,)
        The alphas along the path where models are computed.

    coefs : ndarray of shape (n_features, n_alphas) or             (n_targets, n_features, n_alphas)
        Coefficients along the path.

    dual_gaps : ndarray of shape (n_alphas,)
        The dual gaps at the end of the optimization for each alpha.

    n_iters : list of int
        The number of iterations taken by the coordinate descent optimizer to
        reach the specified tolerance for each alpha.

    See Also
    --------
    lars_path : Compute Least Angle Regression or Lasso path using LARS
        algorithm.
    Lasso : The Lasso is a linear model that estimates sparse coefficients.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    LassoCV : Lasso linear model with iterative fitting along a regularization
        path.
    LassoLarsCV : Cross-validated Lasso using the LARS algorithm.
    sklearn.decomposition.sparse_encode : Estimator that can be used to
        transform signals into sparse linear combination of atoms from a fixed.

    Notes
    -----
    For an example, see
    :ref:`examples/linear_model/plot_lasso_lasso_lars_elasticnet_path.py
    <sphx_glr_auto_examples_linear_model_plot_lasso_lasso_lars_elasticnet_path.py>`.

    To avoid unnecessary memory duplication the X argument of the fit method
    should be directly passed as a Fortran-contiguous numpy array.

    Note that in certain cases, the Lars solver may be significantly
    faster to implement this functionality. In particular, linear
    interpolation can be used to retrieve model coefficients between the
    values output by lars_path

    Examples
    --------

    Comparing lasso_path and lars_path with interpolation:

    >>> import numpy as np
    >>> from sklearn.linear_model import lasso_path
    >>> X = np.array([[1, 2, 3.1], [2.3, 5.4, 4.3]]).T
    >>> y = np.array([1, 2, 3.1])
    >>> # Use lasso_path to compute a coefficient path
    >>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5])
    >>> print(coef_path)
    [[0.         0.         0.46874778]
     [0.2159048  0.4425765  0.23689075]]

    >>> # Now use lars_path and 1D linear interpolation to compute the
    >>> # same path
    >>> from sklearn.linear_model import lars_path
    >>> alphas, active, coef_path_lars = lars_path(X, y, method='lasso')
    >>> from scipy import interpolate
    >>> coef_path_continuous = interpolate.interp1d(alphas[::-1],
    ...                                             coef_path_lars[:, ::-1])
    >>> print(coef_path_continuous([5., 1., .5]))
    [[0.         0.         0.46915237]
     [0.2159048  0.4425765  0.23668876]]
    rA   )r]   r^   r_   rp   rq   r\   r`   rr   ro   rt   rs   )	enet_path)r9   r:   r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   paramss                r>   
lasso_pathrz      sJ    Z 		 #  r@           both)r9   r:   r]   r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   rG         ?)r]   r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   rG   c                X	   |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  d	d      }|j                  d
d      }t        |      dkD  rt        d|j                               |ryt	        | dt
        j                  t
        j                  gd|      } t	        |d| j                  j                  ddd      }|$t	        || j                  j                  ddd      }| j                  \  }}d}|j                  dk7  rd}|j                  d   }|r|rt        d      |s_t        j                  |       rJ|'||z  }t        j                  || j                        }n!t        j                  || j                        }|rt!        | |||dd|      \  } }}}}}}|t#        | |||d||d      }n)t        |      dkD  rt        j$                  |      ddd   }t        |      }t        j&                  |      }g }t)        |      }|dvrt        d      |dk(  }|s$t        j&                  ||f| j                        } n$t        j&                  ||f| j                        } |	0t        j                  | j                  dd | j                  d      }!n!t        j*                  |	| j                        }!t-        |      D ]  \  }"}#|#|z  |z  }$|#d |z
  z  |z  }%|sWt        j                  |       rBt/        j0                  |!|$|%| j2                  | j4                  | j6                  |||||||!      }&n|rt/        j8                  |!|$|%| |||||	      }&nt;        |t
        j<                        rD|r"t	        || j                  j                  d      }t/        j>                  |!|$|%||||||||      }&n1|du rt/        j@                  |!|$|%| ||||||
      }&nt        d"|z        |&\  }!}'}(})|!| d#|"f<   |'|z  ||"<   |jC                  |)       |
sM|
d$kD  rtE        |&       _|
dkD  rtE        d%|"|fz         vtF        jH                  jK                  d&        |r|| ||fS || |fS )'a  Compute elastic net path with coordinate descent.

    The elastic net optimization function varies for mono and multi-outputs.

    For mono-output tasks it is::

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

    For multi-output tasks it is::

        (1 / (2 * n_samples)) * ||Y - XW||_Fro^2
        + alpha * l1_ratio * ||W||_21
        + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2

    Where::

        ||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

    i.e. the sum of norm of each row.

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

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Training data. Pass directly as Fortran-contiguous data to avoid
        unnecessary memory duplication. If ``y`` is mono-output then ``X``
        can be sparse.

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

    l1_ratio : float, default=0.5
        Number between 0 and 1 passed to elastic net (scaling between
        l1 and l2 penalties). ``l1_ratio=1`` corresponds to the Lasso.

    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If None alphas are set automatically.

    precompute : 'auto', bool or array-like of shape             (n_features, n_features), 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.

    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.

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

    coef_init : array-like of shape (n_features, ), default=None
        The initial values of the coefficients.

    verbose : bool or int, default=False
        Amount of verbosity.

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

    positive : bool, default=False
        If set to True, forces coefficients to be positive.
        (Only allowed when ``y.ndim == 1``).

    check_input : bool, default=True
        If set to False, the input validation checks are skipped (including the
        Gram matrix when provided). It is assumed that they are handled
        by the caller.

    **params : kwargs
        Keyword arguments passed to the coordinate descent solver.

    Returns
    -------
    alphas : ndarray of shape (n_alphas,)
        The alphas along the path where models are computed.

    coefs : ndarray of shape (n_features, n_alphas) or             (n_targets, n_features, n_alphas)
        Coefficients along the path.

    dual_gaps : ndarray of shape (n_alphas,)
        The dual gaps at the end of the optimization for each alpha.

    n_iters : list of int
        The number of iterations taken by the coordinate descent optimizer to
        reach the specified tolerance for each alpha.
        (Is returned when ``return_n_iter`` is set to True).

    See Also
    --------
    MultiTaskElasticNet : Multi-task ElasticNet model trained with L1/L2 mixed-norm     as regularizer.
    MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in cross-validation.
    ElasticNet : Linear regression with combined L1 and L2 priors as regularizer.
    ElasticNetCV : Elastic Net model with iterative fitting along a regularization path.

    Notes
    -----
    For an example, see
    :ref:`examples/linear_model/plot_lasso_lasso_lars_elasticnet_path.py
    <sphx_glr_auto_examples_linear_model_plot_lasso_lasso_lars_elasticnet_path.py>`.

    Examples
    --------
    >>> from sklearn.linear_model import enet_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, _ = enet_path(X, y, n_alphas=3)
    >>> alphas.shape
    (3,)
    >>> estimated_coef
     array([[ 0.        ,  0.78...,  0.56...],
            [ 0.        ,  1.12...,  0.61...],
            [-0.        , -2.12..., -1.12...],
            [ 0.        , 23.04..., 88.93...],
            [ 0.        , 10.63..., 41.56...]])
    rb   NX_scalerF   tol-C6?max_iter  random_state	selectioncyclicr   zUnexpected parameters in paramsr.   r-   )accept_sparsedtyper2   r0   F)r   r   r2   r0   	ensure_2dr,   )r   r2   r0   r   r&   Tz;positive=True is not allowed for multi-output (y.ndim != 1)r   )rE   r0   rG   )r\   r]   rE   r^   r_   r`   rH   )randomr   z,selection should be either random or cyclic.r   r   r2   rA   )walphabetaX_data	X_indicesX_indptrr:   rF   X_meanr   r   rngr   rt   zEPrecompute should be one of True, False, 'auto' or array-like. Got %r.r   zPath: %03i out of %03i.)&poplenr3   keysr   r7   rX   float32r   typerT   rN   r	   r5   r8   zerosr)   rg   sortemptyr"   asfortranarray	enumeratecd_fastsparse_enet_coordinate_descentdataindicesindptr"enet_coordinate_descent_multi_task
isinstancendarrayenet_coordinate_descent_gramenet_coordinate_descentappendprintsysstderrwrite)*r9   r:   r]   r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   rG   ry   X_offset_paramX_scale_paramrF   r   r   r   r   re   
n_featuresmulti_output	n_targetsX_sparse_scalingrc   	dual_gapsn_itersr   r   coefscoef_ir   l1_regl2_regmodel	dual_gap_eps_n_iter_s*                                             r>   rx   rx   y  s   X ZZ
D1NJJy$/MJJ5M
**UD
!Czz*d+H::nd3L

;1I
6{Q:FKKMJJ ::rzz*
 '',,
 >!'',,cB GGIzLvv{GGAJ	VWW FOOA.%  .=!zz*:!''J!xx
!''B (0#)
%1aAz2 ~ 	
 
Vq2&6{H"IG
\
*C,,GHH("F*h/qww?)Z:!''JSb)D!!)177;f% A&5!I-#.)I5 2::vv))+'!!E  >>vvq!XsCE 
BJJ/ (177<<sS
88E 5 33vvq!XsCE W  +0'y$c1f !9,	!w{e1.!X>?

  %CA&F ui005)##r@   c                   B    e Zd ZU dZdej
                  iZ eeddd      g eeddd      gd	gd	d
g ee	ddd      dgd	g eeddd      gd	gd	gdg e
ddh      gdZeed<    ee      Z	 dddddddddddd
dZ ed      dd       Zed        Z fdZ xZS )
ElasticNeta  Linear regression with combined L1 and L2 priors as regularizer.

    Minimizes the objective function::

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

    If you are interested in controlling the L1 and L2 penalty
    separately, keep in mind that this is equivalent to::

            a * ||w||_1 + 0.5 * b * ||w||_2^2

    where::

            alpha = a + b and l1_ratio = a / (a + b)

    The parameter l1_ratio corresponds to alpha in the glmnet R package while
    alpha corresponds to the lambda parameter in glmnet. Specifically, l1_ratio
    = 1 is the lasso penalty. Currently, l1_ratio <= 0.01 is not reliable,
    unless you supply your own sequence of alpha.

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

    Parameters
    ----------
    alpha : float, default=1.0
        Constant that multiplies the penalty terms. Defaults to 1.0.
        See the notes for the exact mathematical meaning of this
        parameter. ``alpha = 0`` is equivalent to an ordinary least square,
        solved by the :class:`LinearRegression` object. For numerical
        reasons, using ``alpha = 0`` with the ``Lasso`` object is not advised.
        Given this, you should use the :class:`LinearRegression` object.

    l1_ratio : float, default=0.5
        The ElasticNet mixing parameter, with ``0 <= l1_ratio <= 1``. For
        ``l1_ratio = 0`` the penalty is an L2 penalty. ``For l1_ratio = 1`` it
        is an L1 penalty.  For ``0 < l1_ratio < 1``, the penalty is a
        combination of L1 and L2.

    fit_intercept : bool, default=True
        Whether the intercept should be estimated or not. If ``False``, the
        data is assumed to be already centered.

    precompute : bool or array-like of shape (n_features, n_features),                 default=False
        Whether to use a precomputed Gram matrix to speed up
        calculations. The Gram matrix can also be passed as argument.
        For sparse input this option is always ``False`` to preserve sparsity.
        Check :ref:`an example on how to use a precomputed Gram Matrix in ElasticNet
        <sphx_glr_auto_examples_linear_model_plot_elastic_net_precomputed_gram_matrix_with_weighted_samples.py>`
        for details.

    max_iter : int, default=1000
        The maximum number of iterations.

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

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``, see Notes below.

    warm_start : bool, default=False
        When set to ``True``, reuse the solution of the previous call to fit as
        initialization, otherwise, just erase the previous solution.
        See :term:`the Glossary <warm_start>`.

    positive : bool, default=False
        When set to ``True``, forces the coefficients to be positive.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    coef_ : ndarray of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the cost function formula).

    sparse_coef_ : sparse matrix of shape (n_features,) or             (n_targets, n_features)
        Sparse representation of the `coef_`.

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

    n_iter_ : list of int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance.

    dual_gap_ : float or ndarray of shape (n_targets,)
        Given param alpha, the dual gaps at the end of the optimization,
        same shape as each observation of y.

    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
    --------
    ElasticNetCV : Elastic net model with best model selection by
        cross-validation.
    SGDRegressor : Implements elastic net regression with incremental training.
    SGDClassifier : Implements logistic regression with elastic net penalty
        (``SGDClassifier(loss="log_loss", penalty="elasticnet")``).

    Notes
    -----
    To avoid unnecessary memory duplication the X argument of the fit method
    should be directly passed as a Fortran-contiguous numpy array.

    The precise stopping criteria based on `tol` are the following: First, check that
    that maximum coordinate update, i.e. :math:`\max_j |w_j^{new} - w_j^{old}|`
    is smaller than `tol` times the maximum absolute coefficient, :math:`\max_j |w_j|`.
    If so, then additionally check whether the dual gap is smaller than `tol` times
    :math:`||y||_2^2 / n_{	ext{samples}}`.

    Examples
    --------
    >>> from sklearn.linear_model import ElasticNet
    >>> from sklearn.datasets import make_regression

    >>> X, y = make_regression(n_features=2, random_state=0)
    >>> regr = ElasticNet(random_state=0)
    >>> regr.fit(X, y)
    ElasticNet(random_state=0)
    >>> print(regr.coef_)
    [18.83816048 64.55968825]
    >>> print(regr.intercept_)
    1.451...
    >>> print(regr.predict([[0, 0]]))
    [1.451...]
    rG   r   Nrl   rj   r&   r|   rn   rh   r   r   r   r   r]   rE   rq   r   r`   r   
warm_startrt   r   r   _parameter_constraintsr}   TFr   r   )
r]   rE   rq   r   r`   r   r   rt   r   r   c       
             || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        y Nr   )selfr   r]   rE   rq   r   r`   r   r   rt   r   r   s               r>   __init__zElasticNet.__init__  sS     
 *$ $ ("r@   ru   c                 :   | j                   dk(  rt        j                  dd       d}|ru| j                  xr | j                  }t        | ||ddt        j                  t        j                  gdd|dd	      \  }}t        |dd|j                  j                  d
      }|j                  \  }}| j                   }t        |t        j                        rd}|5|rt!        |||j                        }||t        j"                  |      z  z  }| j                  xr | }	t%        ||d| j&                  | j                  |	||      \  }}}
}}}}|s|t)        ||d      \  }}|j*                  dk(  r|ddt        j,                  f   }|&|j*                  dk(  r|ddt        j,                  f   }|j                  d   }| j.                  rt1        | d      s%t        j2                  ||f|j                  d      }n2| j4                  }|j*                  dk(  r|t        j,                  ddf   }t        j2                  ||j                        }g | _        t9        |      D ]  }|
|dd|f   }nd}| j;                  ||dd|f   | j<                  dd|g||d||   dd| j>                  d| j@                  |
|| jB                  | jD                  | jF                  |      \  }}}}|dddf   ||<   |d   ||<   | j6                  jI                  |d           |dk(  r)| j6                  d   | _        |d   | _        |d   | _%        n|| _        || _%        | jM                  |
||       tO        d | j4                  | jP                  fD              stS        d      | S )a  Fit model with coordinate descent.

        Parameters
        ----------
        X : {ndarray, sparse matrix, sparse array} of (n_samples, n_features)
            Data.

            Note that large sparse matrices and arrays requiring `int64`
            indices are not accepted.

        y : ndarray of shape (n_samples,) or (n_samples, n_targets)
            Target. Will be cast to X's dtype if necessary.

        sample_weight : float or array-like of shape (n_samples,), default=None
            Sample weights. Internally, the `sample_weight` vector will be
            rescaled to sum to `n_samples`.

            .. versionadded:: 0.23

        check_input : bool, default=True
            Allow to bypass several input checking.
            Don't use this parameter unless you know what you do.

        Returns
        -------
        self : object
            Fitted estimator.

        Notes
        -----
        Coordinate descent is an algorithm that considers each column of
        data at a time hence it will automatically convert the X input
        as a Fortran-contiguous numpy array if necessary.

        To avoid memory re-allocation it is advised to allocate the
        initial data in memory directly using that format.
        r   zjWith alpha=0, this algorithm does not converge well. You are advised to use the LinearRegression estimatorr   )
stacklevelFr.   r-   T)r   r2   r   force_writeableaccept_large_sparser0   r   	y_numeric)r2   r0   r   r   Nr   )rE   r0   rG   rF   r1   r&   r   r   )r]   r^   r_   rp   rq   r\   r`   rr   ro   rs   rt   rG   r   rb   r   r   r   r   rF   c              3   b   K   | ]'  }t        j                  |      j                          ) y wr   )r7   isfiniteall).0r   s     r>   	<genexpr>z!ElasticNet.fit.<locals>.<genexpr>_  s!     OA2;;q>%%'Os   -/zCoordinate descent iterations resulted in non-finite parameter values. The input data may contain large values and need to be preprocessed.)*r   warningswarnr`   rE   r%   r7   rX   r   r   r   r   rT   r   numbersNumberr   rQ   r)   rq   r?   rN   rS   r   hasattrr   r   r   rangepathr]   rt   r   r   r   r   r   r   _set_interceptr   
intercept_r3   )r   r9   r:   rF   rG   X_copiedre   r   r   should_copyrb   y_offsetr   rq   r\   r   r   
dual_gaps_kthis_Xyrc   	this_coefthis_dual_gap	this_iters                           r>   fitzElasticNet.fit  s   N ::?MM    {{9t'9'9H #zz2::. $$)!DAq 5A !"	:

mW^^4 M$ 4]AQWW U8 *Y9N-NOM kk2(l<DOO,,#'	=
91h':r -3a#.DAq66Q;!RZZ- A>bgglArzzM"BGGAJ	gdG&<HHi4AGG3OEJJEzzQbjj!m,XXiqww7
y! 	.A~QT(59YY!Q$w%("!HH!!....+- 6? 62Ay-0 !AE!H)!,JqMLL	!-?	.B ><<?DLqDJ']DNDJ'DNHh8 O$**doo1NOO$  r@   c                 @    t        j                  | j                        S )z,Sparse representation of the fitted `coef_`.)r	   
csr_matrixr   r   s    r>   sparse_coef_zElasticNet.sparse_coef_i  s       ,,r@   c                     t        |        t        j                  |      r/t        || j                  j
                  d      | j                  z   S t        | !  |      S )a  Decision function of the linear model.

        Parameters
        ----------
        X : numpy array or scipy.sparse matrix of shape (n_samples, n_features)

        Returns
        -------
        T : ndarray of shape (n_samples,)
            The predicted decision function.
        TrI   )	r!   r	   r5   r   r   rP   r   super_decision_function)r   r9   	__class__s     r>   r   zElasticNet._decision_functionn  sI     	??1"1djjllFXX7-a00r@   rA   NT)__name__
__module____qualname____doc__r
   UNUSED"_ElasticNet__metadata_request__fitr   r   r   r   r   dict__annotations__staticmethodrx   r   r   r   r   propertyr   r   __classcell__r   s   @r>   r   r     s   Vt  -.>.E.EF 4D89dAq89# ,/h4?F+q$v67 kK'( (H!567$D  	"D # #6 5G 6GR - -1 1r@   r   c                        e Zd ZU dZi ej
                  Zeed<   ej                  d        e	e
      Z	 dddddddddd	d
	 fdZ xZS )Lassoa  Linear Model trained with L1 prior as regularizer (aka the Lasso).

    The optimization objective for Lasso is::

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

    Technically the Lasso model is optimizing the same objective function as
    the Elastic Net with ``l1_ratio=1.0`` (no L2 penalty).

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

    Parameters
    ----------
    alpha : float, default=1.0
        Constant that multiplies the L1 term, controlling regularization
        strength. `alpha` must be a non-negative float i.e. in `[0, inf)`.

        When `alpha = 0`, the objective is equivalent to ordinary least
        squares, solved by the :class:`LinearRegression` object. For numerical
        reasons, using `alpha = 0` with the `Lasso` object is not advised.
        Instead, you should use the :class:`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).

    precompute : bool or array-like of shape (n_features, n_features),                 default=False
        Whether to use a precomputed Gram matrix to speed up
        calculations. The Gram matrix can also be passed as argument.
        For sparse input this option is always ``False`` to preserve sparsity.

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

    max_iter : int, default=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``, see Notes below.

    warm_start : bool, default=False
        When set to True, reuse the solution of the previous call to fit as
        initialization, otherwise, just erase the previous solution.
        See :term:`the Glossary <warm_start>`.

    positive : bool, default=False
        When set to ``True``, forces the coefficients to be positive.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    coef_ : ndarray of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the cost function formula).

    dual_gap_ : float or ndarray of shape (n_targets,)
        Given param alpha, the dual gaps at the end of the optimization,
        same shape as each observation of y.

    sparse_coef_ : sparse matrix of shape (n_features, 1) or             (n_targets, n_features)
        Readonly property derived from ``coef_``.

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

    n_iter_ : int or list of int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance.

    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 : Regularization path using LARS.
    lasso_path : Regularization path using Lasso.
    LassoLars : Lasso Path along the regularization parameter using LARS algorithm.
    LassoCV : Lasso alpha parameter by cross-validation.
    LassoLarsCV : Lasso least angle parameter algorithm by cross-validation.
    sklearn.decomposition.sparse_encode : Sparse coding array estimator.

    Notes
    -----
    The algorithm used to fit the model is coordinate descent.

    To avoid unnecessary memory duplication the X argument of the fit method
    should be directly passed as a Fortran-contiguous numpy array.

    Regularization improves the conditioning of the problem and
    reduces the variance of the estimates. Larger values specify stronger
    regularization. Alpha corresponds to `1 / (2C)` in other linear
    models such as :class:`~sklearn.linear_model.LogisticRegression` or
    :class:`~sklearn.svm.LinearSVC`. If an array is passed, penalties are
    assumed to be specific to the targets. Hence they must correspond in
    number.

    The precise stopping criteria based on `tol` are the following: First, check that
    that maximum coordinate update, i.e. :math:`\max_j |w_j^{new} - w_j^{old}|`
    is smaller than `tol` times the maximum absolute coefficient, :math:`\max_j |w_j|`.
    If so, then additionally check whether the dual gap is smaller than `tol` times
    :math:`||y||_2^2 / n_{\text{samples}}`.

    The target can be a 2-dimensional array, resulting in the optimization of the
    following objective::

        (1 / (2 * n_samples)) * ||Y - XW||^2_F + alpha * ||W||_11

    where :math:`||W||_{1,1}` is the sum of the magnitude of the matrix coefficients.
    It should not be confused with :class:`~sklearn.linear_model.MultiTaskLasso` which
    instead penalizes the :math:`L_{2,1}` norm of the coefficients, yielding row-wise
    sparsity in the coefficients.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.Lasso(alpha=0.1)
    >>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
    Lasso(alpha=0.1)
    >>> print(clf.coef_)
    [0.85 0.  ]
    >>> print(clf.intercept_)
    0.15...
    r   r]   TFr   r   Nr   )	rE   rq   r`   r   r   r   rt   r   r   c       	         :    t         |   |d||||||||	|
       y )NrA   )r   r]   rE   rq   r`   r   r   r   rt   r   r   r   r   )r   r   rE   rq   r`   r   r   r   rt   r   r   r   s              r>   r   zLasso.__init__!  s8     	'!!% 	 	
r@   r   )r   r   r   r   r   r   r   r   r   r   rx   r   r   r   r   s   @r>   r   r     sr    Rh$

+
+$D  z*	"D 
 
 
r@   r   c           	      ^   | |   }||   }| |   }||   }|d\  }}n4||   }||   }|j                   d   }||t        j                  |      z  z  }t        j                  |       sG|| f||f|| f||ffD ]6  \  }}|j
                  |us|j                  d   r%|j                  d       8 |j                  dk(  r|d   }nd	}t        ||d||d	|
      \  }}}}}}}|j                         }||d<   ||d<   ||d<   ||d<   d	|d<   ||d<   ||d<   d|v r|	|d<   t        |d||
      } |||fi |\  }}}~~|j                  dk(  rF|t        j                  ddddf   }t        j                  |      }|ddt        j                  f   }|ddt        j                  f   t        j                  ||      z
  }t        ||      }||ddddt        j                  f   z
  }||z  }||dz  j!                  d      }nt        j"                  |dz  |d      }|j!                  d      S )a  Returns the MSE for the models computed by 'path'.

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

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

    sample_weight : None or array-like of shape (n_samples,)
        Sample weights.

    train : list of indices
        The indices of the train set.

    test : list of indices
        The indices of the test set.

    path : callable
        Function returning a list of models on the path. See
        enet_path for an example of signature.

    path_params : dictionary
        Parameters passed to the path function.

    alphas : array-like, default=None
        Array of float that is used for cross-validation. If not
        provided, computed using 'path'.

    l1_ratio : float, default=1
        float between 0 and 1 passed to ElasticNet (scaling between
        l1 and l2 penalties). For ``l1_ratio = 0`` the penalty is an
        L2 penalty. For ``l1_ratio = 1`` it is an L1 penalty. For ``0
        < l1_ratio < 1``, the penalty is a combination of L1 and L2.

    X_order : {'F', 'C'}, default=None
        The order of the arrays expected by the path function to
        avoid memory copies.

    dtype : a numpy dtype, default=None
        The dtype of the arrays expected by the path function to
        avoid memory copies.
    N)NNr   	WRITEABLET)r   r&   rq   F)rE   r0   rF   r\   rb   r   r`   rp   rF   r]   r.   )r   r   r2   r   rK   )weightsrL   )rT   r7   rQ   r	   r5   baseflagssetflagsrN   r)   r0   r   rS   
atleast_1drR   r   meanaverage) r9   r:   rF   traintestrE   r   path_paramsrp   r]   X_orderr   X_trainy_trainX_testy_testsw_trainsw_testre   arrayarray_inputrq   rb   r   r   r\   r   rc   
interceptsX_test_coefsresiduesthis_mses                                    r>   _path_residualsr  B  s   t hGhGtWFtWF&' '%MM!$	 	Ix 000 ??1aLaLQKQK	#
 		+E; zz,U[[5M T*		+ 	vv{ .
 
DL#EAGWh':r ""$KK&K
$K	 *K!K"K#+K [ "*J 'e7SGGW<<FE1vv{bjj!Q&'==*2::&!RZZ-(266(E+BBJ"651LfQ2::%566H
HaK%%1%-::hk7C==a=  r@   c                   ^   e Zd ZU dZ eeddd      g eeddd      gddgd	g ed
h      dd	g eeddd      g eeddd      gd	gdgdgedgd	gdg eddh      gdZe	e
d<   e	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zed        Zed        Zeed               Z ed      dd       Zd Zy)LinearModelCVzCBase class for iterative model fitting along a regularization path.r   Nri   rj   r&   rl   rh   rn   rm   	cv_objectro   r   r   r   r^   r_   rp   rE   rq   r   r   r`   cvro   n_jobsrt   r   r   r   Tc                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        y r   r  )r   r^   r_   rp   rE   rq   r   r   r`   r  ro   r  rt   r   r   s                  r>   r   zLinearModelCV.__init__  sh    $  *$  ("r@   c                      y)z<Model to be fitted after the best alpha has been determined.N r   s    r>   _get_estimatorzLinearModelCV._get_estimator      r@   c                      y)z>Bool indicating if class is meant for multidimensional target.Nr"  r   s    r>   _is_multitaskzLinearModelCV._is_multitask	  r$  r@   c                      y)z%Compute path with coordinate descent.Nr"  )r9   r:   kwargss      r>   r   zLinearModelCV.path  r$  r@   ru   c                    #$ t        | d        j                  xr  j                  }t        dt        j
                  t        j                  gd      }t        t        j                        st        j                        r}t        dt        j
                  t        j                  gddd      }t         ||f      \  t        j                        r9t        |d      rEt	        j                  |j                  j                        sd}nt	        j                  |      sd}~nDt        dt        j
                  t        j                  gd	d|
      }t         ||f      \  d}t                j!                         sQj"                  dkD  r4j$                  d   dkD  r"t'        d j(                  j*                  z        t-        d      nTt        j                        rt/        d      j"                  dk(  r%t'        d j(                  j*                  dd z        t        t0        j2                        rdt5        j6                         j9                         }	 j;                         $$j=                  dd       d$v r!t	        j>                  $d         }
|
d   $d<   ndg}
$j=                  dd       $j=                  dd        j@                  }tC        |
      }tE        tF        tH        dd      }|I|
D cg c]=  }tK        | j                   jL                   jN                   j                        ? }}nQtQ        |      D ]  \  }} ||d| d        t	        jR                  t	        jT                  |      ddd   |df      }tC        |d         }$jW                  d|i       |$d <   tY         jZ                        dkD  rd$d <   t]         j^                        }ta               r]tc        |      je                  d!d"g#      }|stg         d"      st'        d$      |r|d"<   ti         dfi |}2tg         d"      s&dn#tk               }tk        tk               %      |_6        to         |jp                  fi |jl                  jp                        #t        jr                  }#$ fd&tu        |
|      D        } tw         jZ                   jx                  d'(      |      }t	        jz                  ||tC        #      df      }t	        j|                  |d)      }t	        j~                  t	        j                  |d*d             _A        tu        |
||      D ]/  \  }}}t	        j                  |      }||   }||k  s'||   }|}|}1  _C         _D         j@                  4t	        j                  |       _F        |dk(  r2 j                  d    _F        nt	        j                  |d          _F         j;                         j                         D  ci c]  \  }} ||	j;                         v r||  }!}}  |	j                  d.i |! ||	_I        ||	_J        ||	_        t         d+d      }"t        |"t              r|"d,k(  rd|	_M        |	j                         n|	j                  -       t         d      s `C|	j                   _O        |	j                   _P        |	j                   _Q        |	j                   _R         S c c}w c c} }w )/a  Fit linear model with coordinate descent.

        Fit is on grid of alphas and best alpha estimated by cross-validation.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data. Pass directly as Fortran-contiguous data
            to avoid unnecessary memory duplication. If y is mono-output,
            X can be sparse. Note that large sparse matrices and arrays
            requiring `int64` indices are not accepted.

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

        sample_weight : float or array-like of shape (n_samples,),                 default=None
            Sample weights used for fitting and evaluation of the weighted
            mean squared error of each cv-fold. Note that the cross validated
            MSE that is finally used to find the best model is the unweighted
            mean over the (weighted) MSEs of each test fold.

        **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 fitted model.
        r   F)r0   r   r   r.   T)r   r   r   r0   r   validate_separatelyr   r-   )r   r   r2   r   r0   r&   z'For multi-task outputs, use MultiTask%s)r   z/X should be dense but a sparse matrix waspassedzFor mono-task outputs, use %sCV	   Nr   rE   r]   r   r  r  r{   rl   )target_typemin_valinclude_boundaries)r]   rE   r^   r_   r`   rF   zalphas[]rH   r_   r`   splitrF   )methodry   zGThe CV splitter and underlying estimator do not support sample weights.)r1  c              3      K   | ]Z  \  }}D ]P  \  }} t        t              
||	j                  	j                  ||d j                  j
                         R \ yw)r-   )rp   r]   r  r   N)r   r  rE   r   r   r   )r   this_l1_ratiothis_alphasr	  r
  r9   foldsr  rF   r   r:   s        r>   r   z$LinearModelCV.fit.<locals>.<genexpr>  s      
 +{$!
  t %GO$""		"&ggll 

s   A A#threads)r  ro   preferrK   r   rq   rm   )rF   r"  )Sr   r`   rE   r   r7   rX   r   r   r   r	   r5   r%   r   may_share_memoryr   r    r&  rN   rT   r3   r   r   r#   	TypeErrorr   r   r   r   r#  
get_paramsr   r  rp   r   r   r   r   rg   r^   r_   r   tiler   updater   r  r   r  r   r   consumesr$   r   r   splitterlistr1  infzipr   ro   rO   r  squeezemoveaxis	mse_path_argmin	l1_ratio_alpha_r8   alphas_items
set_paramsr   r]   getattrstrrq   r   r   r   r   r   )%r   r9   r:   rF   ry   r`   check_y_paramsreference_to_old_Xcheck_X_paramsr   	l1_ratiosrp   
n_l1_ratiocheck_scalar_alphar]   indexr   r_   r  splitter_supports_sample_weightrouted_paramsbest_msejobs	mse_pathsmean_mse	l1_alphas
mse_alphasi_best_alphathis_best_mse
best_alphabest_l1_rationamevaluecommon_paramsrq   r6  r  s%   ````                               @@r>   r   zLinearModelCV.fit  s   N 	&$. 3!3!3rzz2::6%
 a$(:!" "#zz2::. $$)N !a0PDAq q!-v6r?R?R&++QVV@ #F(();Q?" "#zz2::. $N !a0PDAq F1%!!#vvzaggaj1n =@W@WW  QT*Aq! QRR1 58O8OPQPR8SS  mW^^4 M$0QM##% oo' 	.$k*&=>I&/lK
# I 	d#$'^
$%	
 > !*  %"&"4"4!]];;"/	F  !*& 1 >u"5GE7!*<=> WWRWWV_TrT2ZODF vay>J12 &H DKK(1,$)K! dgg.DR.H.Q.Q'8 /R /+ )7)$@ ' 
 /*7'+D%B6BM(1Bo2 !%!GM%*%9M" XRXXaCm&<&<&B&BCD66
 
 /2)V.D
$
H;;LL
 		
 JJy:s5z2*FG	7791-BKK	1a$@A/29fh/O 	)+Hi99Z0L&|4Mx'&|4
 ((	) ' ;;::f-DLQ#||A ::fQi0DL
  $0668
eu'')) %K
 

 	)=) &T<6
j#&:+?$E  IIaOIIa-I8tZ([[
**}}Ub
s   "A\?]c                     t        | j                  j                        j                  |       j	                  t        | j                        t               j	                  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   r1  )callercallee)r?  method_mapping)r   r   r   add_self_requestaddr   r  r   )r   routers     r>   get_metadata_routingz"LinearModelCV.get_metadata_routing3  s]     !8!89d#S!$''*,22%2P   	 r@   )rB   rC   NTrm   r   r   TNFNFNr   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r#  r&  r   r   r   r   rl  r"  r@   r>   r  r    sT   M q$y9:h4?@&#!6(+\9Eh4?@q$v67+m;T"K'( (H!567$D "  # #@ K K M M 4  4 5^ 6^@	r@   r  c                   t     e Zd ZdZ ee      Zdddddddddd	dd	dd
d fd
Zd Zd Z	 fdZ
d fd	Z xZS )LassoCVa  Lasso linear model with iterative fitting along a regularization path.

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

    The best model is selected by cross-validation.

    The optimization objective for Lasso is::

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

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

    Parameters
    ----------
    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If ``None`` alphas are set automatically.

    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).

    precompute : 'auto', bool or array-like of shape             (n_features, n_features), 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=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

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

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

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

        For int/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.

    verbose : bool or int, default=False
        Amount of verbosity.

    n_jobs : int, 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.

    positive : bool, default=False
        If positive, restrict regression coefficients to be positive.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    alpha_ : float
        The amount of penalization chosen by cross validation.

    coef_ : ndarray of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the cost function formula).

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

    mse_path_ : ndarray of shape (n_alphas, n_folds)
        Mean square error for the test set on each fold, varying alpha.

    alphas_ : ndarray of shape (n_alphas,)
        The grid of alphas used for fitting.

    dual_gap_ : float or ndarray of shape (n_targets,)
        The dual gap at the end of the optimization for the optimal alpha
        (``alpha_``).

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance for 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 : The Lasso is a linear model that estimates sparse coefficients.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    LassoCV : Lasso linear model with iterative fitting along a regularization
        path.
    LassoLarsCV : Cross-validated Lasso using the LARS algorithm.

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

    To avoid unnecessary memory duplication the `X` argument of the `fit`
    method should be directly passed as a Fortran-contiguous numpy array.

    For an example, see :ref:`examples/linear_model/plot_lasso_model_selection.py
    <sphx_glr_auto_examples_linear_model_plot_lasso_model_selection.py>`.

    :class:`LassoCV` leads to different results than a hyperparameter
    search using :class:`~sklearn.model_selection.GridSearchCV` with a
    :class:`Lasso` model. In :class:`LassoCV`, a model for a given
    penalty `alpha` is warm started using the coefficients of the
    closest model (trained at the previous iteration) on the
    regularization path. It tends to speed up the hyperparameter
    search.

    Examples
    --------
    >>> from sklearn.linear_model import LassoCV
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(noise=4, random_state=0)
    >>> reg = LassoCV(cv=5, random_state=0).fit(X, y)
    >>> reg.score(X, y)
    0.9993...
    >>> reg.predict(X[:1,])
    array([-78.4951...])
    rB   rC   NTrm   r   r   Fr   r  c                @    t         |   |||||||||	|
||||       y )Nr  r   )r   r^   r_   rp   rE   rq   r   r   r`   r  ro   r  rt   r   r   r   s                  r>   r   zLassoCV.__init__  sA    $ 	'!% 	 	
r@   c                     t               S r   )r   r   s    r>   r#  zLassoCV._get_estimator  s	    wr@   c                      yNFr"  r   s    r>   r&  zLassoCV._is_multitask      r@   c                 F    t         |          }d|j                  _        |S rr  r   __sklearn_tags__target_tagsr   r   tagsr   s     r>   rv  zLassoCV.__sklearn_tags__  #    w')(-%r@   c                 *    t        |   ||fd|i|S )a  Fit Lasso model with coordinate descent.

        Fit is on grid of alphas and best alpha estimated by cross-validation.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data. Pass directly as Fortran-contiguous data
            to avoid unnecessary memory duplication. If y is mono-output,
            X can be sparse. Note that large sparse matrices and arrays
            requiring `int64` indices are not accepted.

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

        sample_weight : float or array-like of shape (n_samples,),                 default=None
            Sample weights used for fitting and evaluation of the weighted
            mean squared error of each cv-fold. Note that the cross validated
            MSE that is finally used to find the best model is the unweighted
            mean over the (weighted) MSEs of each test fold.

        **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 fitted model.
        rF   r   r   r   r9   r:   rF   ry   r   s        r>   r   zLassoCV.fit$  !    L w{1aG}GGGr@   r   )r   r   r   r   r   rz   r   r   r#  r&  rv  r   r   r   s   @r>   rn  rn  L  sc    eN 
#D
 !!
F
&H &Hr@   rn  c                        e Zd ZU dZi ej
                  d eeddd      dgiZee	d<    e
e      Zd	d
dddddddddddddddZd Zd Z fdZd fd	Z xZS )ElasticNetCVaK  Elastic Net model with iterative fitting along a regularization path.

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

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

    Parameters
    ----------
    l1_ratio : float or list of float, default=0.5
        Float between 0 and 1 passed to ElasticNet (scaling between
        l1 and l2 penalties). For ``l1_ratio = 0``
        the penalty is an L2 penalty. For ``l1_ratio = 1`` it is an L1 penalty.
        For ``0 < l1_ratio < 1``, the penalty is a combination of L1 and L2
        This parameter can be a list, in which case the different
        values are tested by cross-validation and the one giving the best
        prediction score is used. Note that a good choice of list of
        values for l1_ratio is often to put more values close to 1
        (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,
        .9, .95, .99, 1]``.

    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path, used for each l1_ratio.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If None alphas are set automatically.

    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).

    precompute : 'auto', bool or array-like of shape             (n_features, n_features), 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=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

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

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

        For int/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.

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

    verbose : bool or int, default=0
        Amount of verbosity.

    n_jobs : int, 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.

    positive : bool, default=False
        When set to ``True``, forces the coefficients to be positive.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    alpha_ : float
        The amount of penalization chosen by cross validation.

    l1_ratio_ : float
        The compromise between l1 and l2 penalization chosen by
        cross validation.

    coef_ : ndarray of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the cost function formula).

    intercept_ : float or ndarray of shape (n_targets, n_features)
        Independent term in the decision function.

    mse_path_ : ndarray of shape (n_l1_ratio, n_alpha, n_folds)
        Mean square error for the test set on each fold, varying l1_ratio and
        alpha.

    alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)
        The grid of alphas used for fitting, for each l1_ratio.

    dual_gap_ : float
        The dual gaps at the end of the optimization for the optimal alpha.

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance for 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
    --------
    enet_path : Compute elastic net path with coordinate descent.
    ElasticNet : Linear regression with combined L1 and L2 priors as regularizer.

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

    To avoid unnecessary memory duplication the `X` argument of the `fit`
    method should be directly passed as a Fortran-contiguous numpy array.

    The parameter `l1_ratio` corresponds to alpha in the glmnet R package
    while alpha corresponds to the lambda parameter in glmnet.
    More specifically, the optimization objective is::

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

    If you are interested in controlling the L1 and L2 penalty
    separately, keep in mind that this is equivalent to::

        a * L1 + b * L2

    for::

        alpha = a + b and l1_ratio = a / (a + b).

    For an example, see
    :ref:`examples/linear_model/plot_lasso_model_selection.py
    <sphx_glr_auto_examples_linear_model_plot_lasso_model_selection.py>`.

    Examples
    --------
    >>> from sklearn.linear_model import ElasticNetCV
    >>> from sklearn.datasets import make_regression

    >>> X, y = make_regression(n_features=2, random_state=0)
    >>> regr = ElasticNetCV(cv=5, random_state=0)
    >>> regr.fit(X, y)
    ElasticNetCV(cv=5, random_state=0)
    >>> print(regr.alpha_)
    0.199...
    >>> print(regr.intercept_)
    0.398...
    >>> print(regr.predict([[0, 0]]))
    [0.398...]
    r]   r   r&   r|   rj   rh   r   r}   rB   rC   NTrm   r   r   Fr   r]   r^   r_   rp   rE   rq   r   r   r  r`   ro   r  rt   r   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        y r   r  )r   r]   r^   r_   rp   rE   rq   r   r   r  r`   ro   r  rt   r   r   s                   r>   r   zElasticNetCV.__init__	  so    & ! *$  ("r@   c                     t               S r   )r   r   s    r>   r#  zElasticNetCV._get_estimator2	  s
    |r@   c                      yrr  r"  r   s    r>   r&  zElasticNetCV._is_multitask5	  rs  r@   c                 F    t         |          }d|j                  _        |S rr  ru  rx  s     r>   rv  zElasticNetCV.__sklearn_tags__8	  rz  r@   c                 *    t        |   ||fd|i|S )a  Fit ElasticNet model with coordinate descent.

        Fit is on grid of alphas and best alpha estimated by cross-validation.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data. Pass directly as Fortran-contiguous data
            to avoid unnecessary memory duplication. If y is mono-output,
            X can be sparse. Note that large sparse matrices and arrays
            requiring `int64` indices are not accepted.

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

        sample_weight : float or array-like of shape (n_samples,),                 default=None
            Sample weights used for fitting and evaluation of the weighted
            mean squared error of each cv-fold. Note that the cross validated
            MSE that is finally used to find the best model is the unweighted
            mean over the (weighted) MSEs of each test fold.

        **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 fitted model.
        rF   r|  r}  s        r>   r   zElasticNetCV.fit=	  r~  r@   r   )r   r   r   r   r  r   r   r   r   r   r   rx   r   r   r#  r&  rv  r   r   r   s   @r>   r  r  M  s    xt$

.
.$XdAq8,G$D 
 	"D
 #!#F
&H &Hr@   r  c            
            e Zd ZU dZi ej
                  Zeed<   dD ]  Zej                  e        	 dddddddd	d
ddZ
 ed      d        Z fdZ xZS )MultiTaskElasticNeta\  Multi-task ElasticNet model trained with L1/L2 mixed-norm as regularizer.

    The optimization objective for MultiTaskElasticNet is::

        (1 / (2 * n_samples)) * ||Y - XW||_Fro^2
        + alpha * l1_ratio * ||W||_21
        + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2

    Where::

        ||W||_21 = sum_i sqrt(sum_j W_ij ^ 2)

    i.e. the sum of norms of each row.

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

    Parameters
    ----------
    alpha : float, default=1.0
        Constant that multiplies the L1/L2 term. Defaults to 1.0.

    l1_ratio : float, default=0.5
        The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.
        For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it
        is an L2 penalty.
        For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.

    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).

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

    max_iter : int, default=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

    warm_start : bool, default=False
        When set to ``True``, reuse the solution of the previous call to fit as
        initialization, otherwise, just erase the previous solution.
        See :term:`the Glossary <warm_start>`.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    intercept_ : ndarray of shape (n_targets,)
        Independent term in decision function.

    coef_ : ndarray of shape (n_targets, n_features)
        Parameter vector (W in the cost function formula). If a 1D y is
        passed in at fit (non multi-task usage), ``coef_`` is then a 1D array.
        Note that ``coef_`` stores the transpose of ``W``, ``W.T``.

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance.

    dual_gap_ : float
        The dual gaps at the end of the optimization.

    eps_ : float
        The tolerance scaled scaled by the variance of the target `y`.

    sparse_coef_ : sparse matrix of shape (n_features,) or             (n_targets, n_features)
        Sparse representation of the `coef_`.

    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
    --------
    MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in
        cross-validation.
    ElasticNet : Linear regression with combined L1 and L2 priors as regularizer.
    MultiTaskLasso : Multi-task Lasso model trained with L1/L2
        mixed-norm as regularizer.

    Notes
    -----
    The algorithm used to fit the model is coordinate descent.

    To avoid unnecessary memory duplication the X and y arguments of the fit
    method should be directly passed as Fortran-contiguous numpy arrays.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.MultiTaskElasticNet(alpha=0.1)
    >>> clf.fit([[0,0], [1, 1], [2, 2]], [[0, 0], [1, 1], [2, 2]])
    MultiTaskElasticNet(alpha=0.1)
    >>> print(clf.coef_)
    [[0.45663524 0.45612256]
     [0.45663524 0.45612256]]
    >>> print(clf.intercept_)
    [0.0872422 0.0872422]
    r   )rq   rt   r}   Tr   r   FNr   )r]   rE   r`   r   r   r   r   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y r   )	r]   r   rE   r   r`   r   r   r   r   )
r   r   r]   rE   r`   r   r   r   r   r   s
             r>   r   zMultiTaskElasticNet.__init__	  sE     !
* $("r@   ru   c                    t        t        j                  t        j                  gdd| j                  xr | j
                        }t        dd      }t        | ||||f      \  }}t        ||       |j                  |j                        }t        | d      rd}nd	}|j                  d
k(  rt        d|z        |j                  \  }}|j                  d
   }t        ||| j
                  d      \  }}}	}
}| j                  rt        | d      s3t        j                   ||f|j                  j"                  d      | _        | j&                  | j(                  z  |z  }| j&                  d| j(                  z
  z  |z  }t        j*                  | j$                        | _        | j,                  dk(  }t/        j0                  | j$                  ||||| j2                  | j4                  t7        | j8                        |	      \  | _        | _        | _        | _        | xj:                  |z  c_        | jA                  |	|
|       | S )a  Fit MultiTaskElasticNet model with coordinate descent.

        Parameters
        ----------
        X : ndarray of shape (n_samples, n_features)
            Data.
        y : ndarray of shape (n_samples, n_targets)
            Target. Will be cast to X's dtype if necessary.

        Returns
        -------
        self : object
            Fitted estimator.

        Notes
        -----
        Coordinate descent is an algorithm that considers each column of
        data at a time hence it will automatically convert the X input
        as a Fortran-contiguous numpy array if necessary.

        To avoid memory re-allocation it is advised to allocate the
        initial data in memory directly using that format.
        r-   T)r   r2   r   r0   F)r   r2   r*  r]   r   r   r&   zFor mono-task outputs, use %s)rE   r0   r   r   rA   r   )!r   r7   rX   r   r`   rE   r%   r    astyper   r   rN   r3   rT   r*   r   r   r   r   r   r]   r   r   r   r   r   r   r"   r   r   r   r   r   )r   r9   r:   rP  rN  	model_strre   r   r   rb   r   r   r   r   r   s                  r>   r   zMultiTaskElasticNet.fit
  s    6 ::rzz* 3!3!3	
 S9!Q^^,L
1 	 1%HHQWW4$$II66Q;<yHII !	:GGAJ	,<q 2 2-
)1h' gdG&<J'qww||3DJ dmm+i7sT]]23i?&&tzz2
8+ 66JJMMHHt001

	
JNIL 	)#Hh8 r@   c                 h    t         |          }d|j                  _        d|j                  _        |S NTFr   rv  rw  r   single_outputrx  s     r>   rv  z$MultiTaskElasticNet.__sklearn_tags___
  1    w')(,%).&r@   r   )r   r   r   r   r   r   r   r   paramr   r   r   r   rv  r   r   s   @r>   r  r  j	  s    zx$

+
+$D  , *""5)*
 # #. 5X 6Xt r@   r  c            	       v    e Zd ZU dZi ej
                  Zeed<   ej                  d       	 dddddddd	d
dZ	y)MultiTaskLassoa  Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.

    The optimization objective for Lasso is::

        (1 / (2 * n_samples)) * ||Y - XW||^2_Fro + alpha * ||W||_21

    Where::

        ||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

    i.e. the sum of norm of each row.

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

    Parameters
    ----------
    alpha : float, default=1.0
        Constant that multiplies the L1/L2 term. Defaults to 1.0.

    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).

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

    max_iter : int, default=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

    warm_start : bool, default=False
        When set to ``True``, reuse the solution of the previous call to fit as
        initialization, otherwise, just erase the previous solution.
        See :term:`the Glossary <warm_start>`.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    coef_ : ndarray of shape (n_targets, n_features)
        Parameter vector (W in the cost function formula).
        Note that ``coef_`` stores the transpose of ``W``, ``W.T``.

    intercept_ : ndarray of shape (n_targets,)
        Independent term in decision function.

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance.

    dual_gap_ : ndarray of shape (n_alphas,)
        The dual gaps at the end of the optimization for each alpha.

    eps_ : float
        The tolerance scaled scaled by the variance of the target `y`.

    sparse_coef_ : sparse matrix of shape (n_features,) or             (n_targets, n_features)
        Sparse representation of the `coef_`.

    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
    --------
    Lasso: Linear Model trained with L1 prior as regularizer (aka the Lasso).
    MultiTaskLassoCV: Multi-task L1 regularized linear model with built-in
        cross-validation.
    MultiTaskElasticNetCV: Multi-task L1/L2 ElasticNet with built-in cross-validation.

    Notes
    -----
    The algorithm used to fit the model is coordinate descent.

    To avoid unnecessary memory duplication the X and y arguments of the fit
    method should be directly passed as Fortran-contiguous numpy arrays.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.MultiTaskLasso(alpha=0.1)
    >>> clf.fit([[0, 1], [1, 2], [2, 4]], [[0, 0], [1, 1], [2, 3]])
    MultiTaskLasso(alpha=0.1)
    >>> print(clf.coef_)
    [[0.         0.60809415]
    [0.         0.94592424]]
    >>> print(clf.intercept_)
    [-0.41888636 -0.87382323]
    r   r]   Tr   r   FNr   )rE   r`   r   r   r   r   r   c                    || _         || _        || _        || _        || _        || _        d| _        || _        || _        y )NrA   )	r   rE   r   r`   r   r   r]   r   r   )	r   r   rE   r`   r   r   r   r   r   s	            r>   r   zMultiTaskLasso.__init__
  sE     
* $("r@   r   )
r   r   r   r   r  r   r   r   r   r   r"  r@   r>   r  r  f
  s\    pd$

4
4$D  z* # #r@   r  c                        e Zd ZU dZi ej
                  d eeddd      dgiZee	d<   ej                  d	       ej                  d
        ee      ZdddddddddddddddZd Zd Z fdZ fdZ xZS )MultiTaskElasticNetCVa  Multi-task L1/L2 ElasticNet with built-in cross-validation.

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

    The optimization objective for MultiTaskElasticNet is::

        (1 / (2 * n_samples)) * ||Y - XW||^Fro_2
        + alpha * l1_ratio * ||W||_21
        + 0.5 * alpha * (1 - l1_ratio) * ||W||_Fro^2

    Where::

        ||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

    i.e. the sum of norm of each row.

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

    .. versionadded:: 0.15

    Parameters
    ----------
    l1_ratio : float or list of float, default=0.5
        The ElasticNet mixing parameter, with 0 < l1_ratio <= 1.
        For l1_ratio = 1 the penalty is an L1/L2 penalty. For l1_ratio = 0 it
        is an L2 penalty.
        For ``0 < l1_ratio < 1``, the penalty is a combination of L1/L2 and L2.
        This parameter can be a list, in which case the different
        values are tested by cross-validation and the one giving the best
        prediction score is used. Note that a good choice of list of
        values for l1_ratio is often to put more values close to 1
        (i.e. Lasso) and less close to 0 (i.e. Ridge), as in ``[.1, .5, .7,
        .9, .95, .99, 1]``.

    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If not provided, set automatically.

    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).

    max_iter : int, default=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

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

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

        For int/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.

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

    verbose : bool or int, default=0
        Amount of verbosity.

    n_jobs : int, default=None
        Number of CPUs to use during the cross validation. Note that this is
        used only if multiple values for l1_ratio are given.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    intercept_ : ndarray of shape (n_targets,)
        Independent term in decision function.

    coef_ : ndarray of shape (n_targets, n_features)
        Parameter vector (W in the cost function formula).
        Note that ``coef_`` stores the transpose of ``W``, ``W.T``.

    alpha_ : float
        The amount of penalization chosen by cross validation.

    mse_path_ : ndarray of shape (n_alphas, n_folds) or                 (n_l1_ratio, n_alphas, n_folds)
        Mean square error for the test set on each fold, varying alpha.

    alphas_ : ndarray of shape (n_alphas,) or (n_l1_ratio, n_alphas)
        The grid of alphas used for fitting, for each l1_ratio.

    l1_ratio_ : float
        Best l1_ratio obtained by cross-validation.

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance for the optimal alpha.

    dual_gap_ : float
        The dual gap at the end of the optimization for 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
    --------
    MultiTaskElasticNet : Multi-task L1/L2 ElasticNet with built-in cross-validation.
    ElasticNetCV : Elastic net model with best model selection by
        cross-validation.
    MultiTaskLassoCV : Multi-task Lasso model trained with L1 norm
        as regularizer and built-in cross-validation.

    Notes
    -----
    The algorithm used to fit the model is coordinate descent.

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

    To avoid unnecessary memory duplication the `X` and `y` arguments of the
    `fit` method should be directly passed as Fortran-contiguous numpy arrays.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.MultiTaskElasticNetCV(cv=3)
    >>> clf.fit([[0,0], [1, 1], [2, 2]],
    ...         [[0, 0], [1, 1], [2, 2]])
    MultiTaskElasticNetCV(cv=3)
    >>> print(clf.coef_)
    [[0.52875032 0.46958558]
     [0.52875032 0.46958558]]
    >>> print(clf.intercept_)
    [0.00166409 0.00166409]
    r]   r   r&   r|   rj   rh   r   rq   rt   r}   rB   rC   NTr   r   r   r]   r^   r_   rp   rE   r   r   r  r`   ro   r  r   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        y r   r  )r   r]   r^   r_   rp   rE   r   r   r  r`   ro   r  r   r   s                 r>   r   zMultiTaskElasticNetCV.__init__  sa    " ! * ("r@   c                     t               S r   )r  r   s    r>   r#  z$MultiTaskElasticNetCV._get_estimator  s    "$$r@   c                      yr   r"  r   s    r>   r&  z#MultiTaskElasticNetCV._is_multitask      r@   c                 h    t         |          }d|j                  _        d|j                  _        |S r  r  rx  s     r>   rv  z&MultiTaskElasticNetCV.__sklearn_tags__  r  r@   c                 &    t        |   ||fi |S )a  Fit MultiTaskElasticNet model with coordinate descent.

        Fit is on grid of alphas and best alpha estimated by cross-validation.

        Parameters
        ----------
        X : ndarray of shape (n_samples, n_features)
            Training data.
        y : ndarray of shape (n_samples, n_targets)
            Training target variable. Will be cast to X's dtype if necessary.

        **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 MultiTaskElasticNet instance.
        r|  r   r9   r:   ry   r   s       r>   r   zMultiTaskElasticNetCV.fit      6 w{1a*6**r@   )r   r   r   r   r  r   r   r   r   r   r   r   rx   r   r   r#  r&  rv  r   r   r   s   @r>   r  r  
  s    kZ$

.
.$XdAq8,G$D  |,z*	"D
 #>%+ +r@   r  c                        e Zd ZU dZi ej
                  Zeed<   ej                  d       ej                  d        e	e
      Zddddd	d
ddddddd fd
Zd Zd Z fdZ fdZ xZS )MultiTaskLassoCVa  Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.

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

    The optimization objective for MultiTaskLasso is::

        (1 / (2 * n_samples)) * ||Y - XW||^Fro_2 + alpha * ||W||_21

    Where::

        ||W||_21 = \sum_i \sqrt{\sum_j w_{ij}^2}

    i.e. the sum of norm of each row.

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

    .. versionadded:: 0.15

    Parameters
    ----------
    eps : float, default=1e-3
        Length of the path. ``eps=1e-3`` means that
        ``alpha_min / alpha_max = 1e-3``.

    n_alphas : int, default=100
        Number of alphas along the regularization path.

    alphas : array-like, default=None
        List of alphas where to compute the models.
        If not provided, set automatically.

    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).

    max_iter : int, default=1000
        The maximum number of iterations.

    tol : float, default=1e-4
        The tolerance for the optimization: if the updates are
        smaller than ``tol``, the optimization code checks the
        dual gap for optimality and continues until it is smaller
        than ``tol``.

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

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

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

        For int/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.

    verbose : bool or int, default=False
        Amount of verbosity.

    n_jobs : int, default=None
        Number of CPUs to use during the cross validation. Note that this is
        used only if multiple values for l1_ratio are given.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance, default=None
        The seed of the pseudo random number generator that selects a random
        feature to update. Used when ``selection`` == 'random'.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    selection : {'cyclic', 'random'}, default='cyclic'
        If set to 'random', a random coefficient is updated every iteration
        rather than looping over features sequentially by default. This
        (setting to 'random') often leads to significantly faster convergence
        especially when tol is higher than 1e-4.

    Attributes
    ----------
    intercept_ : ndarray of shape (n_targets,)
        Independent term in decision function.

    coef_ : ndarray of shape (n_targets, n_features)
        Parameter vector (W in the cost function formula).
        Note that ``coef_`` stores the transpose of ``W``, ``W.T``.

    alpha_ : float
        The amount of penalization chosen by cross validation.

    mse_path_ : ndarray of shape (n_alphas, n_folds)
        Mean square error for the test set on each fold, varying alpha.

    alphas_ : ndarray of shape (n_alphas,)
        The grid of alphas used for fitting.

    n_iter_ : int
        Number of iterations run by the coordinate descent solver to reach
        the specified tolerance for the optimal alpha.

    dual_gap_ : float
        The dual gap at the end of the optimization for 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
    --------
    MultiTaskElasticNet : Multi-task ElasticNet model trained with L1/L2
        mixed-norm as regularizer.
    ElasticNetCV : Elastic net model with best model selection by
        cross-validation.
    MultiTaskElasticNetCV : Multi-task L1/L2 ElasticNet with built-in
        cross-validation.

    Notes
    -----
    The algorithm used to fit the model is coordinate descent.

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

    To avoid unnecessary memory duplication the `X` and `y` arguments of the
    `fit` method should be directly passed as Fortran-contiguous numpy arrays.

    Examples
    --------
    >>> from sklearn.linear_model import MultiTaskLassoCV
    >>> from sklearn.datasets import make_regression
    >>> from sklearn.metrics import r2_score
    >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)
    >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)
    >>> r2_score(y, reg.predict(X))
    0.9994...
    >>> reg.alpha_
    np.float64(0.5713...)
    >>> reg.predict(X[:1,])
    array([[153.7971...,  94.9015...]])
    r   rq   rt   rB   rC   NTr   r   Fr   r^   r_   rp   rE   r   r   r`   r  ro   r  r   r   c                <    t         |   |||||||||	|
||       y )Nr  r   )r   r^   r_   rp   rE   r   r   r`   r  ro   r  r   r   r   s                r>   r   zMultiTaskLassoCV.__init__  s;      	'% 	 	
r@   c                     t               S r   )r  r   s    r>   r#  zMultiTaskLassoCV._get_estimator  s    r@   c                      yr   r"  r   s    r>   r&  zMultiTaskLassoCV._is_multitask  r  r@   c                 h    t         |          }d|j                  _        d|j                  _        |S r  r  rx  s     r>   rv  z!MultiTaskLassoCV.__sklearn_tags__  r  r@   c                 &    t        |   ||fi |S )ap  Fit MultiTaskLasso model with coordinate descent.

        Fit is on grid of alphas and best alpha estimated by cross-validation.

        Parameters
        ----------
        X : ndarray of shape (n_samples, n_features)
            Data.
        y : ndarray of shape (n_samples, n_targets)
            Target. Will be cast to X's dtype if necessary.

        **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 fitted model.
        r|  r  s       r>   r   zMultiTaskLassoCV.fit  r  r@   )r   r   r   r   r  r   r   r   r   r   rz   r   r   r#  r&  rv  r   r   r   s   @r>   r  r    s    [z$

.
.$D  |,z*
#D
 
> + +r@   r  )r,   )NrA   TrB   rC   TN)Nr&   NN)Jr   r   r   abcr   r   	functoolsr   r   r   numpyr7   joblibr   scipyr	   sklearn.utilsr
   r  r   r   r   model_selectionr   utilsr   r   r   utils._metadata_requestsr   r   r   r   utils._param_validationr   r   r   utils.extmathr   utils.metadata_routingr   r   utils.parallelr   r   utils.validationr   r    r!   r"   r#   r$   r%    r'   r   _baser(   r)   r*   r?   rg   rz   rx   r   r   r  r  rn  r  r  r  r  r  r"  r@   r>   <module>r     s    
  #  "  #  * A A & 4 4  L K + /   " : :(d XBv O,O,q$y9:h4?@&!6(+YET"+"D);#K #'* 	k#"k\ O,O,dCV<=sD;<h4?@&!6(+YET"+"D);#K!{  #'#. D$'&D$V
g1!>; g1\v
J v
L 
K!\y$k3 yx~Hnm ~HBVH>= VHzy% yxL#( L#^+NM +Dn+~} n+r@   