Ë
    ÷Q(hj}  ã                   ó  — d Z ddlmZmZ ddlZddlZddlm	Z	m
Z
mZmZmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZmZmZ ddl m!Z! ddl"m#Z#m$Z$  G d„ dee«      Z% G d„ de%«      Z& G d„ de%«      Z' G d„ de%«      Z(y)z>
Generalized Linear Models with Exponential Dispersion Family
é    )ÚIntegralÚRealNé   )ÚHalfGammaLossÚHalfPoissonLossÚHalfSquaredErrorÚHalfTweedieLossÚHalfTweedieLossIdentity)ÚBaseEstimatorÚRegressorMixinÚ_fit_context)Úcheck_array)Ú_openmp_effective_n_threads)ÚHiddenÚIntervalÚ
StrOptions)Ú_check_optimize_result)Ú_check_sample_weightÚcheck_is_fittedÚvalidate_dataé   )ÚLinearModelLossé   )ÚNewtonCholeskySolverÚNewtonSolverc            
       óü   ‡ — e Zd ZU dZ eeddd¬«      gdg eddh«       ee«      g ee	d	dd¬«      g eeddd
¬«      gdgdgdœZ
eed<   ddddddddœd„Z ed¬«      dd„«       Zd„ Zd„ Zdd„Zˆ fd„Zd„ Zˆ xZS )Ú_GeneralizedLinearRegressora  Regression via a penalized Generalized Linear Model (GLM).

    GLMs based on a reproductive Exponential Dispersion Model (EDM) aim at fitting and
    predicting the mean of the target y as y_pred=h(X*w) with coefficients w.
    Therefore, the fit minimizes the following objective function with L2 priors as
    regularizer::

        1/(2*sum(s_i)) * sum(s_i * deviance(y_i, h(x_i*w)) + 1/2 * alpha * ||w||_2^2

    with inverse link function h, s=sample_weight and per observation (unit) deviance
    deviance(y_i, h(x_i*w)). Note that for an EDM, 1/2 * deviance is the negative
    log-likelihood up to a constant (in w) term.
    The parameter ``alpha`` corresponds to the lambda parameter in glmnet.

    Instead of implementing the EDM family and a link function separately, we directly
    use the loss functions `from sklearn._loss` which have the link functions included
    in them for performance reasons. We pick the loss functions that implement
    (1/2 times) EDM deviances.

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

    .. versionadded:: 0.23

    Parameters
    ----------
    alpha : float, default=1
        Constant that multiplies the penalty term and thus determines the
        regularization strength. ``alpha = 0`` is equivalent to unpenalized
        GLMs. In this case, the design matrix `X` must have full column rank
        (no collinearities).
        Values must be in the range `[0.0, inf)`.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the linear predictor (X @ coef + intercept).

    solver : {'lbfgs', 'newton-cholesky'}, default='lbfgs'
        Algorithm to use in the optimization problem:

        'lbfgs'
            Calls scipy's L-BFGS-B optimizer.

        'newton-cholesky'
            Uses Newton-Raphson steps (in arbitrary precision arithmetic equivalent to
            iterated reweighted least squares) with an inner Cholesky based solver.
            This solver is a good choice for `n_samples` >> `n_features`, 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` because it explicitly computes the Hessian matrix.

            .. versionadded:: 1.2

    max_iter : int, default=100
        The maximal number of iterations for the solver.
        Values must be in the range `[1, inf)`.

    tol : float, default=1e-4
        Stopping criterion. For the lbfgs solver,
        the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``
        where ``g_j`` is the j-th component of the gradient (derivative) of
        the objective function.
        Values must be in the range `(0.0, inf)`.

    warm_start : bool, default=False
        If set to ``True``, reuse the solution of the previous call to ``fit``
        as initialization for ``coef_`` and ``intercept_``.

    verbose : int, default=0
        For the lbfgs solver set verbose to any positive number for verbosity.
        Values must be in the range `[0, inf)`.

    Attributes
    ----------
    coef_ : array of shape (n_features,)
        Estimated coefficients for the linear predictor (`X @ coef_ +
        intercept_`) in the GLM.

    intercept_ : float
        Intercept (a.k.a. bias) added to linear predictor.

    n_iter_ : int
        Actual number of iterations used in the solver.

    _base_loss : BaseLoss, default=HalfSquaredError()
        This is set during fit via `self._get_loss()`.
        A `_base_loss` contains a specific loss function as well as the link
        function. The loss to be minimized specifies the distributional assumption of
        the GLM, i.e. the distribution from the EDM. Here are some examples:

        =======================  ========  ==========================
        _base_loss               Link      Target Domain
        =======================  ========  ==========================
        HalfSquaredError         identity  y any real number
        HalfPoissonLoss          log       0 <= y
        HalfGammaLoss            log       0 < y
        HalfTweedieLoss          log       dependent on tweedie power
        HalfTweedieLossIdentity  identity  dependent on tweedie power
        =======================  ========  ==========================

        The link function of the GLM, i.e. mapping from linear predictor
        `X @ coeff + intercept` to prediction `y_pred`. For instance, with a log link,
        we have `y_pred = exp(X @ coeff + intercept)`.
    ç        NÚleft©ÚclosedÚbooleanÚlbfgsúnewton-choleskyr   ÚneitherÚverbose©ÚalphaÚfit_interceptÚsolverÚmax_iterÚtolÚ
warm_startr&   Ú_parameter_constraintsç      ð?Téd   ç-Cëâ6?Fr   c                óf   — || _         || _        || _        || _        || _        || _        || _        y ©Nr'   )Úselfr(   r)   r*   r+   r,   r-   r&   s           ú[/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/linear_model/_glm/glm.pyÚ__init__z$_GeneralizedLinearRegressor.__init__—   s6   € ð ˆŒ
Ø*ˆÔØˆŒØ ˆŒØˆŒØ$ˆŒØˆ�ó    )Úprefer_skip_nested_validationc                 óî  — t        | ||ddgt        j                  t        j                  gdd¬«      \  }}| j                  dk(  rt        j                  }n8t        t        |j                  |j                  «      t        j                  «      }t        ||dd¬«      }|�t        |||¬
«      }|j                  \  }}| j                  «       | _        t        | j                  | j                  ¬«      }|j                  j!                  |«      s-t#        d| j                  j$                  j&                  ›d�«      ‚| j(                  rxt+        | d«      rl| j                  r@t        j,                  | j.                  t        j0                  | j2                  g«      f«      }n| j.                  }|j5                  |d¬«      }n\|j7                  ||¬
«      }| j                  r=|j                  j8                  j9                  t        j:                  ||¬«      «      |d<   | j<                  }	t?        «       }
| j                  dk(  rŸ|j@                  }tB        jD                  jG                  ||dd| jH                  d| jJ                  dz
  | jL                  dt        jN                  tP        «      jR                  z  dœ||||	|
f¬«      }tU        d|«      | _+        |jX                  }nç| j                  dk(  rUt[        |||	| jL                  | jH                  |
| jJ                  ¬«      }|j]                  |||«      }|j^                  | _+        nƒta        | j                  tb        «      rP| j	                  |||	| jL                  | jH                  |
¬«      }|j]                  |||«      }|j^                  | _+        nt#        d| j                  › d�«      ‚| j                  r|d   | _        |d	d | _        | S d| _        || _        | S )a±  Fit a Generalized Linear Model.

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

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

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

        Returns
        -------
        self : object
            Fitted model.
        ÚcscÚcsrTF)Úaccept_sparseÚdtypeÚ	y_numericÚmulti_outputr#   ÚC©r=   ÚorderÚ	ensure_2dN©r=   )Ú	base_lossr)   ú:Some value(s) of y are out of the valid range of the loss ú.Úcoef_)Úcopy©ÚweightséÿÿÿÿzL-BFGS-Bé2   r   é@   )ÚmaxiterÚmaxlsÚiprintÚgtolÚftol)ÚmethodÚjacÚoptionsÚargsr$   )ÚcoefÚlinear_lossÚl2_reg_strengthr,   r+   Ú	n_threadsr&   )rX   rY   rZ   r,   r+   r[   zInvalid solver=r   )2r   ÚnpÚfloat64Úfloat32r*   ÚminÚmaxr=   r   r   ÚshapeÚ	_get_lossÚ
_base_lossr   r)   rE   Úin_y_true_rangeÚ
ValueErrorÚ	__class__Ú__name__r-   ÚhasattrÚconcatenaterH   ÚarrayÚ
intercept_ÚastypeÚinit_zero_coefÚlinkÚaverager(   r   Úloss_gradientÚscipyÚoptimizeÚminimizer+   r&   r,   ÚfinfoÚfloatÚepsr   Ún_iter_Úxr   ÚsolveÚ	iterationÚ
issubclassr   )r4   ÚXÚyÚsample_weightÚ
loss_dtypeÚ	n_samplesÚ
n_featuresrY   rX   rZ   r[   ÚfuncÚopt_resÚsols                 r5   Úfitz_GeneralizedLinearRegressor.fitª   st  € ô( ØØØØ  %˜.Ü—:‘:œrŸz™zÐ*ØØô
‰ˆˆ1ð �;‰;˜'Ò!ô Ÿ™‰JäœS §¡¨!¯'©'Ó2´B·J±JÓ?ˆJÜ˜ °3À%ÔHˆàÐ$ô 1°ÀÈÔTˆMà !§¡Ñˆ	�:ØŸ.™.Ó*ˆŒä%Ø—o‘oØ×,Ñ,ô
ˆð
 ×$Ñ$×4Ñ4°QÔ7ÜðØ—O‘O×-Ñ-×6Ñ6Ð9¸ð<óð ð, �?Š?œw t¨WÔ5Ø×!Ò!ä—~‘~ t§z¡z´2·8±8¸T¿_¹_Ð<MÓ3NÐ&OÓP‘à—z‘z�Ø—;‘;˜z°�;Ó6‰Dà×-Ñ-¨a°zÐ-ÓBˆDØ×!Ò!Ø&×0Ñ0×5Ñ5×:Ñ:Ü—J‘J˜q¨-Ô8ó��R‘ð Ÿ*™*ˆÜ/Ó1ˆ	ð �;‰;˜'Ò!Ø×,Ñ,ˆDä—n‘n×-Ñ-ØØØ!Øà#Ÿ}™}ØØ"Ÿl™l¨QÑ.Ø ŸH™Hð ¤§¡¬%£×!4Ñ!4Ñ4ñ	ð ˜˜M¨?¸IÐFð .ó ˆGô" 2°'¸7ÓCˆDŒLØ—9‘9‰DØ�[‰[Ð-Ò-Ü&ØØ'Ø /Ø—H‘HØŸ™Ø#ØŸ™ôˆCð —9‘9˜Q  =Ó1ˆDØŸ=™=ˆD�LÜ˜Ÿ™¤\Ô2Ø—+‘+ØØ'Ø /Ø—H‘HØŸ™Ø#ð ó ˆCð —9‘9˜Q  =Ó1ˆDØŸ=™=ˆD�Lä˜¨t¯{©{¨m¸1Ð=Ó>Ð>à×ÒØ" 2™hˆDŒOØ˜c˜r˜ˆDŒJð ˆð "ˆDŒOØˆDŒJàˆr7   c           	      ó´   — t        | «       t        | |g d¢t        j                  t        j                  gddd¬«      }|| j
                  z  | j                  z   S )a£  Compute the linear_predictor = `X @ coef_ + intercept_`.

        Note that we often use the term raw_prediction instead of linear predictor.

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

        Returns
        -------
        y_pred : array of shape (n_samples,)
            Returns predicted values of linear predictor.
        )r;   r:   ÚcooTF)r<   r=   rC   Úallow_ndÚreset)r   r   r\   r]   r^   rH   rk   )r4   r|   s     r5   Ú_linear_predictorz-_GeneralizedLinearRegressor._linear_predictorC  sQ   € ô 	˜ÔÜØØÚ/Ü—:‘:œrŸz™zÐ*ØØØô
ˆð �4—:‘:‰~ §¡Ñ/Ð/r7   c                 ór   — | j                  |«      }| j                  j                  j                  |«      }|S )a*  Predict using GLM with feature matrix X.

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

        Returns
        -------
        y_pred : array of shape (n_samples,)
            Returns predicted values.
        )rŠ   rc   rn   Úinverse)r4   r|   Úraw_predictionÚy_preds       r5   Úpredictz#_GeneralizedLinearRegressor.predict^  s3   € ð ×/Ñ/°Ó2ˆØ—‘×%Ñ%×-Ñ-¨nÓ=ˆØˆr7   c                 ó4  — | j                  |«      }t        ||j                  dd¬«      }|�t        |||j                  ¬«      }| j                  }|j                  |«      st        d|j                  › d�«      ‚t        j                  |j                  |d¬«      |¬	«      } ||||d
¬«      }|j                  j                  t        j                  ||¬	«      «      } ||t        j                  ||j                  d   «      |d
¬«      }	d
||z   |	|z   z  z
  S )aJ  Compute D^2, the percentage of deviance explained.

        D^2 is a generalization of the coefficient of determination R^2.
        R^2 uses squared error and D^2 uses the deviance of this GLM, see the
        :ref:`User Guide <regression_metrics>`.

        D^2 is defined as
        :math:`D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}`,
        :math:`D_{null}` is the null deviance, i.e. the deviance of a model
        with intercept alone, which corresponds to :math:`y_{pred} = \bar{y}`.
        The mean :math:`\bar{y}` is averaged by sample_weight.
        Best possible score is 1.0 and it can be negative (because the model
        can be arbitrarily worse).

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

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

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

        Returns
        -------
        score : float
            D^2 of self.predict(X) w.r.t. y.
        r@   FrA   NrD   rF   rG   )Úy_truer~   rJ   r   )r‘   r�   r~   r[   r   )rŠ   r   r=   r   rc   rd   re   rg   r\   ro   Úconstant_to_optimal_zerorn   Útilera   )
r4   r|   r}   r~   r�   rE   ÚconstantÚdevianceÚy_meanÚdeviance_nulls
             r5   Úscorez!_GeneralizedLinearRegressor.scorep  s%  € ðJ ×/Ñ/°Ó2ˆä˜ ×!5Ñ!5¸SÈEÔRˆàÐ$ô 1°ÀÈÏÉÔQˆMà—O‘Oˆ	à×(Ñ(¨Ô+ÜðØ×&Ñ&Ð' qð*óð ô
 —:‘:Ø×.Ñ.°aÀtÐ.ÓLØ!ô
ˆñ ØØ)Ø'Øô	
ˆð —‘×$Ñ$¤R§Z¡Z°¸=Ô%IÓJˆÙ!ØÜŸ7™7 6¨1¯7©7°1©:Ó6Ø'Øô	
ˆð �H˜xÑ'¨M¸HÑ,DÑEÑEÐEr7   c                 óà   •— t         ‰| �  «       }d|j                  _        	 | j	                  «       }|j                  d«       |j                  _        |S # t        t        t        f$ r Y |S w xY w)NTg      ð¿)ÚsuperÚ__sklearn_tags__Ú
input_tagsÚsparserb   rd   Útarget_tagsÚpositive_onlyre   ÚAttributeErrorÚ	TypeError)r4   ÚtagsrE   rf   s      €r5   r›   z,_GeneralizedLinearRegressor.__sklearn_tags__»  st   ø€ Ü‰wÑ'Ó)ˆØ!%ˆ�‰Ôð		ð Ÿ™Ó(ˆIØ1:×1JÑ1JÈ4Ó1PÐ-PˆD×ÑÔ*ð
 ˆøô	 œN¬IÐ6ò 	ð Øˆð		ús   ¢1A ÁA-Á,A-c                 ó   — t        «       S )a	  This is only necessary because of the link and power arguments of the
        TweedieRegressor.

        Note that we do not need to pass sample_weight to the loss class as this is
        only needed to set loss.constant_hessian on which GLMs do not rely.
        )r   ©r4   s    r5   rb   z%_GeneralizedLinearRegressor._get_lossÊ  s   € ô  Ó!Ð!r7   r3   )rg   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Útyper   r.   ÚdictÚ__annotations__r6   r   r…   rŠ   r�   r˜   r›   rb   Ú__classcell__©rf   s   @r5   r   r      sÍ   ø… ñfñX ˜4  d°6Ô:Ð;Ø#˜á˜Ð!2Ð3Ó4Ù�4‹Lð
ñ ˜h¨¨4¸Ô?Ð@Ù˜˜s D°Ô;Ð<Ø �kØ�;ñ$Ð˜Dó ð  ØØØØØØôñ& °Ô5òVó 6ðVòp0ò6ó$IFôVö"r7   r   c                   ób   ‡ — e Zd ZU dZi ej
                  ¥Zeed<   ddddddd	d
œˆ fd„
Zd„ Z	ˆ xZ
S )ÚPoissonRegressoraŸ  Generalized Linear Model with a Poisson distribution.

    This regressor uses the 'log' link function.

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

    .. versionadded:: 0.23

    Parameters
    ----------
    alpha : float, default=1
        Constant that multiplies the L2 penalty term and determines the
        regularization strength. ``alpha = 0`` is equivalent to unpenalized
        GLMs. In this case, the design matrix `X` must have full column rank
        (no collinearities).
        Values of `alpha` must be in the range `[0.0, inf)`.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the linear predictor (`X @ coef + intercept`).

    solver : {'lbfgs', 'newton-cholesky'}, default='lbfgs'
        Algorithm to use in the optimization problem:

        'lbfgs'
            Calls scipy's L-BFGS-B optimizer.

        'newton-cholesky'
            Uses Newton-Raphson steps (in arbitrary precision arithmetic equivalent to
            iterated reweighted least squares) with an inner Cholesky based solver.
            This solver is a good choice for `n_samples` >> `n_features`, 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` because it explicitly computes the Hessian matrix.

            .. versionadded:: 1.2

    max_iter : int, default=100
        The maximal number of iterations for the solver.
        Values must be in the range `[1, inf)`.

    tol : float, default=1e-4
        Stopping criterion. For the lbfgs solver,
        the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``
        where ``g_j`` is the j-th component of the gradient (derivative) of
        the objective function.
        Values must be in the range `(0.0, inf)`.

    warm_start : bool, default=False
        If set to ``True``, reuse the solution of the previous call to ``fit``
        as initialization for ``coef_`` and ``intercept_`` .

    verbose : int, default=0
        For the lbfgs solver set verbose to any positive number for verbosity.
        Values must be in the range `[0, inf)`.

    Attributes
    ----------
    coef_ : array of shape (n_features,)
        Estimated coefficients for the linear predictor (`X @ coef_ +
        intercept_`) in the GLM.

    intercept_ : float
        Intercept (a.k.a. bias) added to linear predictor.

    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_ : int
        Actual number of iterations used in the solver.

    See Also
    --------
    TweedieRegressor : Generalized Linear Model with a Tweedie distribution.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.PoissonRegressor()
    >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]
    >>> y = [12, 17, 22, 21]
    >>> clf.fit(X, y)
    PoissonRegressor()
    >>> clf.score(X, y)
    np.float64(0.990...)
    >>> clf.coef_
    array([0.121..., 0.158...])
    >>> clf.intercept_
    np.float64(2.088...)
    >>> clf.predict([[1, 1], [3, 4]])
    array([10.676..., 21.875...])
    r.   r/   Tr#   r0   r1   Fr   r'   c          	      ó2   •— t         ‰| �  |||||||¬«       y ©Nr'   ©rš   r6   ©	r4   r(   r)   r*   r+   r,   r-   r&   rf   s	           €r5   r6   zPoissonRegressor.__init__>  ó,   ø€ ô 	‰ÑØØ'ØØØØ!Øð 	õ 	
r7   c                 ó   — t        «       S r3   )r   r¤   s    r5   rb   zPoissonRegressor._get_lossS  s   € ÜÓ Ð r7   ©rg   r¥   r¦   r§   r   r.   r©   rª   r6   rb   r«   r¬   s   @r5   r®   r®   Ô  sH   ø… ñcðJ$Ø
%×
<Ñ
<ð$Ð˜Dó ð ØØØØØØö
ö*!r7   r®   c                   ób   ‡ — e Zd ZU dZi ej
                  ¥Zeed<   ddddddd	d
œˆ fd„
Zd„ Z	ˆ xZ
S )ÚGammaRegressoraá  Generalized Linear Model with a Gamma distribution.

    This regressor uses the 'log' link function.

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

    .. versionadded:: 0.23

    Parameters
    ----------
    alpha : float, default=1
        Constant that multiplies the L2 penalty term and determines the
        regularization strength. ``alpha = 0`` is equivalent to unpenalized
        GLMs. In this case, the design matrix `X` must have full column rank
        (no collinearities).
        Values of `alpha` must be in the range `[0.0, inf)`.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the linear predictor `X @ coef_ + intercept_`.

    solver : {'lbfgs', 'newton-cholesky'}, default='lbfgs'
        Algorithm to use in the optimization problem:

        'lbfgs'
            Calls scipy's L-BFGS-B optimizer.

        'newton-cholesky'
            Uses Newton-Raphson steps (in arbitrary precision arithmetic equivalent to
            iterated reweighted least squares) with an inner Cholesky based solver.
            This solver is a good choice for `n_samples` >> `n_features`, 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` because it explicitly computes the Hessian matrix.

            .. versionadded:: 1.2

    max_iter : int, default=100
        The maximal number of iterations for the solver.
        Values must be in the range `[1, inf)`.

    tol : float, default=1e-4
        Stopping criterion. For the lbfgs solver,
        the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``
        where ``g_j`` is the j-th component of the gradient (derivative) of
        the objective function.
        Values must be in the range `(0.0, inf)`.

    warm_start : bool, default=False
        If set to ``True``, reuse the solution of the previous call to ``fit``
        as initialization for `coef_` and `intercept_`.

    verbose : int, default=0
        For the lbfgs solver set verbose to any positive number for verbosity.
        Values must be in the range `[0, inf)`.

    Attributes
    ----------
    coef_ : array of shape (n_features,)
        Estimated coefficients for the linear predictor (`X @ coef_ +
        intercept_`) in the GLM.

    intercept_ : float
        Intercept (a.k.a. bias) added to linear predictor.

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

        .. versionadded:: 0.24

    n_iter_ : int
        Actual number of iterations used in the solver.

    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
    --------
    PoissonRegressor : Generalized Linear Model with a Poisson distribution.
    TweedieRegressor : Generalized Linear Model with a Tweedie distribution.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.GammaRegressor()
    >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]
    >>> y = [19, 26, 33, 30]
    >>> clf.fit(X, y)
    GammaRegressor()
    >>> clf.score(X, y)
    np.float64(0.773...)
    >>> clf.coef_
    array([0.072..., 0.066...])
    >>> clf.intercept_
    np.float64(2.896...)
    >>> clf.predict([[1, 0], [2, 8]])
    array([19.483..., 35.795...])
    r.   r/   Tr#   r0   r1   Fr   r'   c          	      ó2   •— t         ‰| �  |||||||¬«       y r°   r±   r²   s	           €r5   r6   zGammaRegressor.__init__Â  r³   r7   c                 ó   — t        «       S r3   )r   r¤   s    r5   rb   zGammaRegressor._get_loss×  s
   € Ü‹Ðr7   rµ   r¬   s   @r5   r·   r·   W  sH   ø… ñdðL$Ø
%×
<Ñ
<ð$Ð˜Dó ð ØØØØØØö
ö*r7   r·   c            
       ó˜   ‡ — e Zd ZU dZi ej
                  ¥ eeddd¬«      g eh d£«      gdœ¥Ze	e
d<   dd	d
dddddddœ	ˆ fd„
Zd„ Zˆ xZS )ÚTweedieRegressora:  Generalized Linear Model with a Tweedie distribution.

    This estimator can be used to model different GLMs depending on the
    ``power`` parameter, which determines the underlying distribution.

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

    .. versionadded:: 0.23

    Parameters
    ----------
    power : float, default=0
            The power determines the underlying target distribution according
            to the following table:

            +-------+------------------------+
            | Power | Distribution           |
            +=======+========================+
            | 0     | Normal                 |
            +-------+------------------------+
            | 1     | Poisson                |
            +-------+------------------------+
            | (1,2) | Compound Poisson Gamma |
            +-------+------------------------+
            | 2     | Gamma                  |
            +-------+------------------------+
            | 3     | Inverse Gaussian       |
            +-------+------------------------+

            For ``0 < power < 1``, no distribution exists.

    alpha : float, default=1
        Constant that multiplies the L2 penalty term and determines the
        regularization strength. ``alpha = 0`` is equivalent to unpenalized
        GLMs. In this case, the design matrix `X` must have full column rank
        (no collinearities).
        Values of `alpha` must be in the range `[0.0, inf)`.

    fit_intercept : bool, default=True
        Specifies if a constant (a.k.a. bias or intercept) should be
        added to the linear predictor (`X @ coef + intercept`).

    link : {'auto', 'identity', 'log'}, default='auto'
        The link function of the GLM, i.e. mapping from linear predictor
        `X @ coeff + intercept` to prediction `y_pred`. Option 'auto' sets
        the link depending on the chosen `power` parameter as follows:

        - 'identity' for ``power <= 0``, e.g. for the Normal distribution
        - 'log' for ``power > 0``, e.g. for Poisson, Gamma and Inverse Gaussian
          distributions

    solver : {'lbfgs', 'newton-cholesky'}, default='lbfgs'
        Algorithm to use in the optimization problem:

        'lbfgs'
            Calls scipy's L-BFGS-B optimizer.

        'newton-cholesky'
            Uses Newton-Raphson steps (in arbitrary precision arithmetic equivalent to
            iterated reweighted least squares) with an inner Cholesky based solver.
            This solver is a good choice for `n_samples` >> `n_features`, 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` because it explicitly computes the Hessian matrix.

            .. versionadded:: 1.2

    max_iter : int, default=100
        The maximal number of iterations for the solver.
        Values must be in the range `[1, inf)`.

    tol : float, default=1e-4
        Stopping criterion. For the lbfgs solver,
        the iteration will stop when ``max{|g_j|, j = 1, ..., d} <= tol``
        where ``g_j`` is the j-th component of the gradient (derivative) of
        the objective function.
        Values must be in the range `(0.0, inf)`.

    warm_start : bool, default=False
        If set to ``True``, reuse the solution of the previous call to ``fit``
        as initialization for ``coef_`` and ``intercept_`` .

    verbose : int, default=0
        For the lbfgs solver set verbose to any positive number for verbosity.
        Values must be in the range `[0, inf)`.

    Attributes
    ----------
    coef_ : array of shape (n_features,)
        Estimated coefficients for the linear predictor (`X @ coef_ +
        intercept_`) in the GLM.

    intercept_ : float
        Intercept (a.k.a. bias) added to linear predictor.

    n_iter_ : int
        Actual number of iterations used in the solver.

    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
    --------
    PoissonRegressor : Generalized Linear Model with a Poisson distribution.
    GammaRegressor : Generalized Linear Model with a Gamma distribution.

    Examples
    --------
    >>> from sklearn import linear_model
    >>> clf = linear_model.TweedieRegressor()
    >>> X = [[1, 2], [2, 3], [3, 4], [4, 3]]
    >>> y = [2, 3.5, 5, 5.5]
    >>> clf.fit(X, y)
    TweedieRegressor()
    >>> clf.score(X, y)
    np.float64(0.839...)
    >>> clf.coef_
    array([0.599..., 0.299...])
    >>> clf.intercept_
    np.float64(1.600...)
    >>> clf.predict([[1, 1], [3, 4]])
    array([2.500..., 4.599...])
    Nr%   r    >   ÚlogÚautoÚidentity)Úpowerrn   r.   r   r/   Tr½   r#   r0   r1   Fr   )	r¿   r(   r)   rn   r*   r+   r,   r-   r&   c       	   	      óN   •— t         ‰
| �  |||||||	¬«       || _        || _        y r°   )rš   r6   rn   r¿   )r4   r¿   r(   r)   rn   r*   r+   r,   r-   r&   rf   s             €r5   r6   zTweedieRegressor.__init__f  s<   ø€ ô 	‰ÑØØ'ØØØØ!Øð 	ô 	
ð ˆŒ	Øˆ�
r7   c                 ó,  — | j                   dk(  r;| j                  dk  rt        | j                  ¬«      S t        | j                  ¬«      S | j                   dk(  rt        | j                  ¬«      S | j                   dk(  rt        | j                  ¬«      S y )Nr½   r   )r¿   r¼   r¾   )rn   r¿   r
   r	   r¤   s    r5   rb   zTweedieRegressor._get_loss  st   € Ø�9‰9˜ÒØ�z‰z˜QŠä.°T·Z±ZÔ@Ð@ô '¨T¯Z©ZÔ8Ð8à�9‰9˜ÒÜ"¨¯©Ô4Ð4à�9‰9˜
Ò"Ü*°·±Ô<Ð<ð #r7   )rg   r¥   r¦   r§   r   r.   r   r   r   r©   rª   r6   rb   r«   r¬   s   @r5   r»   r»   Û  sp   ø… ñBðH$Ø
%×
<Ñ
<ð$á˜4  t°IÔ>Ð?ÙÒ7Ó8Ð9ò$Ð˜Dó ð ØØØØØØØØöö2=r7   r»   ))r§   Únumbersr   r   Únumpyr\   Úscipy.optimizerq   Ú
_loss.lossr   r   r   r	   r
   Úbaser   r   r   Úutilsr   Úutils._openmp_helpersr   Úutils._param_validationr   r   r   Úutils.optimizer   Úutils.validationr   r   r   Ú_linear_lossr   Ú_newton_solverr   r   r   r®   r·   r»   © r7   r5   ú<module>rÏ      sƒ   ðñ÷ #ã Û ÷õ ÷ @Ñ ?Ý  Ý @ß CÑ CÝ 4ß TÑ TÝ *ß >ôs" .°-ô s"ôl@!Ð2ô @!ôFAÐ0ô AôHq=Ð2õ q=r7   