U
    <¼|e¢+  ã                   @   s°   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 ddl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mZ G dd„ deee
ƒZdS )é    N)ÚReal)Úsparse)Úlinprogé   )ÚBaseEstimatorÚRegressorMixiné   )ÚLinearModel)ÚConvergenceWarning)Ú_safe_indexing)Ú_check_sample_weight)Ú
sp_versionÚparse_version)ÚHiddenÚIntervalÚ
StrOptionsc                	   @   sˆ   e Zd ZU dZeedddd�geedddd�gdged	d
dddhƒeedhƒƒgedgdœZ	ee
d< ddddddœdd„Zddd„ZdS )ÚQuantileRegressoraI  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='interior-point'
        Method used by :func:`scipy.optimize.linprog` to solve the linear
        programming formulation.

        From `scipy>=1.6.0`, 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` will change 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
    >>> solver = "highs" if sp_version >= parse_version("1.6.0") else "interior-point"
    >>> reg = QuantileRegressor(quantile=0.8, solver=solver).fit(X, y)
    >>> np.mean(y <= reg.predict(X))
    0.8
    r   r   Úneither)ÚclosedNÚleftÚbooleanúhighs-dsú	highs-ipmÚhighsúinterior-pointzrevised simplexÚwarn©ÚquantileÚalphaÚfit_interceptÚsolverÚsolver_optionsÚ_parameter_constraintsg      à?g      ð?Tc                C   s"   || _ || _|| _|| _|| _d S )Nr   )Úselfr   r   r   r    r!   © r$   ú[/var/www/website-v5/atlas_env/lib/python3.8/site-packages/sklearn/linear_model/_quantile.pyÚ__init__�   s
    	zQuantileRegressor.__init__c                 C   s2  |   ¡  | j||dddgddd�\}}t||ƒ}|jd }|}| jrL|d7 }t |¡| j }| jdkrxt	 
d	t¡ d
}n4| jdkr¦ttdƒk r¦td| j› dt› �ƒ‚n| j}|d
krÐttdƒkrÐtd|› d�ƒ‚t |¡rô|dkrôtd| j› d�ƒ‚| jdk�r|d
k�rddi}n| j}t |¡d }	t|	ƒ}
|
t|ƒk �rZ||	 }t||	ƒ}t||	ƒ}t tjd| |d�|| j |d| j  g¡}| j�r d|d< d||< |dk�rtj|
|jdd�}| j�r t tj|
df|jd�¡}tj||| | || gdd�}ntj|| || gdd�}n\t |
¡}| j�r^t |
df¡}tj||| | || gdd�}ntj|| || gdd�}|}t|||||d�}|j}|j�sÜdddd d!œ}t	 
d"|j › d#�| !|j d$¡ d% d& |j" t#¡ |d|… ||d| …  }|j$| _%| j�r"|dd… | _&|d | _'n|| _&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–The default solver will change from 'interior-point' to 'highs' in version 1.4. Set `solver='highs'` or to the desired solver to silence this warning.r   )r   r   r   z1.6.0zSolver z* is only available with scipy>=1.6.0, got z1.11.0z- 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   r   )Ú
fill_value)ÚdtypeÚformat)Úshaper/   )r0   )Ú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   r   é   é   zDLinear programming for QuantileRegressor did not succeed.
Status is z: zunknown reasonÚ
zResult message of linprog:
g        )(Ú_validate_paramsÚ_validate_datar   r1   r   ÚnpÚsumr   r    Úwarningsr   ÚFutureWarningr   r   Ú
ValueErrorr   Úissparser!   ÚnonzeroÚlenr   ÚconcatenateÚfullr   Úeyer/   Ú
csc_matrixÚonesÚhstackr   ÚxÚsuccessÚstatusÚ
setdefaultÚmessager
   ÚnitÚn_iter_Úcoef_Ú
intercept_)r#   ÚXÚyÚsample_weightÚ
n_featuresÚn_paramsr   r    r!   ÚindicesZ	n_indicesr3   rG   rI   r4   r5   ÚresultÚsolutionZfailureÚparamsr$   r$   r%   Úfit�   sÆ    û



ü

üÿ
ÿÿ


ýÿ
"
"ûüþýüûùzQuantileRegressor.fit)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Údictr"   Ú__annotations__r&   r]   r$   r$   r$   r%   r      s.   
Zûÿ	öðùr   )r?   Únumbersr   Únumpyr=   Úscipyr   Úscipy.optimizer   Úbaser   r   Ú_baser	   Ú
exceptionsr
   Úutilsr   Úutils.validationr   Úutils.fixesr   r   Úutils._param_validationr   r   r   r   r$   r$   r$   r%   Ú<module>   s   