
     h+                         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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            	           e Zd ZU dZ eeddd          g eeddd          gdg eh d	           e ed
h                    gedgdZ	ee
d<   dddd
dddZ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>   revised simplexhighshighs-ds	highs-ipminterior-pointwarnquantilealphafit_interceptsolversolver_options_parameter_constraintsg      ?g      ?Tc                L    || _         || _        || _        || _        || _        d S Nr   )selfr    r!   r"   r#   r$   s         Z/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/linear_model/_quantile.py__init__zQuantileRegressor.__init__   s/     !
*,    c                    |                                   |                     ||g ddd          \  }}t          ||          }|j        d         }|}| j        r|dz  }t          j        |          | j        z  }| j        dk    rt          j
        dt                     d}nG| j        d	v r7t          t          d
          k     rt          d| j         dt                     | j        }|dk    r+t          t          d          k    rt          d| d          t          j        |          r|dvrt          d| j         d          | 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||<   |dv rt          j        |
|j        d          }| j        rOt          j        t          j        |
df|j                            }t          j        ||| | || gd          }nt          j        || || gd          }nmt          j        |
          }| j        r6t          j        |
df          }t          j        ||| | || gd          }nt          j        || || gd          }|}t;          |||||          }|j        }|j        sTddddd }t          j
        d!|j          d"|!                    |j         d#          z   d$z   d%z   |j"        z   tF                     |d|         ||d|z           z
  }|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   zThe 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_valuer-   )dtypeformat)shaper5   )r6   )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   r7   r"   npsumr!   r#   warningsr   FutureWarningr   r   
ValueErrorr   issparser$   nonzerolenr   concatenatefullr    eyer5   
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$   indices	n_indicesr9   rM   rO   r:   r;   resultsolutionfailureparamss                       r)   fitzQuantileRegressor.fit   s   & 	""/// # 
 
1 -]A>>WQZ
 	MH }%%
2;&  M  	   &FF[ 
 
 
 =11117$+ 7 7*47 7  
 [F%%%*h8O8O*O*OO&OOO   ?1 	&0R"R"R2$+ 2 2 2  
 &65E+E+E%t_NN!0N, *]++A.LL	s=)))))'2Mq'**Aq'**ANH777-T]!23
 
  	AaDAhK777
 *YageDDDC! G(	1~QW)U)U)UVV}dAuqb#t%DUSSS}a!S3$%7FFF&##C! Bw	1~..~tQr3&EANNN~q1"cC4&8qAAA"
 
 
 8~ 	-658	 G M/#]/ / /$$V]4DEEF  1	1
 .! #   )8)$x1x<0G'HHz 	"DJ$QiDOODJ!DOr+   r'   )__name__
__module____qualname____doc__r   r   r   r   dictr%   __annotations__r*   re    r+   r)   r   r      s        W Wt XdAq;;;<(4D8889#J    F::vh''((
  ,!$ $D   , - - - - -m m m m m mr+   r   )rE   numbersr   numpyrC   scipyr   scipy.optimizer   baser   r   _baser
   
exceptionsr   utilsr   utils.validationr   utils.fixesr   r   utils._param_validationr   r   r   r   rl   r+   r)   <module>rx      s*                    " " " " " " 0 0 0 0 0 0 0 0       + + + + + + " " " " " " 3 3 3 3 3 3 3 3 3 3 3 3 3 3 B B B B B B B B B Bi i i i i^] i i i i ir+   