
    KimS                       S r SSKrSSKrSSKJrJr  SSKrSSKJr  SSK	J
r
Jr  SSKJr  SSKJrJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"J#r#J$r$J%r%J&r&  SSK'J(r(J)r)J*r*  SSK+J,r,J-r-  SSK.J/r/  SSK0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:  SSK;J<r<J=r=  SSK>J?r?J@r@JArAJBrB  SrCS rDSSSSSSSSSS S!SSSSSS"S#.S$ jrES% rF " S& S'\\\5      rG " S( S)\G\\5      rHg)*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                     U S;  a  US;  a  [        SU  SU S35      eU S:w  a  U(       a  [        SU  SU 35      eUS:X  a  U S	:w  a  [        S
U  S35      eU S:X  a  Uc  [        S5      eU $ )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      `/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/sklearn/linear_model/_logistic.py_check_solverr8   ?   s    **wl/JfXH	 R 
 	
 76(*NtfUVV,6V#3I&QR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                   [        U[        R                  5      (       a  [        R                  " SSU5      n[        XU5      nU(       a3  [        U S[        R                  US;  S9n [        USSS9n[        X5        Uc  U
b  [        UX R                  S	S
9nU R                  u  nn[        U5      nUS:H  nUS:X  a  U(       d  [        S5      e[        U5      n[        5       R!                  U5      nU
b"  [#        XUUS9nUUUR%                  U5         -  nU(       ao  [        R&                  " U[)        U5      -   U R                  S9nXS   :H  n[        R*                  " UR                  U R                  S9nUS:X  a  SUU) '   OhSUU) '   OaUR%                  U5      R-                  U R                  SS9n[        R&                  " UR.                  U[)        U5      -   4SU R                  S9nUS;   a  Uc  UO[        R0                  " U5      nU	GbB  U(       a  U	R2                  S:X  a&  U	R                  S   U[)        U5      -   :X  a  U	USS& GOU	R2                  S:X  a;  U	R                  S   S:X  a(  U	R                  S   U[)        U5      -   :X  a	  U	S   USS& OSU	R                   SUR                   SUR                  S    S3n[        U5      eU	R2                  S:X  aK  U	R                  S   U:X  a8  U	R                  S   U[)        U5      -   :X  a  U	USS2SU	R                  S   24'   O'SU	R                   SUR                   3n[        U5      eU(       ai  Wn [5        [7        5       US9n!US:X  a  U!R8                  n"O*US:X  a$  U!R:                  n"U!R<                  n#U!R>                  n$S[        R@                  " USS 90n%O}[5        [C        UR.                  S!9US9n!Wn US;   a  URE                  SS"9nUS:X  a  U!R8                  n"O*US:X  a$  U!R:                  n"U!R<                  n#U!R>                  n$SURF                  0n%[I        5       n&[        R&                  " [        U5      [        RJ                  S9n'[M        U5       GH  u  n(n)US:X  a  S#U)W-  -  n*/ S$Q[        RN                  " [        RP                  " / S%Q5      U5         n+[R        RT                  " W"US&S	U U UU*U4US'US([        RV                  " [X        5      RZ                  -  S).[]        S*U+5      ES+9n,[_        UU,U[`        S,9n-U,Rb                  U,Rd                  n!nGO]US:X  a$  S#U)W-  -  n*U U UU*U4n.[g        W$W"W#UU.UUUS-9u  nn-GO3US.:X  a5  S#U)W-  -  n*[i        UU!U*UUUUS/9n/U/Rk                  U U US09nU/Rl                  n-OUS:X  ah  [o        U U U)UUSUUUUUUUS19u  n0n1n-U(       a'  [        Rp                  " U0RE                  5       U1/5      nOU0RE                  5       nU-Rs                  5       n-OUS2;   as  U(       a  S3n!OU R-                  U R                  SS9n S4n!US5:X  a  Sn2S#U)-  n3O!US6:X  a  S#U)-  n2Sn3OS#U)-  SU-
  -  n2S#U)-  U-  n3[u        U U UU!U2U3UUUUSUU%US7:H  S89u  nn-n%OS9U S:3n[        U5      eU(       a   U&Rw                  URy                  5       5        O@US;   a  [        Rz                  " UUS;4SS"9n4OUn4U&Rw                  U4Ry                  5       5        U-U'U('   GM     [        RP                  " U&5      [        RP                  " U5      U'4$ )<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   sl   F "g&&''[[Q#6D1F ** &.J J	
 U$7% L$<,]AWWSWXGGIzGIQIY&
 	
 &l3L			G	$B,Qm
 	r||A77XXj3}#55QWWEAJqww/[ E4%L E4%L
 ,,q/((u(=XX\\:M(::;3agg
 :: ,39NyyA~$**Q-:M@R3R"R1		QJJqMQ&JJqMZ#m2D%DDQ1 7tzzlBSxxj!Q8  !o% 		QJJqMY.JJqMZ#m2D%DD)-1o

1o%& 7tzzlBSxxj"  !o%&(
 W%%D{"99D==D00D "..!"<=)GLLA'
 >>
 $BW%%D{"99D==D00D "$$FEXXc"gRXX.F"1W!QZ0O* 6@F ''!K'%!4!44	
 96JG ."B	H yy'++B{"!QZ0Ov}oyID% 	LB ((!QZ0O&  /!#C Q&FB}}H{"*8!++'E:x ^^U[[]J$?@[[]  }}H&qwwU;$$QwDaqQ\2a8++56),(B.&xz+ 
 S/!LL#BB::b9b/ELL)q	A D 88E?BHHRL&00r9   c          	      r   X   nX   nX   nX   nSu  nnUb  [        UU 5      nUU   nUU   n[        UU40 SU_SU_SU_SU_SU_SU_S	U
_S
U	_SU_SU_SU_SU_SU_SS_SU_SU_6u  nnn[        US9nUUl        [	        5       n[        U5      nU H  nU(       a  USSS24   Ul        US   Ul        OUUl        SUl        Uc"  UR                  UR                  UUUS95        MV  U=(       d    0 n[        U UUS9nUR                  U" UUU40 UD65        M     UU[        R                  " U5      U4$ )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     s   n hGWFhGWF"Hg ,]A> '% 2  	
  $   "     , "  !" (#$ %E2v* !/G GVF!Gc3B3hKGM!"7GGM!$G?MM'--g-NO'-2L/!LRVWL MM''66J\JK! " "bhhv&..r9   c                   j  ^  \ rS rSr% Sr\" 1 Sk5      S\" \" S15      5      /\" \SSSS9/\" \SS	S
S9S/S/\" \SSSS9/S/\" \SSSS9/\	\" S15      S/S/\" 1 Sk5      /\" \
SSSS9/S/S/S\
/S.r\	\S'    S#SSSSSS	SSSSSSSS.S jjr\" SS9S$S j5       rU 4S jrS  rU 4S! jrS"rU =r$ )%r   i  av.  
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                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        g Nr   )selfr5   r   rL   r6   rC   rA   rG   rF   rH   r4   rB   rD   r   r   s                  r7   __init__LogisticRegression.__init__  sN    $  	*!2(( $r9   prefer_skip_nested_validationc                    U R                   S:X  a~  U R                  S:X  d  U R                  c+  SnU R                  c  [        R                  " S[        5        OU R                  S:X  a  SnOSnU R
                  [        R                  :X  a  SnO'U R                   n[        R                  " S	[        5        [        U R                  X@R                  5      nUS:w  aL  U R                  b?  SU R                  s=:  a  S:  a(  O  O%[        R                  " S
R                  U5      5        U R                   S:X  a  U R                  S:w  d   U R                   S:X  aA  U R                  S:w  a1  [        R                  " SU R                    SU R                   S35        US:X  a  U R                  c  [        S5      eUc9  U R
                  S:w  a  [        R                  " S5        [        R                  nSnOU R
                  nSU R                   S3nU R                  b  [        R                  " U[        S9  US:X  a  [        R                  nO [        R                  [        R                  /n[!        U UUSUSUS;  S9u  pUR"                  S   n	[%        U5        [        R&                  " U5      U l        [+        U R(                  5      n
U
S:H  nUS:X  a  U(       d  [        S5      e[        R,                  " U5      S:  a  [        S5      e[/        UUU R
                  U R0                  U R2                  U R4                  UU R                  U R6                  U R8                  U R:                  U R<                  US9u  U l        U l         U l!        U $ US;   a  [E        US S!9R-                  5       nOSnU
S:  a  [        S"U R(                  S   -  5      eU RF                  (       a  [I        U S#S5      nOSnUbE  U R0                  (       a4  [        RJ                  " XR@                  SS2[        RL                  4   SS$9nSn[O        UU40 S%U R(                  _S&U/_S'U R                  _S(U R0                  _S)U R:                  _S*U R6                  _S+U_S,U R8                  _S-U R4                  _S.S/_S0U R<                  _S1U_S2U_S3U_S4U_S5U_6u  nnn[        RP                  " U[        RR                  S69U l!        US   U l        U R0                  (       am  U(       a1  U R>                  S7S U l         U R>                  SS7 SSS24   U l        U $ U R>                  SS2S74   U l         U R>                  SS2SS724   U l         U $ U(       a>  [        RT                  " SURV                  S69U l         U R>                  SSS24   U l        U $ [        RT                  " XRV                  S69U l         U $ )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.

    .. 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   LogisticRegression.fit>  sz   < <<<'}}!T]]%:==(MMT & !#&vvllGMM8 
 t{{GYY?l"MM%!dmm*?a*?MM%vg
 LLD T]]a%7LLD T]]a%7MM/~ > MM? +!"
 l"t}}'<UVV?vv}T BGB$$(KK=0OQ 	 ;;"MM#6WZZFjj"**-F &.J J
 WWQZ
$Q'		!&	N	[  .  vvay4 5 
 9G""&&!!		!!+95DJ K_$'48<<>O"Oq=#}}Q/0  ??%dGT:O"O&4+=+= iiBJJ!?aO 	4
 MM
 t	

 ]]
 ,,
 
 LL
 
 ]]
 **
 
 **
 !
 
  ,!
" (#
$  %
q&* zz&91X
"&**RS/!ZZ_T1W5
  #'**QU"3!ZZ3B3/
  "$((1AGG"<!ZZa0
  #%((9GG"Dr9   c                    > [        U 5        U R                  R                  S:*  nU(       a  [        TU ]  U5      $ U R                  U5      n[        USS9$ )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_proba LogisticRegression.predict_proba  sQ    , 	MM&&!+	7,Q//003K;U33r9   c                 L    [         R                  " U R                  U5      5      $ )a   
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_proba$LogisticRegression.predict_log_proba5  s    & vvd((+,,r9   c                    > [         TU ]  5       nSUR                  l        U R                  S:X  a  SUR
                  l        U$ )NTr.   F)r
  __sklearn_tags__
input_tagssparser4   classifier_tagsmulti_classr   tagsr  s     r7   r  #LogisticRegression.__sklearn_tags__J  s;    w')!%;;+%/4D  ,r9   )r   rF   r   r   r6   rA   r   rG   rL   rB   r   r   r5   rH   r4   rC   rD   r   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   dictr   r   __annotations__r   r   r   r  r  r  __static_attributes____classcell__r  s   @r7   r   r     sB   bL	 12:|n-.

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

 h4?@; k"-$D 6  !B 5U 6Un4>-* r9   r   c                     ^  \ rS rSr% Sr0 \R                  Er\\S'   S H  r	\R                  \	5        M     \R                  \" \SSSS9S	/S	S\" \" S
15      5      /S/\" \" \" 5       5      5      \S/S/\" 1 Sk5      \" \" S15      5      /S\" \" S
15      5      /S.5        SS
SSSSSSSSSSSSSSS
S.S jr\" SS9S!S j5       rS!S jrS rS rU 4S jrS rU =r$ )"LogisticRegressionCViS  a6  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                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        UU l        g 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   LogisticRegressionCV.__init__  sb    * "*	 (
!2(%:"r9   r   c                 R  ^ ^^^^*^+^,^-^.^/^0 [        UT S5        [        T R                  [        5      (       a.  T R                  S:X  a  Sn[        R
                  " S[        5        OT R                  nT R                  S:X  a  T R                  c  [        R
                  " S[        5        [        R                  " [        R                  " U5      S:H  5      (       d  Uc  Sm.O_[        R                  " [        R                  " U5      S	:H  5      (       a  S
m.O*Sm.O'T R                  m.[        R
                  " S[        5        T R                  S:X  aM  [        R
                  " ST R                  R                   ST R                  R                   S3[        5        SnOT R                  n[        T R                  T.T R                   5      m0T.S:X  a:  Ub&  [#        U5      S:X  d  [%        S U 5       5      (       a  ['        SU-  5      eUm+OAUb5  T R                  S:w  a%  [        R
                  " SR)                  T.5      5        Uc  S/m+OUm+[+        T TTS[        R,                  ST0S;  S9u  mmTR.                  S	   n[1        T5        T R2                  m*[5        5       R7                  T5      nUR8                  =n	T l        [#        T R8                  5      n
U
S:H  nU
S:  a  ['        ST R8                  S    S35      eT0S;   a  [;        TSS9R=                  5       m,OSm,[?        5       (       a  [A        T S4ST0UD6m/OB[C        5       m/[C        0 S9T/l"        [C        US9T/l#        Tb  TT/RF                  RH                  S'   [K        T RL                  TSS 9n[O        URP                  " TT40 T/RD                  RP                  D65      n[        T*[R        5      (       a\  [U        T*RW                  5       5      [U        T R8                  5      ::  d+  S!T R8                   S"T*RW                  5        3n['        U5      eO;T*S#:X  a5  [Y        T*T R8                  TTS$9m*[S        [[        T R8                  T*5      5      m*U(       a  S	n
U	S	S n	[]        [^        5      m-T R                  S;   a  S%nOS&n[a        T Rb                  T Rd                  US'9" UU*U+U,U-U.U/UU U0U4S( jU 5       5      n[[        U6 u  nnnnUS   T l3        U(       a\  [        Rh                  " U[#        U5      [#        T+5      [#        T Rf                  5      S)45      n[        Rj                  " US	S5      S*   nOY[        Rh                  " U[#        U5      [#        T+5      [#        T Rf                  5      U
S)45      n[        Rl                  " US+S,5      n[        Rh                  " U[#        U5      [#        T+5      [#        T Rf                  5      45      n[        Rj                  " US	S5      S*   T l7        [        Rh                  " U[#        U5      [#        T+5      [#        T Rf                  5      45      n[        Rj                  " US	S5      S*   n[        Rp                  " UU
S	S	S	45      n[S        [[        U	U5      5      T l9        [S        [[        U	U5      5      T l:        [O        5       T l;        [O        5       T l<        [        Rz                  " X45      T l>        [        R~                  " U
5      T l@        T Rr                  U	S      nT R                  (       GaT  UR                  SS-9n[        R                  " [        R                  " U5      UR.                  5      nT Rf                  US      nT Rv                  R                  U5        T+US	      nT Rx                  R                  U5        U(       a$  [        R                  " USSS2/UQSS2P7   SS-9nO%[        R                  " USS2SS2/UQSS2P7   S	S-9n[        TT4T R8                  U/T0T R                  UT R                  T R                  T.T*[=        ST Rd                  S	-
  5      T R                  S.T,TUS/.6u  n  nUS   nGOUR.                  u  nnnURi                  US)5      n[        R                  " US	S-9n[        R                  " UUU45      n[O        [[        U6 5      nU(       aH  [        R                  " [        [#        U5      5       V s/ s H  n USU /UU    QSS2P7   PM     sn SS-9nOP[        R                  " [        [#        U5      5       V s/ s H  n USS2U UU    S   UU    S	   SS24   PM     sn SS-9n[        R                  " U5      nUSS2S4   n!T Rv                  R                  [        R                  " T Rf                  U!   5      5        T.S:X  a<  USS2S	4   n"T Rx                  R                  [        R                  " T+U"   5      5        OT Rx                  R                  S5        U(       ae  UR                  S:X  a  USS2SU24   OUSU SSS24   T l>        T R                  (       a'  UR                  S:X  a  US0   OUS)   T R                  S'   O{[        Rp                  " T Rv                  U
5      T l;        [        Rp                  " T Rx                  U
5      T l<        USS2SU24   T l>        T R                  (       a  USS2S)4   T l@        [        R                  " T Rv                  5      T l;        [        R                  " T Rx                  5      T l<        [        R                  " T+5      T lN        Uc  T Rt                  R                  5        H"  u  n#n$U$SS2SS2SSS24   T Rt                  U#'   M$     T Rr                  R                  5        H  u  n#n%U%SS2SS2S4   T Rr                  U#'   M!     T Rn                  SS2SS2SS2S4   T l7        U(       Gd  [#        U5      nT Rf                  R                  nTR.                  S	   [        T R                  5      -   n&[        T Rv                  S   5      T l;        [        R                  " [O        T Rt                  R                  5       5      5      n'T Rr                  U	S      n(T Rn                  S   n)Ucw  U
S::  a  U'Ri                  S	UUS	U&5      n'OU'Ri                  U
UUS	U&5      n'U(Ri                  UUS	5      n(U)Ri                  UUS	5      n)T R                  S
:X  a  S1T l<        OkS2T l<        Oc[#        T R                  5      n[        T Rx                  S   5      T l<        U
S::  a  U'Ri                  S	UUUU&5      n'OU'Ri                  U
UUUU&5      n'[        Rl                  " U'S+S35      T l:        [        Rl                  " U(S4S55      T l9        [        Rl                  " U)S4S55      T l7        T $ s  sn f s  sn f )6a  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      #    U  H<  n[        U[        R                  5      (       + =(       d    US :  =(       d    US:  v   M>     g7f)r   r?   N)r   r   Number).0rL   s     r7   	<genexpr>+LogisticRegressionCV.fit.<locals>.<genexpr>4  sF       %.	 'x@@ (#a<(#a<( %.s   AA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     >#    U  H  u  pT  H  nT" TTUU40 S TR                   _STR                  _STR                  _ST	_STR                  _ST_STR                  _STR
                  _STR                  _S	T_S
TR                  _STR                  _STR                  _ST_ST_SU_ST
R                  R                  _6v   M     M     g7f)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   )r3  r   r   rL   r   rF   
l1_ratios_rJ   	path_funcr5   routed_paramsrK   r   r4   r]   s       r7   r4  r5    s#     X
0  %&1 	
  77 #00   YY  HH   *   #'"8"8!" "..#$ !0%& ,'( ")* +1177+0 '1.  %s   CC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   )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   splitterr=  r   r   r+  r   r6  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   r>  itemsr   r   r   r   values)1r   r   r]   rK   r   r*  r-  r   label_encoderclasses_only_pos_if_binaryri   r   r+  foldsr   r;  fold_coefs_coefs_pathsr@   r   r   
scores_sum
best_indexr  rN  	coef_initr   r  n_foldsn_csn_l1_ratiosbest_indicesr   best_indices_Cbest_indices_l1cls
coefs_pathr   n_dofnewpaths	newscoresnewniterrF   r>  rJ   r?  r5   r@  r4   s1   ````                                      @@@@@@@r7   r   LogisticRegressionCV.fit  s_   6 	&$.dnnc**t~~/GIMM+ 	 I<<<'~~%- " vvbjj+q011Y5F

9-233&llGMMC 	 %%/MM+DNN,C,C+D E; <@>>;R;R:S T$$ 
 %)!$($>$>!t{{GTYY?l"!y>Q&  %.   !24=>  #J$)E88>w
  "V
&
** &.J J
1 WWQZ
$Q'(( %**1- 6C5K5KK"T]&	N	q===+,A/  _$'48<<>O"O+ , 	M "GM%*_M"#(v#6M (>K$$**?; dggqT2RXXaCm&<&<&B&BCDlD))))+,DMM0BB#}}oY|7H7H7J6KM  !o% C Z'/+	L  DMM< @ALI)CAB)G&12	 ;;/)F Fdkk4<<PVW X
 X
0  %1X
 
B ,/+<(Ra5**c%j#j/3txx="MK ++k1a8CK**c%j#j/3txx=)UWXK ++k9iHK**Ws5z3z?CM&RS{{7Aq1)<FSZZ#dhh-$PQVQ*95)Q1!56C :FCD %?!MN&XXy56
((9- 8;<:::+J))"))J*?AQAQRJ*Q-(BGGNN2":a=1INN!!),GGK10Dz0D10D$EAN	GGK10Dz0D10D$EAN	 0 4"00HH)At||a/0!..! /+"#GAq!& !A
 *0&GT;^^GR0F99V!4L++L4:MNL\ 23LGGEJ3u:EVWEV[A!:Q!:!:;EVW
 GG "'s5z!2!2A $Aq,q/!*<l1oa>PRS$ST!2  ::l3L)!Q$/NGGNN277488N#;<=,&".q!t"4%%bggj.I&JK%%d+./ffk1kzk>*q*~dTUg?VDJ!!121QuX!B%"ggdggy1DGWWT^^Y?DN1kzk>*DJ!!"#ArE(**TWW%DNN3**Z0 $(#4#4#:#:#<Z)3Aq!QJ)?!!#& $="ll002
U$)!Q'NS! 3<<1a
3DL$%jG88==DGGAJT%7%7!88EDGGAJ'DG~~d4+<+<+C+C+E&FGH*1-I ||AH >'//7D!UKH'//	7D!USH%--gtQ?	#++GT1=<<4'%(DN%(DN!$//2!&t~~a'8!9>'//7D+uUH'//!7D+u H !#Hi KD ;;y&&ADL;;x@DLi X
s   x$x$c                    [        X@S5        U R                  5       n[        5       (       a  [        U S4SU0UD6nO3[	        5       n[	        0 S9Ul        Ub  X6R
                  R                  S'   U" U UU40 UR
                  R                  D6$ )a  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   r7  )r!   _get_scorerr"   r#   r   r=  r   )r   r   r]   rK   r   r   r@  s          r7   r   LogisticRegressionCV.scorei  s    0 	,g6""$+ , 	M "GM#(r?M (>K$$**?;
 ""((	
 	
r9   c                    [        U S9R                  U 5      R                  U R                  [	        5       R                  SSS9S9R                  U R                  5       [	        5       R                  SSS9R                  SSS9S9nU$ )a"  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   r6  )callercallee)rD  method_mappingr   )r=  rr  )r   add_self_requestaddr+  r    rl  )r   routers     r7   get_metadata_routing)LogisticRegressionCV.get_metadata_routing  s      &d#S,22%2P   S''),GG4E'2	   	 r9   c                 B    U R                   =(       d    Sn[        U5      $ )z`Get the scorer based on the scoring method specified.
The default scoring method is `accuracy`.
accuracy)r   r   )r   r   s     r7   rl   LogisticRegressionCV._get_scorer  s     ,,,*'""r9   c                 F   > [         TU ]  5       nSUR                  l        U$ )NT)r
  r  r  r  r  s     r7   r  %LogisticRegressionCV.__sklearn_tags__  s!    w')!%r9   )r  r@   rH  rF   r   r   rM  r+  r6   rA   r   rG   rN  r*  r>  rB   r   r   r5   rH   r,  rL  r   r4   rC   r-  rD   r   )r  r  r  r   r!  r   r   r"  r#  parampopupdater   r   r   r   rE  r   callabler   r   r   r   rv  rl  r  r$  r%  r&  s   @r7   r(  r(  S  s@   DL
 $Q&8&O&O#PDP0""5) 1 !!Haf=|L&fZ5I.JK-"3'7'9#:;XtL[56z<.12 '0
F88L1M%N	
$ $'%;N 5Q 6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   r7   <module>r     s      "   D % 
 ? = 0 8 , . ,  I H 4 B  B E 4  !8 
		+n1dT/nq	. q	hn-/Dm nr9   