
    0Phj}                     4   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(dS )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      ?Td   -C6?Fr   c                h    || _         || _        || _        || _        || _        || _        || _        d S Nr'   )selfr(   r)   r*   r+   r,   r-   r&   s           ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/linear_model/_glm/glm.py__init__z$_GeneralizedLinearRegressor.__init__   s:     
* $    )prefer_skip_nested_validationc                    t          | ||ddgt          j        t          j        gdd          \  }}| j        dk    rt          j        }n2t          t          |j        |j                  t          j                  }t          ||dd          }|t          |||
          }|j
        \  }}|                                 | _        t          | j        | j                  }|j                            |          s"t#          d| j        j        j        d          | j        rjt+          | d          rZ| j        r4t          j        | j        t          j        | j        g          f          }n| j        }|                    |d          }nT|                    ||
          }| j        r6|j        j                            t          j        ||                    |d<   | j        }	t?                      }
| j        dk    r|j         }tB          j"        #                    ||dd| j$        d| j%        dz
  | j&        dt          j'        tP                    j)        z  d||||	|
f          }tU          d|          | _+        |j,        }n| j        dk    rIt[          |||	| j&        | j$        |
| j%                  }|.                    |||          }|j/        | _+        n{ta          | j        tb                    rI|                     |||	| j&        | j$        |
          }|.                    |||          }|j/        | _+        nt#          d| j         d          | j        r|d         | _        |d	d         | _        n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weightszL-BFGS-B2   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   s   (  %.:rz*
 
 
1 ;'!! JJS!'22BJ??J3%HHH$ 1TTTM !	:..**%o,
 
 

 $44Q77 	<O-6< < <  , ? 	wtW55 	! "~tz28T_<M3N3N&OPPz;;z;66DD--az-BBD! &05::Jq-888 R */11	 ;'!!,Dn--!#}"lQ. H %!44	 	 M?IF .  G" 2'7CCDL9DD[---&' /H#  C 99Q=11D=DLL\22 	?++' /H#   C 99Q=11D=DLL=t{===>>> 	"2hDOcrcDJJ "DODJ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  s_     	///:rz*
 
 
 4:~//r7   c                 n    |                      |          }| 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^  s4     //22%--n==r7   c                 <   |                      |          }t          ||j        dd          }|t          |||j                  }| j        }|                    |          st          d|j         d          t          j	        |
                    |d          |	          } ||||d
          }|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  sc   J //22!5SERRR$ 1QQQMO	((++ 	*&* * *  
 :..at.LL!
 
 
 9)'	
 
 
 $$RZ=%I%I%IJJ!	76171:66'	
 
 
 Hx'MH,DEEEr7   c                    t                                                      }d|j        _        	 |                                 }|                    d           |j        _        n# t          t          t          f$ r Y nw xY w|S )NTg      )super__sklearn_tags__
input_tagssparserb   rd   target_tagspositive_onlyre   AttributeError	TypeError)r4   tagsrE   rf   s      r5   r   z,_GeneralizedLinearRegressor.__sklearn_tags__  s    ww''))!%		 ((I1:1J1J41P1P-PD**NI6 	 	 	 D	 s   4A$ $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 fX (4d6:::;#J!2344F4LL
 Xh4???@sD;;;< k;$ $D         & \555V V V 65Vp0 0 06  $IF IF IF IFV    " " " " " " "r7   r   c                   X     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          	      X    t                                          |||||||           d S Nr'   r   r6   	r4   r(   r)   r*   r+   r,   r-   r&   rf   s	           r5   r6   zPoissonRegressor.__init__>  E     	'! 	 	
 	
 	
 	
 	
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     s         c cJ$
%
<$D    
 
 
 
 
 
 
*! ! ! ! ! ! !r7   r   c                   X     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          	      X    t                                          |||||||           d S 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  s         d 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       	   	      t    t                                          |||||||	           || _        || _        d S r   )r   r6   rn   r   )r4   r   r(   r)   rn   r*   r+   r,   r-   r&   rf   s             r5   r6   zTweedieRegressor.__init__f  sO     	'! 	 	
 	
 	
 	


r7   c                    | j         dk    r5| j        dk    rt          | j                  S t          | j                  S | j         dk    rt          | j                  S | j         dk    rt          | j                  S d S )Nr   r   )r   r   r   )rn   r   r
   r	   r   s    r5   rb   zTweedieRegressor._get_loss  s    9zQ.TZ@@@@ 'TZ88889"44449
""*<<<< #"r7   )rg   r   r   r   r   r.   r   r   r   r   r   r6   rb   r   r   s   @r5   r   r     s         B BH$
%
<$(4tI>>>?7778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 C C C C C C C C 4 4 4 4 4 4 T T T T T T T T T T * * * * * * > > > > > > > >s" s" s" s" s".- s" s" s"l@! @! @! @! @!2 @! @! @!FA A A A A0 A A AHq= q= q= q= q=2 q= q= q= q= q=r7   