`L ibbdZddlZddlZddlmZmZddlZddlmZddl m Z ddl m Z ddl mZmZdd lmZdd lmZdd lmZdd lmZmZdd lmZddlmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6m7Z7ddl8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@ddlAmBZBddlCmDZDddlEmFZFdZGdZHdZI d%dZJd ZKGd!d"e?e@e>ZLGd#d$eLe?e>ZMy)&z Logistic Regression N)IntegralReal)effective_n_jobs)optimize)get_scorer_names)HalfBinomialLossHalfMultinomialLoss) _fit_context) get_scorer)check_cv)LabelBinarizer LabelEncoder)_fit_liblinear)Bunch check_arraycheck_consistent_lengthcheck_random_statecompute_class_weight)HiddenInterval StrOptions) row_normssoftmax)"_get_additional_lbfgs_options_dict)MetadataRouter MethodMapping_raise_for_params_routing_enabledprocess_routing)check_classification_targets)_check_optimize_result _newton_cg)Paralleldelayed)_check_method_params_check_sample_weightcheck_is_fitted validate_data) BaseEstimatorLinearClassifierMixinSparseCoefMixin)NewtonCholeskySolver)LinearModelLoss) sag_solverzPlease also refer to the documentation for alternative solver options: https://scikit-learn.org/stable/modules/linear_model.html#logistic-regressionc|dvr|dvrtd|d|d|dk7r|rtd|d||dk(r|d k7rtd |d |dk(r | td |S) N) liblinearsaga)l2NzSolver z+ supports only 'l2' or None penalties, got z penalty.r2z$ supports only dual=False, got dual= elasticnetr3z;Only 'saga' solver supports elasticnet penalty, got solver=.z6penalty=None is not supported for the liblinear solver ValueError)solverpenaltyduals d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/linear_model/_logistic.py _check_solverr=>s **wl/JfXH R   76(*NtfUVV,6V#3I&QR S  QRR Mc`|dk(r|dvrd}n |dkDrd}nd}|dk(r|dvrtd|z|S)zComputes the multi class type, either "multinomial" or "ovr". For `n_classes` > 2 and a solver that supports it, returns "multinomial". For all other cases, in particular binary classification, return "ovr". auto)r2ovrr multinomialz1Solver %s does not support a multinomial backend.r7) multi_classr9 n_classess r<_check_multi_classrERsP f ^ #K ]'KKm#.(@LvUVV r>c"t|tjrtjdd|}t || | }|r9t |dtj|dv}t |dd}t|||j\}}tj|}t|}t||t|}|$|d k7r|jd kDr td |d }|| t!|||j"d }t%}t| t&s|d k(r(| &t)| |||}|||j+|z}|dk(rtj,|t/|z|j"}||k(}tj0|j|j"}|dk(rtj2dd g}d||<ntj2dd g}d||<| dk(rt)| |||}|||j+|z}n|dvr7t%}|j+|j5|j"d}nGt7}|j+|}|jd d k(rtj8d |z |g}tj,|j|t/|zfd|j"}|dvr||ntj:|} | |dk(rO| j||jfvr%td| j||jfz| |d| jn|j}!|!d k(rd }!| jd|!k7s| jd ||d zfvrEtd| jd| jd |j||j|d zfz|!d k(r.| |dd| jd f<| |d d| jd f<n| |ddd| jd f<|d k(r|dvr|j=d}t?tA|j |!}"}#|d"k(r |"jB}$n)|d#k(r$|"jD}$|"jF}%|"jH}&d$|jJi}'n}#|d"k(r"t?tM|!}"|"jB}$nY|d#k(r:t?tM|!}"|"jD}$|"jF}%|"jH}&n|d%k(rt?tM|!}"d$tjN|d &i}'tQ}(tj,t|tjR})tU|D]\}*}+|d"k(rd'|+ zz },gd(tjVtj2gd)|}-tYjZ$|d*d ||#||,|f|d+|d,tj\t^j`zd-tcd.|-/}.te||.|tf0}/|.jh|.jj}"}n|d#k(r'd'|+ zz },||#||,|f}0tm&$%||0|||1\}}/nZ|d%k(r`. 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. pos_class : int, default=None The class with respect to which we perform a one-vs-all fit. If None, then it is assumed that the given problem is binary. 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_features,), 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. multi_class : {'ovr', 'multinomial', 'auto'}, default='auto' If the option chosen is 'ovr', then a binary problem is fit for each label. For 'multinomial' the loss minimised is the multinomial loss fit across the entire probability distribution, *even when the data is binary*. 'multinomial' is unavailable when solver='liblinear'. 'auto' selects 'ovr' if the data is binary, or if solver='liblinear', and otherwise selects 'multinomial'. .. versionadded:: 0.18 Stochastic Average Gradient descent solver for 'multinomial' case. .. versionchanged:: 0.22 Default changed from 'ovr' to 'auto' in 0.22. random_state : int, RandomState instance, default=None Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the data. See :term:`Glossary ` 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_features) or (n_cs, n_features + 1) List of coefficients for the Logistic Regression model. If fit_intercept is set to True then the second dimension will be n_features + 1, where the last item represents the intercept. For ``multiclass='multinomial'``, the shape is (n_classes, n_cs, n_features) or (n_classes, n_cs, n_features + 1). Cs : ndarray Grid of Cs used for cross-validation. n_iter : array of shape (n_cs,) Actual number of iteration for each 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. csrr2sagr3) accept_sparsedtypeaccept_large_sparseFN) ensure_2drMrBrz&To fit OvR, use the pos_class argumentr*T)rMcopyclassesy sample_weightrArMr2rbalanced)rKr3lbfgs newton-cgnewton-choleskyrPF)orderrMrZr[r\z;Initialization coef is of shape %d, expected shape %d or %dzMInitialization coef is of shape (%d, %d), expected shape (%d, %d) or (%d, %d))r_)rD) base_loss fit_interceptrZr[coefr\axis?)rV2r*de)rr*rzL-BFGS-Brg@)maxitermaxlsgtolftoliprint)methodjacargsoptions)extra_warning_msg) grad_hessfuncgradx0rsrltolverbose)rc linear_lossl2_reg_strengthrzmax_iter n_threadsr{)XrSrTUsing the 'liblinear' solver for multiclass classification is deprecated. An error will be raised in 1.8. Either use another solver which supports the multinomial loss or wrap the estimator in a OneVsRestClassifier to keep applying a one-versus-rest scheme.rTrKr3logl1r4r3)is_sagazRsolver must be one of {'liblinear', 'lbfgs', 'newton-cg', 'sag'}, got '%s' instead)F isinstancenumbersrnplogspacer=rfloat64rshapeuniquerrElensizer8r'rMrdictr fit_transformzerosintonesarrayastyperhstacksumravelr/r loss_gradientlossgradientgradient_hessian_productTr expand_dimslistint32 enumerate searchsortedrminimizefinfofloatepsrr" _LOGISTIC_SOLVER_CONVERGENCE_MSGxfunr#r.solve iterationwarningswarn FutureWarningr concatenateitemr0maxreshapenewaxisappendrP)7rrS pos_classCsrbr~rzr{r9rc class_weightr;r:intercept_scalingrC random_state check_inputmax_squared_sumrTl1_ratior n_samples n_featuresrRle class_weight_w0masky_bin mask_classesY_multilbinsw_sumrDrtargetrwrxhesswarm_start_sagcoefsn_iteriCr}rpopt_resn_iter_irssolcoef_ intercept_alphabetamulti_w0s7 r<_logistic_regression_pathrds \"g&&' [[Q # 67D 1F  ** &.J J   U$ 71%GGIziilG%l3L$[&#g,GK[M9 < > $B)GLLA'  W %%D { "99D==D00D "$$ W "*,MD%%D { ""*,MD99D==D00D ( ("*,MD!"..!"<= FE XXc"gRXX .F" N1 W !QZ0O* 6@F''!K'%!4!44  96J  G."B H yy'++B { "!QZ0Ov}oyID%  LB( (!QZ0O& /!#CQ& FB}}H { "7|a  " !+   ^^U[[]J$?@[[] }}H  &m+qwwU;$$QwDaqQ\2a8++56), (B.$8:@A  - 'Aw||,IBB::b9b/EA~#A;rzz1}5 LL ) LL #q ]N` 88E?BHHRL& 00r>c||}||}||}||}d\}}|t||}||}||}t||fid|d|d|d| d|d| d |d |d | d | d |d| d|d|ddd|d|\}}}t| |}|dk(rtjddg|_n.|dk(rtj ||_ntd|z|:||k(}tj|jtj}d||<t} t|}|D]}!|dk(r|!tjddf}!|r|!ddddf|_|!dddf|_n|!|_d|_|$| j!|j#|||t|xsi}t%|||}| j!||||fi|||tj| |fS) aComputes 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. pos_class : int The class with respect to which we perform a one-vs-all fit. If None, then it is assumed that the given problem is binary. 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 ` 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. multi_class : {'auto', 'ovr', 'multinomial'} If the option chosen is 'ovr', then a binary problem is fit for each label. For 'multinomial' the loss minimised is the multinomial loss fit across the entire probability distribution, *even when the data is binary*. 'multinomial' is unavailable when solver='liblinear'. random_state : int, RandomState instance Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the data. See :term:`Glossary ` 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_features) or (n_cs, n_features + 1) List of coefficients for the Logistic Regression model. If fit_intercept is set to True then the second dimension will be n_features + 1, where the last item represents the intercept. Cs : ndarray 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 Cs. )NNNrrrbr9r~rrrCrzr{r;r:rrrFrrT)r9rCrArVr*rBz7multi_class should be either multinomial or ovr, got %drUrWrXr)rparamsindices)r'rLogisticRegressionrrclasses_rr8rrrrr rrrrscorer&)"rrStraintestrrscoringrbr~rzrr{r9r:r;rrCrrrTr score_paramsX_trainX_testy_trainy_testsw_trainsw_testrrlog_regrscoresws" r<_log_reg_scoring_pathrYsxhG tWFhG tWF"Hg ,]A>  '%1   $   "  , "!"#$(%&'E2v,!KHGe88RG,  %99W- E S  "RZZ8u VF!G L % "**a- A a"fIGM!"1b5G GM!$G  ? MM'--g-N O'-2L/!LRVWL MM''66J\J KL "bhhv& ..r>ceZdZUdZehddgdgeedddgeedddgdgeeddd geed hdgd gehd geedddgd gdgdegeeddddgehde edhgdZ ee d< d!ddddddddddddddddZ e dd"dZfdZdZfd ZxZS)#rah4 Logistic Regression (aka logit, MaxEnt) classifier. This class implements regularized logistic regression using the 'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note that regularization is applied by default**. It can handle both dense and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit floats for optimal performance; any other input format will be converted (and copied). The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization with primal formulation, or no regularization. The 'liblinear' solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. The Elastic-Net regularization is only supported by the 'saga' solver. For :term:`multiclass` problems, all solvers but 'liblinear' optimize the (penalized) multinomial loss. 'liblinear' only handle binary classification but can be extended to handle multiclass by using :class:`~sklearn.multiclass.OneVsRestClassifier`. Read more in the :ref:`User Guide `. 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) dual : bool, default=False Dual (constrained) or primal (regularized, see also :ref:`this equation `) 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. C : float, default=1.0 Inverse of regularization strength; must be a positive float. Like in support vector machines, smaller values specify stronger regularization. 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 ` 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: - For small datasets, 'liblinear' is a good choice, whereas 'sag' and 'saga' are faster for large ones; - For :term:`multiclass` problems, all solvers except 'liblinear' minimize the full multinomial loss; - '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`. - '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. .. warning:: The choice of the algorithm depends on the penalty chosen and on (multinomial) multiclass support: ================= ============================== ====================== solver penalty multinomial multiclass ================= ============================== ====================== 'lbfgs' 'l2', None yes 'liblinear' 'l1', 'l2' no 'newton-cg' 'l2', None yes 'newton-cholesky' 'l2', None yes 'sag' 'l2', None yes 'saga' 'elasticnet', 'l1', 'l2', None 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 ` for more information regarding :class:`LogisticRegression` and more specifically the :ref:`Table ` 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. multi_class : {'auto', 'ovr', 'multinomial'}, default='auto' If the option chosen is 'ovr', then a binary problem is fit for each label. For 'multinomial' the loss minimised is the multinomial loss fit across the entire probability distribution, *even when the data is binary*. 'multinomial' is unavailable when solver='liblinear'. 'auto' selects 'ovr' if the data is binary, or if solver='liblinear', and otherwise selects 'multinomial'. .. versionadded:: 0.18 Stochastic Average Gradient descent solver for 'multinomial' case. .. versionchanged:: 0.22 Default changed from 'ovr' to 'auto' in 0.22. .. deprecated:: 1.5 ``multi_class`` was deprecated in version 1.5 and will be removed in 1.8. From then on, the recommended 'multinomial' will always be used for `n_classes >= 3`. Solvers that do not support 'multinomial' will raise an error. Use `sklearn.multiclass.OneVsRestClassifier(LogisticRegression())` if you still want to use OvR. 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 `. .. versionadded:: 0.17 *warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers. n_jobs : int, default=None Number of CPU cores used when parallelizing over classes if multi_class='ovr'". This parameter is ignored when the ``solver`` is set to 'liblinear' regardless of whether 'multi_class' is specified or not. ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See :term:`Glossary ` for more details. 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. 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. In particular, when `multi_class='multinomial'`, `coef_` corresponds to outcome 1 (True) and `-coef_` corresponds to outcome 0 (False). 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. In particular, when `multi_class='multinomial'`, `intercept_` corresponds to outcome 1 (True) and `-intercept_` corresponds to outcome 0 (False). 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 (n_classes,) or (1, ) Actual number of iterations for all classes. If binary or multinomial, it returns only 1 element. For liblinear solver, only the maximum number of iteration across all classes is given. .. 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 ` 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`. >rr4r5NbooleanrleftclosedrightneitherrYr>rKr3rZr2r[r\r{r*both>rAr@rB deprecated)r:r;rzrrbrrrr9r~r{ warm_startn_jobsrrC_parameter_constraintsF-C6?rfTrZrh)r;rzrrbrrrr9r~rCr{rrrc||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ ||_yN)r:r;rzrrbrrrr9r~rCr{rrr)selfr:r;rzrrbrrrr9r~rCr{rrrs r<__init__zLogisticRegression.__init__sr&  *!2((   & $   r>prefer_skip_nested_validationc  tjjjjdk7r:j.t j djjjdk(rj tdj7jdk7rt j dtj dnj jdk(rtj}n tjtjg}td |d d v \ttj _j$j$d k(r3t'j"dk(rt j dt(nUj$dvrt j dt(n,j$dk(rt j dt(ndt+t'j"dk(rt'j"dkDrt j dt(t-j.dk7r7t j djt-j.t1jj2j4j6jjj8j:j<j> \_ _!_"SdvrtGdjIndt'j"}j"}|dkrtd|dzt'j"dk(rd}|dd}jJrtMdd}nd}|Cj2r7tjN|jBddtjPfd }d k(rdg}|g}|dg|z}tStTdvrd!}nd"}d#vr)t'|dk(rt-j.dk(rdndtWj.j8|$ f d%tY||D} tY| \} } } tjZ| tj\&dddf_"j^d} d k(r| dd_ nQtjZ| _ j@ja|| tcj2z_ j2r4j@ddd'f_!j@dddd'f_ Stjd|_!S)(an 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. r5NzNl1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty={})z6l1_ratio must be specified when penalty is elasticnet.rfz>Setting penalty=None will ignore the C and l1_ratio parametersr4rZrIrrJrLrMr_rNrBr'multi_class' was deprecated in version 1.5 and will be removed in 1.8. From then on, binary problems will be fit as proper binary logistic regression models (as if multi_class='ovr' were set). Leave it to its default value to avoid this warning.rBr@'multi_class' was deprecated in version 1.5 and will be removed in 1.8. From then on, it will always use 'multinomial'. Leave it to its default value to avoid this warning.rAz'multi_class' was deprecated in version 1.5 and will be removed in 1.8. Use OneVsRestClassifier(LogisticRegression(..)) instead. Leave it to its default value to avoid this warning.r@r2rr*z]'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = {}.rrTsquaredeThis solver needs samples of at least 2 classes in the data, but the data contains only one class: %rrrrdthreads processesr`rr{preferc3( K|]\}} fid|dgd jd jd jd jd dd jd j d d d j d |d dd dyw)rrrrbrzr{r9rCr~rrFrrcr:rrTrN)rrbrzr{r~rr).0class_warm_start_coef_C_rrrCr path_funcr:rTrr9rSs r< z)LogisticRegression.fit..hsX ,)(+  ! 4      #00  HH    (  ".. " ".. &   ! "!0# $,% &$' X sBBrUrV)3r=r9r:r;rrrformatr8rrinfrfloat32r)r!rrrCrrrErrrrbrrr{r~rzrrrn_iter_rrrgetattrrrr%rr$zipasarrayrrrrr)rrrSrT_dtyperDrwarm_start_coefr  fold_coefs__rrrrrCrrr:r9s```` @@@@@@@r<fitzLogisticRegression.fits <t{{DLL$))D <<< 'DMM,E MM%vdll3  <<< 'DMM,AUV V << vv} TBGBllG W ZZFjj"**-F   &.J J 1 %Q' !  &&   } ,T]]1Cq1H MML    !8 8 MML     & MML  !K(fc$-->PQ [ 4==!A%  "   ,1 #V$4T[[$AB 9G""&&!!    !!+9 5DJK _ $'48<<>O"O & == q='{+  t}}  "I|H ??%dGT:O"O  &4+=+= iiBJJ!?aO - 'vH./O  "#fy0O56  _ $F F ? ?H " -2IIWhdkk4<,>(??DJ   "jjB/DOAssF+DJ !hhy1DO r>c\t||jdvxs:|jdvxr*|jjdkxs|jdk(}|rt ||S|j|}|jdk(rtj| |f}n|}t|dS)a Probability estimates. The returned estimates for all classes are ordered by the label of classes. For a multi_class problem, if multi_class is set to be "multinomial" the softmax function is used to find the predicted probability of each class. Else use a one-vs-rest approach, i.e. calculate the probability of each class assuming it to be positive using the logistic function and normalize these values across all the 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 probability of the sample for each class in the model, where classes are ordered as they are in ``self.classes_``. )rAr)r@rrr2r*Fr]) r(rCrrr9super_predict_proba_lrdecision_functionndimrc_r)rrrAdecision decision_2d __class__s r< predict_probaz LogisticRegression.predict_probas4 /1    6 6 H##q(FDKK;,F  7,Q/ /--a0H}}!!eeXIx$78 & ;U3 3r>cJtj|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_``. )rrr()rrs r<predict_log_probaz$LogisticRegression.predict_log_probas&vvd((+,,r>cFt|}d|j_|SNTr __sklearn_tags__ input_tagssparsertagsr's r<r.z#LogisticRegression.__sklearn_tags__!w')!% r>)r4r)__name__ __module__ __qualname____doc__rrrrrrr__annotations__rr rr(r*r. __classcell__r's@r<rr=sOhV 9:DA q$v67tQW5 6#&tQYGHz:,7>'( U  h4?@; k"dAq8$? 5 6 :|n- . '$D6!!   #!!F5n6n`*4X-*r>rcdeZdZUdZiej Zeed<dD]Zejeeje e ddddgd ge eeedgddgd ge hd gd d ddddddddddddddddddZedddZddZdZdZfdZxZS) LogisticRegressionCVa5Logistic Regression CV (aka logit, MaxEnt) classifier. See glossary entry for :term:`cross-validation estimator`. This class implements logistic regression using liblinear, newton-cg, sag or lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2 regularization with primal formulation. The liblinear solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. Elastic-Net penalty 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. The 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers can warm-start the coefficients (see :term:`Glossary`). Read more in the :ref:`User Guide `. 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. 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, then it is the number of 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 `) 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. 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 ` 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: - For small datasets, 'liblinear' is a good choice, whereas 'sag' and 'saga' are faster for large ones; - For multiclass problems, all solvers except 'liblinear' minimize the full multinomial loss; - '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`. - '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. .. warning:: The choice of the algorithm depends on the penalty chosen and on (multinomial) multiclass support: ================= ============================== ====================== solver penalty multinomial multiclass ================= ============================== ====================== 'lbfgs' 'l2' yes 'liblinear' 'l1', 'l2' no 'newton-cg' 'l2' yes 'newton-cholesky' 'l2', yes 'sag' 'l2', yes 'saga' 'elasticnet', 'l1', 'l2' 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 ` 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. multi_class : {'auto, 'ovr', 'multinomial'}, default='auto' If the option chosen is 'ovr', then a binary problem is fit for each label. For 'multinomial' the loss minimised is the multinomial loss fit across the entire probability distribution, *even when the data is binary*. 'multinomial' is unavailable when solver='liblinear'. 'auto' selects 'ovr' if the data is binary, or if solver='liblinear', and otherwise selects 'multinomial'. .. versionadded:: 0.18 Stochastic Average Gradient descent solver for 'multinomial' case. .. versionchanged:: 0.22 Default changed from 'ovr' to 'auto' in 0.22. .. deprecated:: 1.5 ``multi_class`` was deprecated in version 1.5 and will be removed in 1.8. From then on, the recommended 'multinomial' will always be used for `n_classes >= 3`. Solvers that do not support 'multinomial' will raise an error. Use `sklearn.multiclass.OneVsRestClassifier(LogisticRegressionCV())` if you still want to use OvR. 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 ` for details. l1_ratios : list of float, default=None The list of Elastic-Net mixing parameter, with ``0 <= l1_ratio <= 1``. Only used if ``penalty='elasticnet'``. A value of 0 is equivalent to using ``penalty='l2'``, while 1 is equivalent to using ``penalty='l1'``. For ``0 < l1_ratio <1``, the penalty is a combination of L1 and L2. 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 no l1_ratio is used (i.e. penalty is not 'elasticnet'), this is set to ``[None]`` coefs_paths_ : ndarray of shape (n_folds, n_cs, n_features) or (n_folds, n_cs, n_features + 1) dict with classes as the keys, and the path of coefficients obtained during cross-validating across each fold and then across each Cs after doing an OvR for the corresponding class as values. If the 'multi_class' option is set to 'multinomial', then the coefs_paths are the coefficients corresponding to each class. Each dict value has shape ``(n_folds, n_cs, n_features)`` or ``(n_folds, n_cs, n_features + 1)`` depending on whether the intercept is fit or not. If ``penalty='elasticnet'``, the shape is ``(n_folds, n_cs, n_l1_ratios_, n_features)`` or ``(n_folds, n_cs, n_l1_ratios_, n_features + 1)``. scores_ : dict dict with classes as the keys, and the values as the grid of scores obtained during cross-validating each fold, after doing an OvR for the corresponding class. If the 'multi_class' option given is 'multinomial' then the same scores are repeated across all classes, since this is the multinomial class. Each dict value has shape ``(n_folds, n_cs)`` or ``(n_folds, n_cs, n_l1_ratios)`` if ``penalty='elasticnet'``. C_ : ndarray of shape (n_classes,) or (n_classes - 1,) Array of C that maps to the best scores across every class. If refit is set to False, then for each class, the best C is the average of the C's that correspond to the best scores for each fold. `C_` is of shape(n_classes,) when the problem is binary. l1_ratio_ : ndarray of shape (n_classes,) or (n_classes - 1,) Array of l1_ratio that maps to the best scores across every class. If refit is set to False, then for each class, the best l1_ratio is the average of the l1_ratio's that correspond to the best scores for each fold. `l1_ratio_` is of shape(n_classes,) when the problem is binary. n_iter_ : ndarray of shape (n_classes, n_folds, n_cs) or (1, n_folds, n_cs) Actual number of iterations for all classes, folds and Cs. In the binary or multinomial cases, the first dimension is equal to 1. If ``penalty='elasticnet'``, the shape is ``(n_classes, n_folds, n_cs, n_l1_ratios)`` or ``(1, n_folds, n_cs, n_l1_ratios)``. 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).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)rrrr*Nrrz array-like cv_objectr>rr4r5)rcvr l1_ratiosrefitr: TFr4rZrrhrrfr)rrbr>r;r:rr9rzr~rrr{r@rrCrr?c||_||_||_||_||_||_||_| |_| |_| |_ | |_ ||_ | |_ ||_ ||_||_||_yr)rrbr>r;r:rrzr~rrr{r9r@rrCrr?)rrrbr>r;r:rr9rzr~rrr{r@rrCrr?s r<rzLogisticRegressionCV.__init__s**     (    !2&("r>rc f$%&'()*+t|dtjjj+jdk(rej 4t j dk(stdj Drtdj zj &n=j .tjdjjdg&tdtjd +d v \tj $t#j%}|j't)$t*r7$j-Dcic]\}}|j'|gd|c}}$|j.x}_|j'|j.} j0(j0d k(r3t j.d k(rtjdt2nUj0dvrtjdt2n,j0dk(rtjdt2nd(t5(+t |(+dvrt7dj9'nd't;rt=dfdi|*nGt?*t?i*_ t?|*_!*jBjDd<tGjHd} tK| jLfi*j@jL%t | } | d krtd|dz| d k(r d} | dd} |dd}(d k(rdgx} } n| } |} $dk(rItO$tjPt j.$t+tS$$tUtV)jdvrd}nd }tYjZj\|!$%&'()*+f d"| D}t_|\}}}}|d_0(d k(rtjb|t %t &t j`z| d#f}tjd|dd}tjd|dd }tjb|dt %t j`t &zf_3tjh|| ddf}ntjb|| t %t j`t &zd#f}tjb|| t %t j`t &zf_3tjb|| t %d#f}t+t_||_5t+t_||_6tK_7tK_8tjr| jtdf_;tjx| _=tSt_| | D]\}\}}(dk(rjj|}jl|}n|d}j|ru|jd$j}|t j`z}j`|}jnj||t j`z}&|}jpj|(d k(r%tj|dddd|ddfd$}n!tj|dd|ddfd$}tfid%|d&|gd'+d(jd)|d*jd+jd,jd-$d.(d/t9dj\dz d0jd1d2d3'dd4|\}}}|d}nktj|d$}(dk(rCtjtt %Dcgc]}||||ddfc}d$}nEtjtt %Dcgc]}|dd|||ddfc}d$}|t j`z} jnjtjj`| jdk(rJ|t j`z}!jpjtj&|!njpjd(d k(rtjhjn| _7tjhjp| _8|dddjtdf_;js|ddd#f_=|djtdjv|<js|d#jz|<tjjn_7tjjp_8tj&_Jj Éjlj-D]\}}"|"jct %jjj`jd#fjl|<tjjl|d5jl|<jjj-D]\}}#|#jct %jjj`jfjj|<tjjj|d6jj|<jfjcd#t %jjj`jf_3tjjfd7_3Scc}}wcc}wcc}w)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. rr5Nrc3nK|]-}t|tj xs |dkxs|dkD/yw)rr*N)rrNumber)r rs r<rz+LogisticRegressionCV.fit..]sE ! 'x@@(#a<(#a<(s35zGl1_ratios must be a list of numbers between 0 and 1; got (l1_ratios=%r)zOl1_ratios parameter is only used when penalty is 'elasticnet'. Got (penalty={})rIrrJrrBrrrrrAz'multi_class' was deprecated in version 1.5 and will be removed in 1.8. Use OneVsRestClassifier(LogisticRegressionCV(..)) instead. Leave it to its default value to avoid this warning.r@rTrrT)splitr) classifierrr*rYrQrr r c 3 K|]}D]\}}D]} ||fid|djdjdjdjddjdj dj d d jd d jd jd d d|d jjyw)rrrbr:r;r9rzr~r{rrrCrrrrTrrN) rrbr:r;rzr~r{rrrscorerr)r labelrrrrrfolds l1_ratios_rrCr routed_paramsrTrr9rSs r<rz+LogisticRegressionCV.fit..sRX 2$5X 4t&7X 65       77  #00   YY  HH    *    (! "#'"8"8# $"..% &!0' (,) *"+ ,+1177- X  X  X sCCrVrdrrr9rbrcr~rzr:rrCr{rrFrr)rrr*rj)rrr*)rr*rjr)Mrr=r9r:r;r?ranyr8rrrr)rrr!rrr transformrritemsrrCrrErrrr rsplitterrJrr r>rrFrarangerr%rr$rr{rCs_rswapaxesrtilescores_ coefs_paths_r l1_ratio_emptyrrrrr@rargmaxrmeanrrbr~rzrrangerrMr transpose),rrrSrTr label_encoderclsvrRencoded_labelsr>rDiter_encoded_labels iter_classesr r coefs_pathsrrrindex encoded_label best_index best_index_Cr best_index_l1rY coef_initrr best_indicesrbest_indices_Cbest_indices_l1 coefs_pathrrrLrMrrCrrNr9s,```` @@@@@@@@r<rzLogisticRegressionCV.fit:sa 6 &$.t{{DLL$))D <<< '&t~~&!+ %)NN !248NNCJ~~) 88>t||8L J  ** &.J J 1 %Q'(( %**1-  # #A & lD )COCUCUCW9?a ''.q114L #0"8"88$-&001G1GH&&   } ,T]]1Cq1H MML    !8 8 MML     & MML  !K(fc'lK _ $'48<<>O"O  +, M"GM%*_M "#(v#6M (>K $$**?;dggqT 2XRXXaCm&<&<&B&BCD' q=&qz*  >I+AB/NabkG - '26 7 ,"0 "L : %/ #dmm"45+ L  , 78L12  ;;/ )F FWhdkk4<> %$(#4#4#:#:#< Z)3););Z!5!5txx}}bI*!!#&*,%%c*L*!!#&  #ll002 O U$)MMZ!5!5txx}}E% S!%'LLc1BI$N S!  O  <<//SZ!5!5txx}}EDL<< lCDL q lX s? r#9r) <r. c t||d|j}trt|dfd|i|}n6t }t i|_|||j j d<||||fi|j j S)amScore 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. rrTrG)r _get_scorerrr rrJr)rrrSrTrrrNs r<rzLogisticRegressionCV.scores0 ,g6""$  +, M"GM#(r?M (>K $$**?;   ""((   r>c^t|jjj|j |j t j ddj |jt j ddj dd}|S)ajGet metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. .. versionadded:: 1.4 Returns ------- routing : MetadataRouter A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating routing information. )ownerrrF)callercallee)rRmethod_mappingr)rJrv)rr'r4add_self_requestaddr>rrq)rrouters r<get_metadata_routingz)LogisticRegressionCV.get_metadata_routings !8!8 9  d # S,22%2PS''),GG4E'2   r>c8|jxsd}t|S)zpGet the scorer based on the scoring method specified. The default scoring method is `accuracy`. accuracy)rr )rrs r<rqz LogisticRegressionCV._get_scorer s,,,*'""r>cFt|}d|j_|Sr,r-r1s r<r.z%LogisticRegressionCV.__sklearn_tags__ r3r>r)r4r5r6r7rrrr8parampopupdaterrrsetrcallablerr rrrzrqr.r9r:s@r<r<r<sdL $Q&8&O&O#PDP0*""5)*!!Haf=|L-"3'7'9#:;XtL&-["#=>?        '%#N5B6BH - ^>#r>r<)NrATrhrrrZNNFr4rfr@NTNNNr*)Nr7rrrrnumpyrjoblibrscipyrsklearn.metricsr _loss.lossr r baser metricsr model_selectionr preprocessingrr svm._baserutilsrrrrrutils._param_validationrrr utils.extmathrr utils.fixesrutils.metadata_routingrrrrr utils.multiclassr!utils.optimizer"r#utils.parallelr$r%utils.validationr&r'r(r)_baser+r,r-_glm.glmr. _linear_lossr/_sagr0rr=rErrrr<r>r<rs"#,> &8&CB.<<?. IH*)!(*       +q1ja/H\ .\ ~{ -/Dm{ r>