o
    tBh)                     @   s   d dl 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 G dd dee	eZdS )    N)sparse)linprog   )BaseEstimatorRegressorMixin   )LinearModel)ConvergenceWarning)_safe_indexing)_check_sample_weight)
sp_versionparse_versionc                   @   s0   e Zd ZdZdddddddd	Zdd
dZd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='interior-point'
        Method used by :func:`scipy.optimize.linprog` to solve the linear
        programming formulation. Note that the highs methods are recommended
        for usage with `scipy>=1.6.0` 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.

    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)
    >>> reg = QuantileRegressor(quantile=0.8).fit(X, y)
    >>> np.mean(y <= reg.predict(X))
    0.8
    g      ?      ?Tinterior-pointNquantilealphafit_interceptsolversolver_optionsc                C   s"   || _ || _|| _|| _|| _d S Nr   )selfr   r   r   r   r    r   u/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/linear_model/_quantile.py__init__c   s
   	
zQuantileRegressor.__init__c                 C   s~  | j ||g dddd\}}t||}|jd }|}| jr!|d7 }| jdkr/t|| j }ntd| j | jdksA| jd	krItd
| j t	| jt
sWtd| j | jdvrdtd| j | jdv rzttdk rztd| j dt t|r| jdvrtd| j d| jdurt	| jtstd| j | jdu r| jdkrddi}n| j}t|d }t|}	|	t|k r|| }t||}t||}ttjd| |d|| j |d| j  g}
| jrd|
d< d|
|< | jdv r2t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rSt|	df}tj||| | || gdd}ntj|| || gdd}|}t|
||| j|d}|j}|jsd d!d"d#d$}t d%|j! d&|"|j!d' d( d) |j# t$ |d| ||d|   }|j%| _&| 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   z1Penalty alpha must be a non-negative number, got r   g        z5Quantile should be strictly between 0.0 and 1.0, got z-The argument fit_intercept must be bool, got )highs-ds	highs-ipmhighsr   zrevised simplexz'Invalid value for argument solver, got )r"   r#   r$   z1.6.0zSolver z* is only available with scipy>=1.6.0, got )r$   r"   r#   z; does not support sparse X. Use solver 'highs' for example.NzMInvalid value for argument solver_options, must be None or a dictionary, got r   lstsqr   )
fill_valuer   )dtypeformat)shaper'   )r(   )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:
))_validate_datar   r)   r   r   npsum
ValueErrorr   
isinstanceboolr   r   r   r   issparser   dictnonzerolenr
   concatenatefulleyer'   
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+   r?   rA   r,   r-   resultsolutionfailureparamsr   r   r   fitr   s   












"
"
zQuantileRegressor.fitr   )__name__
__module____qualname____doc__r   rY   r   r   r   r   r      s    Sr   )rE   numpyr4   scipyr   scipy.optimizer   baser   r   _baser   
exceptionsr	   utilsr
   utils.validationr   utils.fixesr   r   r   r   r   r   r   <module>   s   