Ë
    êÿæi)  ã                   óº   — d dl Z d dlmZ d dl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 d dlmZ d d	lmZmZ d d
lmZmZ d dlmZmZ  G d„ deee
«      Zy)é    N)ÚReal)Úsparse)Úlinprog)ÚBaseEstimatorÚRegressorMixinÚ_fit_context)ÚConvergenceWarning)ÚLinearModel)Ú_safe_indexing)ÚIntervalÚ
StrOptions)Úparse_versionÚ
sp_version)Ú_check_sample_weightÚvalidate_datac                   ó¶   ‡ — e Zd ZU dZ eeddd¬«      g eeddd¬«      gdg eh d	£«      gedgd
œZee	d<   dddddd
œd„Z
 ed¬«      dd„«       Zˆ fd„Zˆ xZS )ÚQuantileRegressoraÍ  Linear regression model that predicts conditional quantiles.

    The linear :class:`QuantileRegressor` optimizes the pinball loss for a
    desired `quantile` and is robust to outliers.

    This model uses an L1 regularization like
    :class:`~sklearn.linear_model.Lasso`.

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

    .. versionadded:: 1.0

    Parameters
    ----------
    quantile : float, default=0.5
        The quantile that the model tries to predict. It must be strictly
        between 0 and 1. If 0.5 (default), the model predicts the 50%
        quantile, i.e. the median.

    alpha : float, default=1.0
        Regularization constant that multiplies the L1 penalty term.

    fit_intercept : bool, default=True
        Whether or not to fit the intercept.

    solver : {'highs-ds', 'highs-ipm', 'highs', 'interior-point',             'revised simplex'}, default='highs'
        Method used by :func:`scipy.optimize.linprog` to solve the linear
        programming formulation.

        It is recommended to use the highs methods because
        they are the fastest ones. Solvers "highs-ds", "highs-ipm" and "highs"
        support sparse input data and, in fact, always convert to sparse csc.

        From `scipy>=1.11.0`, "interior-point" is not available anymore.

        .. versionchanged:: 1.4
           The default of `solver` changed to `"highs"` in version 1.4.

    solver_options : dict, default=None
        Additional parameters passed to :func:`scipy.optimize.linprog` as
        options. If `None` and if `solver='interior-point'`, then
        `{"lstsq": True}` is passed to :func:`scipy.optimize.linprog` for the
        sake of stability.

    Attributes
    ----------
    coef_ : array of shape (n_features,)
        Estimated coefficients for the features.

    intercept_ : float
        The intercept of the model, aka bias term.

    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
        The actual number of iterations performed by the solver.

    See Also
    --------
    Lasso : The Lasso is a linear model that estimates sparse coefficients
        with l1 regularization.
    HuberRegressor : Linear regression model that is robust to outliers.

    Examples
    --------
    >>> from sklearn.linear_model import QuantileRegressor
    >>> import numpy as np
    >>> n_samples, n_features = 10, 2
    >>> rng = np.random.RandomState(0)
    >>> y = rng.randn(n_samples)
    >>> X = rng.randn(n_samples, n_features)
    >>> # the two following lines are optional in practice
    >>> from sklearn.utils.fixes import sp_version, parse_version
    >>> reg = QuantileRegressor(quantile=0.8).fit(X, y)
    >>> np.mean(y <= reg.predict(X))
    np.float64(0.8)
    r   é   Úneither)ÚclosedNÚleftÚboolean>   úrevised simplexÚhighsúhighs-dsú	highs-ipmúinterior-point©ÚquantileÚalphaÚfit_interceptÚsolverÚsolver_optionsÚ_parameter_constraintsg      à?g      ð?Tr   c                óJ   — || _         || _        || _        || _        || _        y ©Nr   )Úselfr   r    r!   r"   r#   s         ús/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/sklearn/linear_model/_quantile.pyÚ__init__zQuantileRegressor.__init__   s)   € ð !ˆŒØˆŒ
Ø*ˆÔØˆŒØ,ˆÕó    )Úprefer_skip_nested_validationc                 óŠ  — t        | ||g d¢dd¬«      \  }}t        ||«      }|j                  d   }|}| j                  r|dz  }t	        j
                  |«      | j                  z  }| j                  dk(  r+t        t        d«      k\  rt        d| j                  › d	�«      ‚t        j                  |«      r'| j                  d
vrt        d| j                  › d�«      ‚| j                  €| j                  dk(  rddi}n| j                  }t	        j                  |«      d   }t        |«      }	|	t        |«      k  r||   }t!        ||«      }t!        ||«      }t	        j"                  t	        j$                  d|z  |¬«      || j&                  z  |d| j&                  z
  z  g«      }
| j                  r
d|
d<   d|
|<   | j                  d
v r£t        j(                  |	|j*                  d¬«      }| j                  rWt        j,                  t	        j.                  |	df|j*                  ¬«      «      }t        j0                  ||| | || gd¬«      }n”t        j0                  || || gd¬«      }nvt	        j(                  |	«      }| j                  r8t	        j.                  |	df«      }t	        j"                  ||| | || gd¬«      }nt	        j"                  || || gd¬«      }|}t3        |
||| j                  |¬«      }|j4                  }|j6                  s_dddddœ}t9        j:                  d|j<                  › d�|j?                  |j<                  d«      z   dz   d z   |j@                  z   tB        «       |d| ||d|z   z
  }|jD                  | _#        | j                  r|dd | _$        |d   | _%        | S || _$        d!| _%        | S )"aÅ  Fit the model according to the given training data.

        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
            Returns self.
        )ÚcscÚcsrÚcooTF)Úaccept_sparseÚ	y_numericÚmulti_outputr   r   z1.11.0zSolver z- is not anymore available in SciPy >= 1.11.0.)r   r   r   z; does not support sparse X. Use solver 'highs' for example.NÚlstsqr   é   )Ú
fill_valuer-   )ÚdtypeÚformat)Úshaper6   )r7   )Úaxis)ÚcÚA_eqÚb_eqÚmethodÚoptionszIteration limit reached.z!Problem appears to be infeasible.z Problem appears to be unbounded.z#Numerical difficulties encountered.)r   r4   é   é   zDLinear programming for QuantileRegressor did not succeed.
Status is z: zunknown reasonÚ
zResult message of linprog:
g        )&r   r   r8   r!   ÚnpÚsumr    r"   r   r   Ú
ValueErrorr   Úissparser#   ÚnonzeroÚlenr   ÚconcatenateÚfullr   Úeyer6   Ú
csc_matrixÚonesÚhstackr   ÚxÚsuccessÚwarningsÚwarnÚstatusÚ
setdefaultÚmessager	   ÚnitÚn_iter_Úcoef_Ú
intercept_)r'   ÚXÚyÚsample_weightÚ
n_featuresÚn_paramsr    r#   ÚindicesÚ	n_indicesr:   rJ   rL   r;   r<   ÚresultÚsolutionÚfailureÚparamss                      r(   ÚfitzQuantileRegressor.fitŽ   sÈ  € ô( ØØØÚ/ØØô
‰ˆˆ1ô -¨]¸AÓ>ˆà—W‘W˜Q‘Zˆ
Øˆà×ÒØ˜‰MˆHô —‘�}Ó%¨¯
©
Ñ2ˆà�;‰;Ð*Ò*¬z¼]È8Ó=TÒ/TÜØ˜$Ÿ+™+˜Ð&SÐTóð ô �?‰?˜1Ô $§+¡+Ð5WÑ"WÜØ˜$Ÿ+™+˜ð '2ð 2óð ð
 ×ÑÐ&¨4¯;©;Ð:JÒ+JØ% t˜_‰Nà!×0Ñ0ˆNô, —*‘*˜]Ó+¨AÑ.ˆÜ˜“Lˆ	Ø”s˜=Ó)Ò)Ø)¨'Ñ2ˆMÜ˜q 'Ó*ˆAÜ˜q 'Ó*ˆAÜ�N‰Nä—‘˜˜H™°Ô7Ø §¡Ñ-Ø  T§]¡]Ñ!2Ñ3ðó
ˆð ×ÒàˆAˆa‰DØˆAˆh‰Kà�;‰;Ð<Ñ<ô
 —*‘*˜Y¨a¯g©g¸eÔDˆCØ×!Ò!Ü×(Ñ(¬¯©¸	À1°~ÈQÏWÉWÔ)UÓV�Ü—}‘} d¨A°¨u°q°b¸#À¸tÐ%DÈUÔS‘ä—}‘} a¨!¨¨S°3°$Ð%7ÀÔF‘ä—&‘&˜Ó#ˆCØ×!Ò!Ü—w‘w 	¨1˜~Ó.�Ü—~‘~ t¨Q°°¸°r¸3ÀÀÐ&EÈAÔN‘ä—~‘~ q¨1¨"¨c°C°4Ð&8¸qÔA�àˆäØØØØ—;‘;Ø"ô
ˆð —8‘8ˆØ�~Š~à-Ø6Ø5Ø8ñ	ˆGô �M‰MðØ#Ÿ]™]˜O¨2ð/à×$Ñ$ V§]¡]Ð4DÓEñFð ñð 1ñ	1ð
 —.‘.ñ!ô #ôð ˜)˜8Ð$ x°¸1¸x¹<Ð'HÑHˆà—z‘zˆŒà×ÒØ  ˜ˆDŒJØ$ Q™iˆDŒOð ˆð  ˆDŒJØ!ˆDŒOØˆr*   c                 óF   •— t         ‰| �  «       }d|j                  _        |S )NT)ÚsuperÚ__sklearn_tags__Ú
input_tagsr   )r'   ÚtagsÚ	__class__s     €r(   rg   z"QuantileRegressor.__sklearn_tags__*  s!   ø€ Ü‰wÑ'Ó)ˆØ!%ˆ�‰ÔØˆr*   r&   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Údictr$   Ú__annotations__r)   r   rd   rg   Ú__classcell__)rj   s   @r(   r   r      s™   ø… ñVñr ˜d A q°Ô;Ð<Ù˜4  D°Ô8Ð9Ø#˜áòóð

ð   ˜,ñ$Ð˜Dó ð* ØØØØô-ñ °Ô5òYó 6ðY÷vð r*   r   )rP   Únumbersr   ÚnumpyrB   Úscipyr   Úscipy.optimizer   Úsklearn.baser   r   r   Úsklearn.exceptionsr	   Úsklearn.linear_model._baser
   Úsklearn.utilsr   Úsklearn.utils._param_validationr   r   Úsklearn.utils.fixesr   r   Úsklearn.utils.validationr   r   r   © r*   r(   Ú<module>r~      s@   ðó Ý ã Ý Ý "ç DÑ DÝ 1Ý 2Ý (ß @ß 9ß HôY˜ ^°]õ Yr*   