
    2;jimS                       d Z ddlZddlZddlmZmZ ddlZddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZm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$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z= ddl>m?Z?m@Z@mAZAmBZB dZCd ZDdddddddddd d!dddddd"d#d$ZEd% ZF G d& d'eee          ZG G d( d)eGee          ZHdS )*z
Logistic Regression
    N)IntegralReal)optimize)HalfBinomialLossHalfMultinomialLoss)_fit_context)BaseEstimatorLinearClassifierMixinSparseCoefMixin)NewtonCholeskySolver)LinearModelLoss)
sag_solver)
get_scorerget_scorer_names)check_cv)LabelEncoder)_fit_liblinear)Bunchcheck_arraycheck_consistent_lengthcheck_random_statecompute_class_weight)HiddenInterval
StrOptions)	row_normssoftmax)"_get_additional_lbfgs_options_dict)MetadataRouterMethodMapping_raise_for_params_routing_enabledprocess_routing)check_classification_targets)_check_optimize_result
_newton_cg)Paralleldelayed)_check_method_params_check_sample_weightcheck_is_fittedvalidate_datazPlease also refer to the documentation for alternative solver options:
    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regressionc                     | dvr|dvrt          d|  d| d          | dk    r|rt          d|  d|           |dk    r| d	k    rt          d
|  d          | dk    r|t          d          | S )N)	liblinearsaga)l2NzSolver z+ supports only 'l2' or None penalties, got z	 penalty.r.   z$ supports only dual=False, got dual=
elasticnetr/   z;Only 'saga' solver supports elasticnet penalty, got solver=.zJC=np.inf as well as penalty=None is not supported for the liblinear solver)
ValueError)solverpenaltyduals      X/root/voice-cloning/.venv/lib/python3.11/site-packages/sklearn/linear_model/_logistic.py_check_solverr8   ?   s    ***wl/J/Jf     
 
 	
 U6UUtUUVVV,6V#3#3S&SSS
 
 	
 X
 
 	
 M    
   Td   -C6?lbfgsFr0         ?   )Csfit_interceptmax_itertolverboser4   coefclass_weightr6   r5   intercept_scalingrandom_statecheck_inputmax_squared_sumsample_weightl1_ratio	n_threadsc                   t          |t          j                  rt          j        dd|          }t          |||          }|rAt          | dt          j        |dv          } t          |dd          }t          | |           ||
t          || | j
        d	
          }| j        \  }}t          |          }|dk    }|dk    r|st          d          t          |          }t                                          |          }|
1t#          |
|||          }|||                    |                   z  }|rkt          j        |t)          |          z   | j
                  }||d         k    }t          j        |j        | j
                  }|dk    rd|| <   nid|| <   nb|                    |                              | j
        d          }t          j        |j        |t)          |          z   fd| j
                  }|dv r||nt          j        |          }|	&|r|	j        dk    r)|	j        d         |t)          |          z   k    r|	|dd<   n|	j        dk    r@|	j        d         dk    r/|	j        d         |t)          |          z   k    r|	d         |dd<   nd|	j         d|j         d|j        d          d}t          |          |	j        dk    rI|	j        d         |k    r8|	j        d         |t)          |          z   k    r|	|ddd|	j        d         f<   n!d|	j         d|j         }t          |          |ra|} t5          t7                      |          }!|dk    r|!j        }"n|dk    r|!j        }"|!j        }#|!j        }$dt          j         |d           i}%nrt5          tC          |j        !          |          }!|} |dv r|"                    d"          }|dk    r|!j        }"n|dk    r|!j        }"|!j        }#|!j        }$d|j#        i}%tI                      }&t          j        t          |          t          j%                  }'tM          |          D ]\  }(})|dk    rd#|)|z  z  }*g d$t          j'        t          j(        g d%          |                   }+tS          j*        |"|d&d	| | ||*|f|d'|d(t          j+        tX                    j-        z  d)t]          d*|+          +          },t_          ||,|t`          ,          }-|,j1        |,j2        }!}n|dk    r+d#|)|z  z  }*| | ||*|f}.tg          |$|"|#||.|||-          \  }}-nP|d.k    r?d#|)|z  z  }*ti          ||!|*||||/          }/|/5                    | | |0          }|/j6        }-n|dk    rtto          | | |)||d|||||||1          \  }0}1}-|r)t          j8        |0"                                |1g          }n|0"                                }|-9                                }-n|d2v rx|rd3}!n|                     | j
        d          } d4}!|d5k    rd}2d#|)z  }3n!|d6k    rd#|)z  }2d}3nd#|)z  d|z
  z  }2d#|)z  |z  }3tu          | | ||!|2|3||||d||%|d7k    8          \  }}-}%nd9| d:}t          |          |r(|&;                    |<                                           nG|dv rt          j=        ||d;fd"          }4n|}4|&;                    |4<                                           |-|'|(<   t          j(        |&          t          j(        |          |'fS )<a  Compute a Logistic Regression model for a list of regularization
    parameters.

    This is an implementation that uses the result of the previous model
    to speed up computations along the set of solutions, making it faster
    than sequentially calling LogisticRegression for the different parameters.
    Note that there will be no speedup with liblinear solver, since it does
    not handle warm-starting.

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

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

    y : array-like of shape (n_samples,) or (n_samples, n_targets)
        Input data, target values.

    classes : ndarray
        A list of class labels known to the classifier.

    Cs : int or array-like of shape (n_cs,), default=10
        List of values for the regularization parameter or integer specifying
        the number of regularization parameters that should be used. In this
        case, the parameters will be chosen in a logarithmic scale between
        1e-4 and 1e4.

    fit_intercept : bool, default=True
        Whether to fit an intercept for the model. In this case the shape of
        the returned array is (n_cs, n_features + 1).

    max_iter : int, default=100
        Maximum number of iterations for the solver.

    tol : float, default=1e-4
        Stopping criterion. For the newton-cg and lbfgs solvers, the iteration
        will stop when ``max{|g_i | i = 1, ..., n} <= tol``
        where ``g_i`` is the i-th component of the gradient.

    verbose : int, default=0
        For the liblinear and lbfgs solvers set verbose to any positive
        number for verbosity.

    solver : {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'},             default='lbfgs'
        Numerical solver to use.

    coef : array-like of shape (n_classes, features + int(fit_intercept)) or             (1, n_features + int(fit_intercept)) or             (n_features + int(fit_intercept)), default=None
        Initialization value for coefficients of logistic regression.
        Useless for liblinear solver.

    class_weight : dict or 'balanced', default=None
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one.

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``.

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

    dual : bool, default=False
        Dual or primal formulation. Dual formulation is only implemented for
        l2 penalty with liblinear solver. Prefer dual=False when
        n_samples > n_features.

    penalty : {'l1', 'l2', 'elasticnet'}, default='l2'
        Used to specify the norm used in the penalization. The 'newton-cg',
        'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is
        only supported by the 'saga' solver.

    intercept_scaling : float, default=1.
        Useful only when the solver `liblinear` is used
        and `self.fit_intercept` is set to `True`. In this case, `x` becomes
        `[x, self.intercept_scaling]`,
        i.e. a "synthetic" feature with constant value equal to
        `intercept_scaling` is appended to the instance vector.
        The intercept becomes
        ``intercept_scaling * synthetic_feature_weight``.

        .. note::
            The synthetic feature weight is subject to L1 or L2
            regularization as all other features.
            To lessen the effect of regularization on synthetic feature weight
            (and therefore on the intercept) `intercept_scaling` has to be increased.

    random_state : int, RandomState instance, default=None
        Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the
        data. See :term:`Glossary <random_state>` for details.

    check_input : bool, default=True
        If False, the input arrays X and y will not be checked.

    max_squared_sum : float, default=None
        Maximum squared sum of X over samples. Used only in SAG solver.
        If None, it will be computed, going through all the samples.
        The value should be precomputed to speed up cross validation.

    sample_weight : array-like of shape (n_samples,), default=None
        Array of weights that are assigned to individual samples.
        If not provided, then each sample is given unit weight.

    l1_ratio : float, default=None
        The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only
        used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent
        to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent
        to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a
        combination of L1 and L2.

    n_threads : int, default=1
       Number of OpenMP threads to use.

    Returns
    -------
    coefs : ndarray of shape (n_cs, n_classes, n_features + int(fit_intercept)) or             (n_cs, n_features + int(fit_intercept))
        List of coefficients for the Logistic Regression model. If fit_intercept is set
        to True, then the last dimension will be n_features + 1, where the last item
        represents the intercept.
        For binary problems the second dimension in n_classes is dropped, i.e. the shape
        will be `(n_cs, n_features + int(fit_intercept))`.

    Cs : ndarray
        Grid of Cs used for cross-validation.

    n_iter : array of shape (n_cs,)
        Actual number of iteration for each C in Cs.

    Notes
    -----
    You might get slightly different results with the solver liblinear than
    with the others since this uses LIBLINEAR which penalizes the intercept.

    .. versionchanged:: 0.19
        The "copy" parameter was removed.
       csrr.   sagr/   )accept_sparsedtypeaccept_large_sparseFN)	ensure_2drU   T)rU   copy   r.   The 'liblinear' solver does not support multiclass classification (n_classes >= 3). Either use another solver or wrap the estimator in a OneVsRestClassifier to keep applying a one-versus-rest scheme.classesyrK   rU   r?   g              rX   F)orderrU   )r=   	newton-cgnewton-choleskyr   z Initialization coef is of shape z, expected shape z or (1, ))	base_lossrA   r=   rc   rE   axis)	n_classes)rb   r>   )2   r?   r;   e   )r   r?   rY      zL-BFGS-Brk   @   )maxitermaxlsgtolftoliprint)methodjacargsoptions)extra_warning_msg)	grad_hessfuncgradx0rv   ro   rC   rD   rd   )rE   linear_lossl2_reg_strengthrC   rB   rM   rD   )Xr]   rK   rK   rS   r/   logmultinomiall1r0   r/   )is_sagazbsolver must be one of {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'}, got 'z
' instead.rj   )>
isinstancenumbersr   nplogspacer8   r   float64r   r*   rU   shapelenr3   r   r   fitr   	transformzerosintonesastypesizesumndimr   r   loss_gradientlossgradientgradient_hessian_productexpand_dimsr   ravelTlistint32	enumeratesearchsortedarrayr   minimizefinfofloatepsr   r%    _LOGISTIC_SOLVER_CONVERGENCE_MSGxfunr&   r   solve	iterationr   concatenateitemr   appendrX   reshape)5r   r]   r\   r@   rA   rB   rC   rD   r4   rE   rF   r6   r5   rG   rH   rI   rJ   rK   rL   rM   	n_samples
n_featuresri   	is_binaryleclass_weight_w0masky_binY_multisw_summsgtargetr   rz   r{   hesswarm_start_sagcoefsn_iteriCr~   rs   opt_resn_iter_irv   solcoef_
intercept_alphabetamulti_w0s5                                                        r7   _logistic_regression_pathr   V   s   F "g&'' $[Q##67D11F  &* &.J J	
 
 
 U$7771%%% L$<,]AQWSWXXXGIzGIQIY&
 
 	
 &l33L			G	$	$B,'Qm
 
 
 	r||A77 
Xj3}#5#55QWEEEGAJqw///[  E4%LL E4%LL
 ,,q//((u(==X\:M(:(::;3ag
 
 
 ::: ,39N9N 	&yA~~$*Q-:M@R@R3R"R"R111	QJqMQ&&JqMZ#m2D2D%DDDQ1118tz 8 8x8 8)+!8 8 8  !oo% 	QJqMY..JqMZ#m2D2D%DDD)-111o
1o%&&"tz " "x" "  !oo% (&((
 
 
 W%DD{""9D=D0D ".!"<"<"<=)GLAAA'
 
 
 >>>
 $$BW%DD{""9D=D0D "$FFEXc"ggRX...F" @ @1W!QZ0O*** 6 6@@F '!K'%!44	 
 96JJ  G ."B	  H y'+BB{""!QZ0Ov}oyID% 	 	 	LB (((!QZ0O&  /!#  C Q&FFB}HH{""*8!++ + +'E:x  #^U[[]]J$?@@[[]]  }}HH&& %qwU;;$$QwDaqQ\2a8++56), , ,(B..&++ + + 
 S//! 	*LL####BBB:b9b/EEELL)))q		8E??BHRLL&00r9   c                   | |         }| |         }||         }||         }d\  }}| t          ||           }||         }||         }t          ||fi d|d|d|d|d|d|d	|
d
|	d|d|d|d|d|ddd|d|\  }}}t          |          }||_        t	                      }t          |          }|D ]}|r|dddf         |_        |d         |_        n||_        d|_        |,|                    |	                    |||                     _|pi }t          | ||          }|                     ||||fi |           ||t          j        |          |fS )a  Computes scores across logistic_regression_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 labels.

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

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

    classes : ndarray
        A list of class labels known to the classifier.

    Cs : int or list of floats
        Each of the values in Cs describes the inverse of
        regularization strength. If Cs is as an int, then a grid of Cs
        values are chosen in a logarithmic scale between 1e-4 and 1e4.

    scoring : str, callable or None
        The scoring method to use for cross-validation. Options:

        - str: see :ref:`scoring_string_names` for options.
        - callable: a scorer callable object (e.g., function) with signature
          ``scorer(estimator, X, y)``. See :ref:`scoring_callable` for details.
        - `None`: :ref:`accuracy <accuracy_score>` is used.

    fit_intercept : bool
        If False, then the bias term is set to zero. Else the last
        term of each coef_ gives us the intercept.

    max_iter : int
        Maximum number of iterations for the solver.

    tol : float
        Tolerance for stopping criteria.

    class_weight : dict or 'balanced'
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one.

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

    verbose : int
        For the liblinear and lbfgs solvers set verbose to any positive
        number for verbosity.

    solver : {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'}
        Decides which solver to use.

    penalty : {'l1', 'l2', 'elasticnet'}
        Used to specify the norm used in the penalization. The 'newton-cg',
        'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is
        only supported by the 'saga' solver.

    dual : bool
        Dual or primal formulation. Dual formulation is only implemented for
        l2 penalty with liblinear solver. Prefer dual=False when
        n_samples > n_features.

    intercept_scaling : float
        Useful only when the solver `liblinear` is used
        and `self.fit_intercept` is set to `True`. In this case, `x` becomes
        `[x, self.intercept_scaling]`,
        i.e. a "synthetic" feature with constant value equal to
        `intercept_scaling` is appended to the instance vector.
        The intercept becomes
        ``intercept_scaling * synthetic_feature_weight``.

        .. note::
            The synthetic feature weight is subject to L1 or L2
            regularization as all other features.
            To lessen the effect of regularization on synthetic feature weight
            (and therefore on the intercept) `intercept_scaling` has to be increased.

    random_state : int, RandomState instance
        Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the
        data. See :term:`Glossary <random_state>` for details.

    max_squared_sum : float
        Maximum squared sum of X over samples. Used only in SAG solver.
        If None, it will be computed, going through all the samples.
        The value should be precomputed to speed up cross validation.

    sample_weight : array-like of shape (n_samples,)
        Array of weights that are assigned to individual samples.
        If not provided, then each sample is given unit weight.

    l1_ratio : float
        The Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only
        used if ``penalty='elasticnet'``. Setting ``l1_ratio=0`` is equivalent
        to using ``penalty='l2'``, while setting ``l1_ratio=1`` is equivalent
        to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a
        combination of L1 and L2.

    score_params : dict
        Parameters to pass to the `score` method of the underlying scorer.

    Returns
    -------
    coefs : ndarray of shape (n_cs, n_classes, n_features + int(fit_intercept)) or             (n_cs, n_features + int(fit_intercept))
        List of coefficients for the Logistic Regression model. If fit_intercept is set
        to True, then the last dimension will be n_features + 1, where the last item
        represents the intercept.
        For binary problems the second dimension in n_classes is dropped, i.e. the shape
        will be `(n_cs, n_features + int(fit_intercept))`.

    Cs : ndarray of shape (n_cs,)
        Grid of Cs used for cross-validation.

    scores : ndarray of shape (n_cs,)
        Scores obtained for each Cs.

    n_iter : ndarray of shape (n_cs,)
        Actual number of iteration for each C in Cs.
    )NNNr\   r@   rL   rA   r4   rB   rF   rC   rD   r6   r5   rG   rH   rI   FrJ   rK   )r4   .rj   ).rj   r_   r   )r   paramsindices)r*   r   LogisticRegressionclasses_r   r   r   r   r   scorer)   r   r   ) r   r]   traintestr\   r@   scoringrA   rB   rC   rF   rD   r4   r5   r6   rG   rH   rJ   rK   rL   score_paramsX_trainX_testy_trainy_testsw_trainsw_testr   r   log_regscoresws                                    r7   _log_reg_scoring_pathr     sM   n hGtWFhGtWF"Hg ,]A>> '% 2    2	
  $m v  "\ C  T  ,+ "\  E!" (#$ h%E2v* !///G GVVF!!G L L 	%c3B3hKGM!"7GGM!$G?MM'--g-NNOOOO'-2L/!LRVWWWL MM'''66JJ\JJKKKK"bhv&&..r9   c                       e Zd ZU dZ eh d          d e edh                    g eeddd          g eeddd	          dgd
g eeddd          gd
g eeddd          ge edh          dgdg eh d          g ee	ddd          gdgd
gde	gdZ
eed<   	 d!dddddddddddddddZ ed          d"d            Z fdZd Z fd Z xZS )#r   a2  
    Logistic Regression (aka logit, MaxEnt) classifier.

    This class implements regularized logistic regression using a set of available
    solvers. **Note that regularization is applied by default**. It can handle both
    dense and sparse input `X`. Use C-ordered arrays or CSR matrices containing 64-bit
    floats for optimal performance; any other input format will be converted (and
    copied).

    The solvers 'lbfgs', 'newton-cg', 'newton-cholesky' and 'sag' support only L2
    regularization with primal formulation, or no regularization. The 'liblinear'
    solver supports both L1 and L2 regularization (but not both, i.e. elastic-net),
    with a dual formulation only for the L2 penalty. The Elastic-Net (combination of L1
    and L2) regularization is only supported by the 'saga' solver.

    For :term:`multiclass` problems (whenever `n_classes >= 3`), all solvers except
    'liblinear' optimize the (penalized) multinomial loss. 'liblinear' only handles
    binary classification but can be extended to handle multiclass by using
    :class:`~sklearn.multiclass.OneVsRestClassifier`.

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

    Parameters
    ----------
    penalty : {'l1', 'l2', 'elasticnet', None}, default='l2'
        Specify the norm of the penalty:

        - `None`: no penalty is added;
        - `'l2'`: add a L2 penalty term and it is the default choice;
        - `'l1'`: add a L1 penalty term;
        - `'elasticnet'`: both L1 and L2 penalty terms are added.

        .. warning::
           Some penalties may not work with some solvers. See the parameter
           `solver` below, to know the compatibility between the penalty and
           solver.

        .. versionadded:: 0.19
           l1 penalty with SAGA solver (allowing 'multinomial' + L1)

        .. deprecated:: 1.8
           `penalty` was deprecated in version 1.8 and will be removed in 1.10.
           Use `l1_ratio` instead. `l1_ratio=0` for `penalty='l2'`, `l1_ratio=1` for
           `penalty='l1'` and `l1_ratio` set to any float between 0 and 1 for
           `'penalty='elasticnet'`.

    C : float, default=1.0
        Inverse of regularization strength; must be a positive float.
        Like in support vector machines, smaller values specify stronger
        regularization. `C=np.inf` results in unpenalized logistic regression.
        For a visual example on the effect of tuning the `C` parameter
        with an L1 penalty, see:
        :ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.

    l1_ratio : float, default=0.0
        The Elastic-Net mixing parameter, with `0 <= l1_ratio <= 1`. Setting
        `l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.
        Any value between 0 and 1 gives an Elastic-Net penalty of the form
        `l1_ratio * L1 + (1 - l1_ratio) * L2`.

        .. warning::
           Certain values of `l1_ratio`, i.e. some penalties, may not work with some
           solvers. See the parameter `solver` below, to know the compatibility between
           the penalty and solver.

        .. versionchanged:: 1.8
            Default value changed from None to 0.0.

        .. deprecated:: 1.8
            `None` is deprecated and will be removed in version 1.10. Always use
            `l1_ratio` to specify the penalty type.

    dual : bool, default=False
        Dual (constrained) or primal (regularized, see also
        :ref:`this equation <regularized-logistic-loss>`) formulation. Dual formulation
        is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`
        when n_samples > n_features.

    tol : float, default=1e-4
        Tolerance for stopping criteria.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the decision function.

    intercept_scaling : float, default=1
        Useful only when the solver `liblinear` is used
        and `self.fit_intercept` is set to `True`. In this case, `x` becomes
        `[x, self.intercept_scaling]`,
        i.e. a "synthetic" feature with constant value equal to
        `intercept_scaling` is appended to the instance vector.
        The intercept becomes
        ``intercept_scaling * synthetic_feature_weight``.

        .. note::
            The synthetic feature weight is subject to L1 or L2
            regularization as all other features.
            To lessen the effect of regularization on synthetic feature weight
            (and therefore on the intercept) `intercept_scaling` has to be increased.

    class_weight : dict or 'balanced', default=None
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one.

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``.

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

        .. versionadded:: 0.17
           *class_weight='balanced'*

    random_state : int, RandomState instance, default=None
        Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the
        data. See :term:`Glossary <random_state>` for details.

    solver : {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'},             default='lbfgs'

        Algorithm to use in the optimization problem. Default is 'lbfgs'.
        To choose a solver, you might want to consider the following aspects:

        - 'lbfgs' is a good default solver because it works reasonably well for a wide
          class of problems.
        - For :term:`multiclass` problems (`n_classes >= 3`), all solvers except
          'liblinear' minimize the full multinomial loss, 'liblinear' will raise an
          error.
        - 'newton-cholesky' is a good choice for
          `n_samples` >> `n_features * n_classes`, especially with one-hot encoded
          categorical features with rare categories. Be aware that the memory usage
          of this solver has a quadratic dependency on `n_features * n_classes`
          because it explicitly computes the full Hessian matrix.
        - For small datasets, 'liblinear' is a good choice, whereas 'sag'
          and 'saga' are faster for large ones;
        - 'liblinear' can only handle binary classification by default. To apply a
          one-versus-rest scheme for the multiclass setting one can wrap it with the
          :class:`~sklearn.multiclass.OneVsRestClassifier`.

        .. warning::
           The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`
           for L2-penalty, `l1_ratio=1` for L1-penalty and `0 < l1_ratio < 1` for
           Elastic-Net) and on (multinomial) multiclass support:

           ================= ======================== ======================
           solver            l1_ratio                 multinomial multiclass
           ================= ======================== ======================
           'lbfgs'           l1_ratio=0               yes
           'liblinear'       l1_ratio=1 or l1_ratio=0 no
           'newton-cg'       l1_ratio=0               yes
           'newton-cholesky' l1_ratio=0               yes
           'sag'             l1_ratio=0               yes
           'saga'            0<=l1_ratio<=1           yes
           ================= ======================== ======================

        .. note::
           'sag' and 'saga' fast convergence is only guaranteed on features
           with approximately the same scale. You can preprocess the data with
           a scaler from :mod:`sklearn.preprocessing`.

        .. seealso::
           Refer to the :ref:`User Guide <Logistic_regression>` for more
           information regarding :class:`LogisticRegression` and more specifically the
           :ref:`Table <logistic_regression_solvers>`
           summarizing solver/penalty supports.

        .. versionadded:: 0.17
           Stochastic Average Gradient (SAG) descent solver. Multinomial support in
           version 0.18.
        .. versionadded:: 0.19
           SAGA solver.
        .. versionchanged:: 0.22
           The default solver changed from 'liblinear' to 'lbfgs' in 0.22.
        .. versionadded:: 1.2
           newton-cholesky solver. Multinomial support in version 1.6.

    max_iter : int, default=100
        Maximum number of iterations taken for the solvers to converge.

    verbose : int, default=0
        For the liblinear and lbfgs solvers set verbose to any positive
        number for verbosity.

    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.
        Useless for liblinear solver. See :term:`the Glossary <warm_start>`.

        .. versionadded:: 0.17
           *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.

    n_jobs : int, default=None
        Does not have any effect.

        .. deprecated:: 1.8
           `n_jobs` is deprecated in version 1.8 and will be removed in 1.10.

    Attributes
    ----------

    classes_ : ndarray of shape (n_classes, )
        A list of class labels known to the classifier.

    coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)
        Coefficient of the features in the decision function.

        `coef_` is of shape (1, n_features) when the given problem is binary.

    intercept_ : ndarray of shape (1,) or (n_classes,)
        Intercept (a.k.a. bias) added to the decision function.

        If `fit_intercept` is set to False, the intercept is set to zero.
        `intercept_` is of shape (1,) when the given problem is binary.

    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

    n_iter_ : ndarray of shape (1, )
        Actual number of iterations for all classes.

        .. versionchanged:: 0.20

            In SciPy <= 1.0.0 the number of lbfgs iterations may exceed
            ``max_iter``. ``n_iter_`` will now report at most ``max_iter``.

    See Also
    --------
    SGDClassifier : Incrementally trained logistic regression (when given
        the parameter ``loss="log_loss"``).
    LogisticRegressionCV : Logistic regression with built-in cross validation.

    Notes
    -----
    The underlying C implementation uses a random number generator to
    select features when fitting the model. It is thus not uncommon,
    to have slightly different results for the same input data. If
    that happens, try with a smaller tol parameter.

    Predict output may not match that of standalone liblinear in certain
    cases. See :ref:`differences from liblinear <liblinear_differences>`
    in the narrative documentation.

    References
    ----------

    L-BFGS-B -- Software for Large-scale Bound-constrained Optimization
        Ciyou Zhu, Richard Byrd, Jorge Nocedal and Jose Luis Morales.
        http://users.iems.northwestern.edu/~nocedal/lbfgsb.html

    LIBLINEAR -- A Library for Large Linear Classification
        https://www.csie.ntu.edu.tw/~cjlin/liblinear/

    SAG -- Mark Schmidt, Nicolas Le Roux, and Francis Bach
        Minimizing Finite Sums with the Stochastic Average Gradient
        https://hal.inria.fr/hal-00860051/document

    SAGA -- Defazio, A., Bach F. & Lacoste-Julien S. (2014).
            :arxiv:`"SAGA: A Fast Incremental Gradient Method With Support
            for Non-Strongly Convex Composite Objectives" <1407.0202>`

    Hsiang-Fu Yu, Fang-Lan Huang, Chih-Jen Lin (2011). Dual coordinate descent
        methods for logistic regression and maximum entropy models.
        Machine Learning 85(1-2):41-75.
        https://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf

    Examples
    --------
    >>> from sklearn.datasets import load_iris
    >>> from sklearn.linear_model import LogisticRegression
    >>> X, y = load_iris(return_X_y=True)
    >>> clf = LogisticRegression(random_state=0).fit(X, y)
    >>> clf.predict(X[:2, :])
    array([0, 0])
    >>> clf.predict_proba(X[:2, :])
    array([[9.82e-01, 1.82e-02, 1.44e-08],
           [9.72e-01, 2.82e-02, 3.02e-08]])
    >>> clf.score(X, y)
    0.97

    For a comparison of the LogisticRegression with other classifiers see:
    :ref:`sphx_glr_auto_examples_classification_plot_classification_probability.py`.
    >   r   r0   r1   N
deprecatedr   rightclosedr?   bothbooleanleftneitherbalancedrH   >   rS   r/   r=   r.   rc   rd   rD   r5   r   rL   r6   rC   rA   rG   rF   rH   r4   rB   rD   
warm_startn_jobs_parameter_constraintsr>   r_   Fr<   Tr=   r;   )r   rL   r6   rC   rA   rG   rF   rH   r4   rB   rD   r   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        d S Nr   )selfr5   r   rL   r6   rC   rA   rG   rF   rH   r4   rB   rD   r   r   s                  r7   __init__zLogisticRegression.__init__  sn    $  	*!2(( $r9   prefer_skip_nested_validationc                 	   | j         dk    r^| j        dk    s| j        $d}| j        t          j        dt                     n| j        dk    rd}nd}| j        t          j        k    rd}n!| j         }t          j        d	t                     t          | j	        || j
                  }|dk    rC| j        <d| j        cxk     rdk     r*n n't          j        d
                    |                     | j         dk    r| j        dk    s| j         dk    r0| j        dk    r%t          j        d| j          d| j         d           |dk    r| j        t          d          |.| j        dk    rt          j        d           t          j        }d}n| j        }d| j         d}| j        t          j        |t                     |dk    rt          j        }nt          j        t          j        g}t!          | ||d|d|dv          \  }}|j        d         }	t%          |           t          j        |          | _        t+          | j                  }
|
dk    }|dk    r|st          d          t          j        |          dk    rt          d          t/          ||| j        | j        | j        | j        || j
        | j        | j        | j        | j        |          \  | _        | _         | _!        | S |dv r$tE          |d !                                          }nd}|
dk     rt          d"| j        d         z            | j#        rtI          | d#d          }nd}|7| j        r0t          j%        || j         ddt          j&        f         d$          }d}tO          ||fi d%| j        d&|gd'| j        d(| j        d)| j        d*| j        d+|d,| j        d-| j        d.d/d0| j        d1|d2|d3|d4|d5|\  }}}t          j(        |t          j)        6          | _!        |d         | _        | j        rd|r3| j        d7d         | _         | j        dd7         dddf         | _        n| j        ddd7f         | _         | j        dddd7f         | _        nY|r7t          j*        d|j+        6          | _         | j        dddf         | _        n t          j*        |
|j+        6          | _         | S )8an  
        Fit the model according to the given training data.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target vector relative to X.

        sample_weight : array-like of shape (n_samples,) default=None
            Array of weights that are assigned to individual samples.
            If not provided, then each sample is given unit weight.

            .. versionadded:: 0.17
               *sample_weight* support to LogisticRegression.

        Returns
        -------
        self
            Fitted estimator.

        Notes
        -----
        The SAGA solver supports both float64 and float32 bit arrays.
        r   r   Nr0   zl'l1_ratio=None' was deprecated in version 1.8 and will trigger an error in 1.10. Use 0<=l1_ratio<=1 instead.r?   r   r1   a  'penalty' was deprecated in version 1.8 and will be removed in 1.10. To avoid this warning, leave 'penalty' set to its default value and use 'l1_ratio' or 'C' instead. Use l1_ratio=0 instead of penalty='l2', l1_ratio=1 instead of penalty='l1', and C=np.inf instead of penalty=None.zNl1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})zInconsistent values: penalty=z with l1_ratio=z2. penalty is deprecated. Please use l1_ratio only.z6l1_ratio must be specified when penalty is elasticnet.r>   z>Setting penalty=None will ignore the C and l1_ratio parameterszS'n_jobs' has no effect since 1.8 and will be removed in 1.10. You provided 'n_jobs=z', please leave it unspecified.)categoryr=   rQ   r   rR   rT   rU   rb   rV   rY   r.   rZ   gꌠ9Y>)FzUsing the 'liblinear' solver while X contains a maximum value > 1e30 results in a frozen fit. Please choose another solver or rescale the input X.r   r   TsquaredzeThis solver needs samples of at least 2 classes in the data, but the data contains only one class: %rr   rg   r\   r@   rL   rA   rC   rD   r4   rB   rF   rI   FrH   rE   r5   rJ   rK   rM   r^   rj   ),r5   rL   warningswarnFutureWarningr   r   infr8   r4   r6   formatr3   r   r   float32r,   r   r$   uniquer   r   maxr   rA   rG   rF   rD   rB   rC   rH   r   r   n_iter_r   r   getattrr   newaxisr   asarrayr   r   rU   )r   r   r]   rK   r5   r4   C_r   _dtyper   ri   r   rJ   warm_start_coefrM   r   _r   s                     r7   r   zLogisticRegression.fit>  s/   < <<''}!!T]%:=(MT &   !##&vlGM8 
 
 
 t{GTY??l""M%!dm*?*?*?*?a*?*?*?*?*?M%vg  
 LD  T]a%7%7LD  T]a%7%7M" " " M" " "  
 l""t}'<UVVV?v}}T   BGGBQ$(KQ Q Q 	 ;"M#6666WZFFj"*-F &.J J
 
 
1 WQZ
$Q'''	!&&	N	[    .   vayy4 5  
 9G"&!	!+9 9 95DJ K_$$'4888<<>>OO"Oq==#}Q/0   ? 	#%dGT::OO"O&4+=& iBJ!?a  O 	4
 
 
 MM
 tt	

 ]]
 ,,
 
 LL
 6
 ]]
 **
 
 **
 !
 G
  ,O!
" (-#
$  i%
q&* z&9991X
 	E 0"&*RSS/!Z_T111W5

"&*QQQU"3!Z3B3/

 E"$(1AG"<"<"<!Zaaa0

"$(9AG"D"D"Dr9   c                     t          |            | j        j        dk    }|r!t                                          |          S |                     |          }t          |d          S )a  
        Probability estimates.

        The returned estimates for all classes are ordered by the
        label of classes.

        For a multiclass / multinomial problem the softmax function is used to find
        the predicted probability of each class.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Vector to be scored, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        T : array-like of shape (n_samples, n_classes)
            Returns the probability of the sample for each class in the model,
            where classes are ordered as they are in ``self.classes_``.
        rY   Fr`   )r+   r   r   super_predict_proba_lrdecision_functionr   )r   r   r   decision_2d	__class__s       r7   predict_probaz LogisticRegression.predict_proba  sh    , 	M&!+	 	477,,Q///0033K;U3333r9   c                 P    t          j        |                     |                    S )ap  
        Predict logarithm of probability estimates.

        The returned estimates for all classes are ordered by the
        label of classes.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Vector to be scored, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        T : array-like of shape (n_samples, n_classes)
            Returns the log-probability of the sample for each class in the
            model, where classes are ordered as they are in ``self.classes_``.
        )r   r   r  )r   r   s     r7   predict_log_probaz$LogisticRegression.predict_log_proba5  s"    & vd((++,,,r9   c                     t                                                      }d|j        _        | j        dk    rd|j        _        |S )NTr.   F)r  __sklearn_tags__
input_tagssparser4   classifier_tagsmulti_classr   tagsr  s     r7   r  z#LogisticRegression.__sklearn_tags__J  s?    ww''))!%;+%%/4D ,r9   )r   r   )__name__
__module____qualname____doc__r   r   r   r   dictr   r   __annotations__r   r   r   r  r  r  __classcell__r  s   @r7   r   r     s        b bL	 J11122F::|n--..

 htQW5556XdAq888$?q$v6667#&htQYGGGHzz:,77>'(JUUU 

 Xh4???@; k"-$ $D   6  !    B \555U U U 65Un4 4 4 4 4>- - -*        r9   r   c                       e Zd ZU dZi ej        Zeed<   dD ]Ze	                    e           e
                     eeddd          dgdd e ed	h                    gd
g e e e                                edgdg eh d           e edh                    gd e ed	h                    gd           dd	ddddddddddddddd	ddZ ed          dd            ZddZd Zd Z fdZ xZS ) LogisticRegressionCVa:  Logistic Regression CV (aka logit, MaxEnt) classifier.

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

    This class implements regularized logistic regression with implicit cross
    validation for the penalty parameters `C` and `l1_ratio`, see
    :class:`LogisticRegression`, using a set of available solvers.

    The solvers 'lbfgs', 'newton-cg', 'newton-cholesky' and 'sag' support only L2
    regularization with primal formulation. The 'liblinear'
    solver supports both L1 and L2 regularization (but not both, i.e. elastic-net),
    with a dual formulation only for the L2 penalty. The Elastic-Net (combination of L1
    and L2) regularization is only supported by the 'saga' solver.

    For the grid of `Cs` values and `l1_ratios` values, the best hyperparameter
    is selected by the cross-validator
    :class:`~sklearn.model_selection.StratifiedKFold`, but it can be changed
    using the :term:`cv` parameter. All solvers except 'liblinear' can warm-start the
    coefficients (see :term:`Glossary<warm_start>`).

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

    Parameters
    ----------
    Cs : int or list of floats, default=10
        Each of the values in Cs describes the inverse of regularization
        strength. If Cs is as an int, then a grid of Cs values are chosen
        in a logarithmic scale between 1e-4 and 1e4.
        Like in support vector machines, smaller values specify stronger
        regularization.

    l1_ratios : array-like of shape (n_l1_ratios), default=None
        Floats between 0 and 1 passed as Elastic-Net mixing parameter (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.
        All the values of the given array-like are tested by cross-validation and the
        one giving the best prediction score is used.

        .. warning::
           Certain values of `l1_ratios`, i.e. some penalties, may not work with some
           solvers. See the parameter `solver` below, to know the compatibility between
           the penalty and solver.

        .. deprecated:: 1.8
            `l1_ratios=None` is deprecated in 1.8 and will raise an error
            in version 1.10. Default value will change from `None` to `(0.0,)`
            in version 1.10.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the decision function.

    cv : int or cross-validation generator, default=None
        The default cross-validation generator used is Stratified K-Folds.
        If an integer is provided, it specifies the number of folds, `n_folds`, used.
        See the module :mod:`sklearn.model_selection` module for the
        list of possible cross-validation objects.

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

    dual : bool, default=False
        Dual (constrained) or primal (regularized, see also
        :ref:`this equation <regularized-logistic-loss>`) formulation. Dual formulation
        is only implemented for l2 penalty with liblinear solver. Prefer dual=False when
        n_samples > n_features.

    penalty : {'l1', 'l2', 'elasticnet'}, default='l2'
        Specify the norm of the penalty:

        - `'l2'`: add a L2 penalty term (used by default);
        - `'l1'`: add a L1 penalty term;
        - `'elasticnet'`: both L1 and L2 penalty terms are added.

        .. warning::
           Some penalties may not work with some solvers. See the parameter
           `solver` below, to know the compatibility between the penalty and
           solver.

        .. deprecated:: 1.8
           `penalty` was deprecated in version 1.8 and will be removed in 1.10.
           Use `l1_ratio` instead. `l1_ratio=0` for `penalty='l2'`, `l1_ratio=1` for
           `penalty='l1'` and `l1_ratio` set to any float between 0 and 1 for
           `'penalty='elasticnet'`.

    scoring : str or callable, default=None
        The scoring method to use for cross-validation. Options:

        - str: see :ref:`scoring_string_names` for options.
        - callable: a scorer callable object (e.g., function) with signature
          ``scorer(estimator, X, y)``. See :ref:`scoring_callable` for details.
        - `None`: :ref:`accuracy <accuracy_score>` is used.

    solver : {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'},             default='lbfgs'

        Algorithm to use in the optimization problem. Default is 'lbfgs'.
        To choose a solver, you might want to consider the following aspects:

        - 'lbfgs' is a good default solver because it works reasonably well for a wide
          class of problems.
        - For :term:`multiclass` problems (`n_classes >= 3`), all solvers except
          'liblinear' minimize the full multinomial loss, 'liblinear' will raise an
          error.
        - 'newton-cholesky' is a good choice for
          `n_samples` >> `n_features * n_classes`, especially with one-hot encoded
          categorical features with rare categories. Be aware that the memory usage
          of this solver has a quadratic dependency on `n_features * n_classes`
          because it explicitly computes the full Hessian matrix.
        - For small datasets, 'liblinear' is a good choice, whereas 'sag'
          and 'saga' are faster for large ones;
        - 'liblinear' might be slower in :class:`LogisticRegressionCV`
          because it does not handle warm-starting.
        - 'liblinear' can only handle binary classification by default. To apply a
          one-versus-rest scheme for the multiclass setting one can wrap it with the
          :class:`~sklearn.multiclass.OneVsRestClassifier`.

        .. warning::
           The choice of the algorithm depends on the penalty (`l1_ratio=0` for
           L2-penalty, `l1_ratio=1` for L1-penalty and `0 < l1_ratio < 1` for
           Elastic-Net) chosen and on (multinomial) multiclass support:

           ================= ======================== ======================
           solver            l1_ratio                 multinomial multiclass
           ================= ======================== ======================
           'lbfgs'           l1_ratio=0               yes
           'liblinear'       l1_ratio=1 or l1_ratio=0 no
           'newton-cg'       l1_ratio=0               yes
           'newton-cholesky' l1_ratio=0               yes
           'sag'             l1_ratio=0               yes
           'saga'            0<=l1_ratio<=1           yes
           ================= ======================== ======================

        .. note::
           'sag' and 'saga' fast convergence is only guaranteed on features
           with approximately the same scale. You can preprocess the data with
           a scaler from :mod:`sklearn.preprocessing`.

        .. versionadded:: 0.17
           Stochastic Average Gradient (SAG) descent solver. Multinomial support in
           version 0.18.
        .. versionadded:: 0.19
           SAGA solver.
        .. versionadded:: 1.2
           newton-cholesky solver. Multinomial support in version 1.6.

    tol : float, default=1e-4
        Tolerance for stopping criteria.

    max_iter : int, default=100
        Maximum number of iterations of the optimization algorithm.

    class_weight : dict or 'balanced', default=None
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one.

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``.

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

        .. versionadded:: 0.17
           class_weight == 'balanced'

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

    verbose : int, default=0
        For the 'liblinear', 'sag' and 'lbfgs' solvers set verbose to any
        positive number for verbosity.

    refit : bool, default=True
        If set to True, the scores are averaged across all folds, and the
        coefs and the C that corresponds to the best score is taken, and a
        final refit is done using these parameters.
        Otherwise the coefs, intercepts and C that correspond to the
        best scores across folds are averaged.

    intercept_scaling : float, default=1
        Useful only when the solver `liblinear` is used
        and `self.fit_intercept` is set to `True`. In this case, `x` becomes
        `[x, self.intercept_scaling]`,
        i.e. a "synthetic" feature with constant value equal to
        `intercept_scaling` is appended to the instance vector.
        The intercept becomes
        ``intercept_scaling * synthetic_feature_weight``.

        .. note::
            The synthetic feature weight is subject to L1 or L2
            regularization as all other features.
            To lessen the effect of regularization on synthetic feature weight
            (and therefore on the intercept) `intercept_scaling` has to be increased.

    random_state : int, RandomState instance, default=None
        Used when `solver='sag'`, 'saga' or 'liblinear' to shuffle the data.
        Note that this only applies to the solver and not the cross-validation
        generator. See :term:`Glossary <random_state>` for details.

    use_legacy_attributes : bool, default=True
        If True, use legacy values for attributes:

        - `C_` is an ndarray of shape (n_classes,) with the same value repeated
        - `l1_ratio_` is an ndarray of shape (n_classes,) with the same value repeated
        - `coefs_paths_` is a dict with class labels as keys and ndarrays as values
        - `scores_` is a dict with class labels as keys and ndarrays as values
        - `n_iter_` is an ndarray of shape (1, n_folds, n_cs) or similar

        If False, use new values for attributes:

        - `C_` is a float
        - `l1_ratio_` is a float
        - `coefs_paths_` is an ndarray of shape
          (n_folds, n_l1_ratios, n_cs, n_classes, n_features)
          For binary problems (n_classes=2), the 2nd last dimension is 1.
        - `scores_` is an ndarray of shape (n_folds, n_l1_ratios, n_cs)
        - `n_iter_` is an ndarray of shape (n_folds, n_l1_ratios, n_cs)

        .. versionchanged:: 1.10
           The default will change from True to False in version 1.10.
        .. deprecated:: 1.10
           `use_legacy_attributes` will be deprecated in version 1.10 and be removed in
           1.12.

    Attributes
    ----------
    classes_ : ndarray of shape (n_classes, )
        A list of class labels known to the classifier.

    coef_ : ndarray of shape (1, n_features) or (n_classes, n_features)
        Coefficient of the features in the decision function.

        `coef_` is of shape (1, n_features) when the given problem
        is binary.

    intercept_ : ndarray of shape (1,) or (n_classes,)
        Intercept (a.k.a. bias) added to the decision function.

        If `fit_intercept` is set to False, the intercept is set to zero.
        `intercept_` is of shape (1,) when the problem is binary.

    Cs_ : ndarray of shape (n_cs)
        Array of C i.e. inverse of regularization parameter values used
        for cross-validation.

    l1_ratios_ : ndarray of shape (n_l1_ratios)
        Array of l1_ratios used for cross-validation. If l1_ratios=None is used
        (i.e. penalty is not 'elasticnet'), this is set to ``[None]``

    coefs_paths_ : dict of ndarray of shape (n_folds, n_cs, n_dof) or             (n_folds, n_cs, n_l1_ratios, n_dof)
        A dict with classes as the keys, and the path of coefficients obtained
        during cross-validating across each fold (`n_folds`) and then across each Cs
        (`n_cs`).
        The size of the coefficients is the number of degrees of freedom (`n_dof`),
        i.e. without intercept `n_dof=n_features` and with intercept
        `n_dof=n_features+1`.
        If `penalty='elasticnet'`, there is an additional dimension for the number of
        l1_ratio values (`n_l1_ratios`), which gives a shape of
        ``(n_folds, n_cs, n_l1_ratios_, n_dof)``.
        See also parameter `use_legacy_attributes`.

    scores_ : dict
        A dict with classes as the keys, and the values as the
        grid of scores obtained during cross-validating each fold.
        The same score is repeated across all classes. Each dict value
        has shape ``(n_folds, n_cs)`` or ``(n_folds, n_cs, n_l1_ratios)`` if
        ``penalty='elasticnet'``.
        See also parameter `use_legacy_attributes`.

    C_ : ndarray of shape (n_classes,) or (1,)
        The value of C that maps to the best score, repeated n_classes times.
        If refit is set to False, the best C is the average of the
        C's that correspond to the best score for each fold.
        `C_` is of shape (1,) when the problem is binary.
        See also parameter `use_legacy_attributes`.

    l1_ratio_ : ndarray of shape (n_classes,) or (n_classes - 1,)
        The value of l1_ratio that maps to the best score, repeated n_classes times.
        If refit is set to False, the best l1_ratio is the average of the
        l1_ratio's that correspond to the best score for each fold.
        `l1_ratio_` is of shape (1,) when the problem is binary.
        See also parameter `use_legacy_attributes`.

    n_iter_ : ndarray of shape (1, n_folds, n_cs) or (1, n_folds, n_cs, n_l1_ratios)
        Actual number of iterations for all classes, folds and Cs.
        If `penalty='elasticnet'`, the shape is `(1, n_folds, n_cs, n_l1_ratios)`.
        See also parameter `use_legacy_attributes`.

    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
    --------
    LogisticRegression : Logistic regression without tuning the
        hyperparameter `C`.

    Examples
    --------
    >>> from sklearn.datasets import load_iris
    >>> from sklearn.linear_model import LogisticRegressionCV
    >>> X, y = load_iris(return_X_y=True)
    >>> clf = LogisticRegressionCV(
    ...     cv=5, random_state=0, use_legacy_attributes=False, l1_ratios=(0,)
    ... ).fit(X, y)
    >>> clf.predict(X[:2, :])
    array([0, 0])
    >>> clf.predict_proba(X[:2, :]).shape
    (2, 3)
    >>> clf.score(X, y)
    0.98...
    r   )r   r   rL   r?   Nr   r   z
array-liker   	cv_objectr   >   r   r0   r1   r   )r@   	l1_ratioscvr   refitr5   use_legacy_attributesr:   TFr=   r<   r;   r   r>   )r@   r#  rA   r$  r6   r5   r   r4   rC   rB   rF   r   rD   r%  rG   rH   r&  c                    || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        d S r   )r@   r#  rA   r$  r6   r5   r   rC   rB   rF   r   rD   r4   r%  rG   rH   r&  )r   r@   r#  rA   r$  r6   r5   r   r4   rC   rB   rF   r   rD   r%  rG   rH   r&  s                     r7   r   zLogisticRegressionCV.__init__  s    * "*	 (
!2(%:"""r9   r   c                 2   '()*+,-./ t          | d           t           j        t                    r( j        dk    rd}t	          j        dt                     n j        } j        dk    r j        t	          j        dt                     t          j	        t          j
        |          dk              s|d-nQt          j	        t          j
        |          d	k              rd
-n$d-n! j        -t	          j        dt                      j        dk    r8t	          j        d j        j         d j        j         dt                     d}n j        }t           j        - j                  /-dk    rC|,t#          |          dk    st%          d |D                       rt'          d|z            |*n<|2 j        dk    r't	          j        d                    -                     |dg*n|*t+           dt          j        d/dv          \  j        d	         }t1                      j        (t5                                                    }|j        x}	 _        t#           j                  }
|
dk    }|
dk     rt'          d j        d          d          /dv r$t;          d                                          +nd+t?                      rtA           dfdi|.nItC                      .tC          i           ._"        tC          |          ._#        .j#        j$        d<   tK           j&        d           }tO           |j(        fi .j"        j(                  }t          (tR                    rftU          (+                                          tU           j                  k    s.d! j         d"(+                                 }t'          |          n@(d#k    r:tY          ( j        $          (tS          t[           j        (                    (|rd	}
|	d	d         }	t]          t^                    , j        dv rd%}nd&} ta           j1         j2        |'          (*+,-. /fd(|D                       }t[          | \  )}}}|d          _3        |rbt          j4        )t#          |          t#          *          t#           j3                  d)f          )t          j5        )d	d          d*         )n\t          j4        )t#          |          t#          *          t#           j3                  |
d)f          )t          j6        )d+d,          )t          j4        |t#          |          t#          *          t#           j3                  f          }t          j5        |d	d          d*          _7        t          j4        |t#          |          t#          *          t#           j3                  f          }t          j5        |d	d          d*         }t          j8        ||
d	d	d	f          }tS          t[          |	|                     _9        tS          t[          |	)                     _:        tO                       _;        tO                       _<        t          j=        |
|f           _>        t          j?        |
           _@         j9        |	d                  } jA        rD|B                    d-          }t          jC        t          jD        |          |j                  } j3        |d                  } j;        E                    |           *|d	                  } j<        E                    |           |r(t          jF        )dddg|ddR          d-          }n)t          jF        )ddddg|ddR          d	-          }t          f j        |g/ jH        | jI         jJ        -(t=          d j2        d	z
             jK        d.+|d/\  }}}|d         }n|j        \  }}}|4                    |d)          }t          jD        |d	-          't          jC        '||f          'tO          t[          '           '|r>t          jF        ')fd0t          t#          |                    D             d-          }n=t          jF        ')fd1t          t#          |                    D             d-          }t          j
        '          ''dddf         } j;        E                    t          jF         j3        |                              -dk    r?'ddd	f         } j<        E                    t          jF        *|                              n j<        E                    d           |r]|jM        dk    r|ddd|f         n|d|         dddf          _>         jH        r#|jM        dk    r|d2         n|d)          j@        d<   nit          j8         j;        |
           _;        t          j8         j<        |
           _<        |ddd|f          _>         jH        r|ddd)f          _@        t          j
         j;                   _;        t          j
         j<                   _<        t          j
        *           _N        | j:        O                                D ]\  } }!|!dddddddf          j:        | <     j9        O                                D ]\  } }"|"dddddf          j9        | <    j7        dddddddf          _7        |st#          |          } j3        jP        }j        d	         t           jH                  z   }#t           j;        d                    _;        t          jS        tO           j:        T                                                    }$ j9        |	d                  }% j7        d         }&||
dk    r|$4                    d	||d	|#          }$n|$4                    |
||d	|#          }$|%4                    ||d	          }%|&4                    ||d	          }& j        d
k    rd3 _<        ntd4 _<        nlt#           jN                  }t           j<        d                    _<        |
dk    r|$4                    d	||||#          }$n|$4                    |
||||#          }$t          j6        |$d+d5           _:        t          j6        |%d6d7           _9        t          j6        |&d6d7           _7         S )8a@  Fit the model according to the given training data.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target vector relative to X.

        sample_weight : array-like of shape (n_samples,) default=None
            Array of weights that are assigned to individual samples.
            If not provided, then each sample is given unit weight.

        **params : dict
            Parameters to pass to the underlying splitter and scorer.

            .. versionadded:: 1.4

        Returns
        -------
        self : object
            Fitted LogisticRegressionCV estimator.
        r   r   NzThe default value for l1_ratios will change from None to (0.0,) in version 1.10. From version 1.10 onwards, only array-like with values in [0, 1] will be allowed, None will be forbidden. To avoid this warning, explicitly set a value, e.g. l1_ratios=(0,).r   z'l1_ratios=None' was deprecated in version 1.8 and will trigger an error in 1.10. Use an array-like with valuesin [0, 1] instead.r   r0   r?   r   r1   z'penalty' was deprecated in version 1.8 and will be removed in 1.10. To avoid this warning, leave 'penalty' set to its default value and use 'l1_ratios' instead. Use l1_ratios=(0,) instead of penalty='l2'  and l1_ratios=(1,) instead of penalty='l1'.zThe fitted attributes of ax   will be simplified in scikit-learn 1.10 to remove redundancy. Set`use_legacy_attributes=False` to enable the new behavior now, or set it to `True` to silence this warning during the transition period while keeping the deprecated behavior for the time being. The default value of use_legacy_attributes will change from True to False in scikit-learn 1.10. See the docstring of z for more details.Tc              3   d   K   | ]+}t          |t          j                   p|d k     p|dk    V  ,dS )r   r?   N)r   r   Number).0rL   s     r7   	<genexpr>z+LogisticRegressionCV.fit.<locals>.<genexpr>4  s_         !	 'x@@@ (#a<(#a<	     r9   zNl1_ratios must be an array-like of numbers between 0 and 1; got (l1_ratios=%r)zOl1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})rQ   r   rR   r   rY   zcThis solver needs samples of at least 2 classes in the data, but the data contains only one class: r2   r   r   rK   )splitr   )
classifierzHThe given class_weight dict must have the class labels as keys; classes=z	 but key=r   r[   threads	processes)r   rD   preferc              3     K   | ]\  }}D ]}} ||fi d j         dj        dj        d	dj        ddj        dj        dj        d	d
j        dj        dj	        ddd|d
j
        j        V  ~dS )r\   r@   rA   r5   r6   r4   rC   rB   rD   rF   r   rG   rH   rJ   rK   rL   r   N)r   r@   rA   r6   rC   rB   rD   r   rG   rH   scorerr   )r+  r   r   rL   r   rF   
l1_ratios_rJ   	path_funcr5   routed_paramsrK   r   r4   r]   s       r7   r,  z+LogisticRegressionCV.fit.<locals>.<genexpr>  si      X
 X
0 t&3X
 X
2 1 I	  
  77 #00   YY v HH   *\   #'"8"8!" "..#$ !0%& ,m'( ")* +177+X
 X
 X
 X
 X
 X
 X
r9   rj   )N.)r   r?   rm   )r?   rm   r   rg   F)r\   r@   r4   rA   rE   rB   rC   r5   rF   rD   rH   rI   rJ   rK   rL   c                 >    g | ]}d |g|         ddR          S )r   N r+  r   best_indicescoefs_pathss     r7   
<listcomp>z,LogisticRegressionCV.fit.<locals>.<listcomp>  s8    WWW[A!:Q!:!:!:;WWWr9   c           	      b    g | ]+}d d ||         d         |         d         d d f         ,S )Nr   r?   r9  r:  s     r7   r=  z,LogisticRegressionCV.fit.<locals>.<listcomp>  sV        $AAAq,q/!*<l1oa>PRSRSRS$ST  r9   )r   rj   r>   r_   )rm   r   r?   )r?   rY   )rY   r?   )Ur!   r   r#  strr   r   r   r5   r   allr  r&  r  r  r8   r4   r6   r   anyr3   r   r,   r   r   r$   rF   r   r   r   r   r   r"   r#   r   splitterr4  r   r   r$  r   r-  r  setkeysr   zipr(   r   r'   r   rD   Cs_r   swapaxesmoveaxisr   tilescores_coefs_paths_r  	l1_ratio_emptyr   r   r   r%  r   unravel_indexargmaxr   meanr   rA   rB   rC   rH   ranger   r5  itemsr   r   r   r   values)0r   r   r]   rK   r   r#  r&  r   label_encoderclasses_only_pos_if_binaryri   r   r$  foldsr   r2  fold_coefs_r@   r   r   
scores_sum
best_indexr  rL  	coef_initr   r  n_foldsn_csn_l1_ratiosbest_indices_Cbest_indices_l1cls
coefs_pathr   n_dofnewpaths	newscoresnewniterr;  rF   r<  r5  rJ   r6  r5   r7  r4   s0   ````                                   @@@@@@@@@r7   r   zLogisticRegressionCV.fit  s   6 	&$...dnc** 	't~/G/GIM+ 	 	 	 	 I<<''~%- "   vbj++q011 'Y5F
9--233 '&lGMC 	 	 	 %//M$DN,C $ $ <@>;R$ $ $ 
 
 
 %)!!$($>!t{GTY??l""!y>>Q&&   %.     ' !24=>   #JJ$)E)E88>w  
  "V

&
* &.J J
 
 
1 WQZ
$Q'''( %**1-- 6C5KK"T]&&	N	q==/=+/ / /   _$$'4888<<>>OO"O 	L+  , 	 MM "GGM%*___M"#(v#6#6#6M (>K$*?; dgqT222XRXaCCm&<&BCCDDlD)) 	B))++,,DM0B0BBBM#}M M7C7H7H7J7JM M  !oo% C Z''/+	  L  DM< @ @AAL 	HI)CABB)G&122	 ;/))FF FWhdk4<PVWWW X
 X
 X
 X
 X
 X
 X
 X
 X
 X
 X
 X
 X
 X
0  %1X
 X
 X
 
 
B ,/+<(Ra5 	I*c%jj#j//3tx=="M K +k1a88CKK*c%jj#j//3tx==)UWX K +k9iHHK*Ws5zz3z??CMM&RSS{7Aq11)<FSZZZ#dh--$PQQVQ**95)Q1!566C :FCCDD %?!M!MNN&&Xy*566
(9-- 8;<: E	,++J)")J*?*?AQRRJ*Q-(BGNN2":a=1IN!!),,, OGK1110Dz0D1110D0D$EANNN		GK1110Dz0D1110D0D$EANNN	 0 4"0H)At|a/00!.! /+"#  GAq!& !AA
 *0&GT;^^GR00F9V!444L+L4:MNNL\ 233L GWWWWWU3u::EVEVWWW  
 G    !&s5zz!2!2      :l33L)!!!Q$/NGNN2748N#;<<===,&&".qqq!t"4%%bgj.I&J&JKKKK%%d+++ 		+./fkk111kzk>**q*~dTUTUTUg?VDJ! H121QuXX!B%"gdgy11DGWT^Y??DN111kzk>*DJ! +"#AAArE(*TW%%DN33*Z00 $(#4#:#:#<#< @ @Z)3AAAqqq!QQQJ)?!#&&"l0022 3 3
U$)!!!QQQ'NS!!<111aaa
3DL$ %	A%jjG8=DGAJT%7!8!88EDGAJ''DG~d4+<+C+C+E+E&F&FGGH*1-I |AH >>'//7D!UKKHH'//	7D!USSH%--gtQ??	#++GT1==<4''%(DNN%(DNN!$/22!&t~a'8!9!9>>'//7D+uUUHH'//!7D+u   H !#Hi K KD ;y&&AADL;x@@DLr9   c                    t          || d           |                                 }t                      rt          | dfd|i|}n4t	                      }t	          i           |_        |||j        j        d<    || ||fi |j        j        S )am  Score using the `scoring` option on the given test data and labels.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Test samples.

        y : array-like of shape (n_samples,)
            True labels for X.

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

        **score_params : dict
            Parameters to pass to the `score` method of the underlying scorer.

            .. versionadded:: 1.4

        Returns
        -------
        score : float
            Score of self.predict(X) w.r.t. y.
        r   rK   r.  )r!   _get_scorerr"   r#   r   r4  r   )r   r   r]   rK   r   r   r7  s          r7   r   zLogisticRegressionCV.scorei  s    0 	,g666""$$ 	L+  , 	 MM "GGM#(r???M (>K$*?;w
 
 "(	
 
 	
r9   c                 |   t          |                               |                               | j        t	                                          dd                                        |                                 t	                                          dd                              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   r-  )callercallee)rB  method_mappingr   )r4  rl  )r   add_self_requestaddr$  r    rg  )r   routers     r7   get_metadata_routingz)LogisticRegressionCV.get_metadata_routing  s      &&&d##S,22%2PP    S'')),GG44E'22	    	 r9   c                 2    | j         pd}t          |          S )zpGet the scorer based on the scoring method specified.
        The default scoring method is `accuracy`.
        accuracy)r   r   )r   r   s     r7   rg  z LogisticRegressionCV._get_scorer  s     ,,*'"""r9   c                 `    t                                                      }d|j        _        |S )NT)r  r  r  r  r  s     r7   r  z%LogisticRegressionCV.__sklearn_tags__  s'    ww''))!%r9   r   )r  r  r  r  r   r   r  r  parampopupdater   r   r   r   rC  r   callabler   r   r   r   rp  rg  r  r  r  s   @r7   r!  r!  S  s         D DL
 $Q&8&O#PDPPP0 * *""5))))!!8Haf===|L&ffZZ5I5I.J.JK-"
33'7'7'9'9#:#:;;XtL[
55566zz<.1122 '0

F88L8L1M1M%N	
 	
  $ $'%; %; %; %; %;N \555Q Q Q 65Qf-
 -
 -
 -
^  ># # #        r9   r!  )Ir  r   r   r   r   numpyr   scipyr   sklearn._loss.lossr   r   sklearn.baser   sklearn.linear_model._baser	   r
   r   sklearn.linear_model._glm.glmr   !sklearn.linear_model._linear_lossr   sklearn.linear_model._sagr   sklearn.metricsr   r   sklearn.model_selectionr   sklearn.preprocessingr   sklearn.svm._baser   sklearn.utilsr   r   r   r   r   sklearn.utils._param_validationr   r   r   sklearn.utils.extmathr   r   sklearn.utils.fixesr   sklearn.utils.metadata_routingr   r    r!   r"   r#   sklearn.utils.multiclassr$   sklearn.utils.optimizer%   r&   sklearn.utils.parallelr'   r(   sklearn.utils.validationr)   r*   r+   r,   r   r8   r   r   r   r!  r9  r9   r7   <module>r     s      " " " " " " " "           D D D D D D D D % % % % % %         
 ? > > > > > = = = = = = 0 0 0 0 0 0 8 8 8 8 8 8 8 8 , , , , , , . . . . . . , , , , , ,              I H H H H H H H H H 4 4 4 4 4 4 4 4 B B B B B B              B A A A A A E E E E E E E E 4 4 4 4 4 4 4 4            !  8 
		+n1 n1 n1 n1 n1dT/ T/ T/nq	 q	 q	 q	 q	. q	 q	 q	hn n n n n-/Dm n n n n nr9   