ó
    Ñ]jr9  ã                   óP   • S SK r S SKrS SKJrJr  S SKJr  S SKJ	r	   " S S5      r
g)é    N)Ú_safe_indexingÚcheck_random_state)Úcheck_matplotlib_support)Ú_validate_style_kwargsc                   óz   • \ rS rSrSrS r SSSSS.S jjr\SSSSSSS	.S
 j5       r\SSSSSSS	.S j5       r	Sr
g)ÚPredictionErrorDisplayé   a  Visualization of the prediction error of a regression model.

This tool can display "residuals vs predicted" or "actual vs predicted"
using scatter plots to qualitatively assess the behavior of a regressor,
preferably on held-out data points.

See the details in the docstrings of
:func:`~sklearn.metrics.PredictionErrorDisplay.from_estimator` or
:func:`~sklearn.metrics.PredictionErrorDisplay.from_predictions` to
create a visualizer. All parameters are stored as attributes.

For general information regarding `scikit-learn` visualization tools, read
more in the :ref:`Visualization Guide <visualizations>`.
For details regarding interpreting these plots, refer to the
:ref:`Model Evaluation Guide <visualization_regression_evaluation>`.

.. versionadded:: 1.2

Parameters
----------
y_true : ndarray of shape (n_samples,)
    True values.

y_pred : ndarray of shape (n_samples,)
    Prediction values.

Attributes
----------
line_ : matplotlib Artist
    Optimal line representing `y_true == y_pred`. Therefore, it is a
    diagonal line for `kind="predictions"` and a horizontal line for
    `kind="residuals"`.

errors_lines_ : matplotlib Artist or None
    Residual lines. If `with_errors=False`, then it is set to `None`.

scatter_ : matplotlib Artist
    Scatter data points.

ax_ : matplotlib Axes
    Axes with the different matplotlib axis.

figure_ : matplotlib Figure
    Figure containing the scatter and lines.

See Also
--------
PredictionErrorDisplay.from_estimator : Prediction error visualization
    given an estimator and some data.
PredictionErrorDisplay.from_predictions : Prediction error visualization
    given the true and predicted targets.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from sklearn.metrics import PredictionErrorDisplay
>>> X, y = load_diabetes(return_X_y=True)
>>> ridge = Ridge().fit(X, y)
>>> y_pred = ridge.predict(X)
>>> display = PredictionErrorDisplay(y_true=y, y_pred=y_pred)
>>> display.plot()
<...>
>>> plt.show()
c                ó   • Xl         X l        g ©N©Úy_trueÚy_pred)Úselfr   r   s      Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/metrics/_plot/regression.pyÚ__init__ÚPredictionErrorDisplay.__init__Q   s   € ØŒØ�ó    NÚresidual_vs_predicted)ÚkindÚscatter_kwargsÚline_kwargsc                óB  • [        U R                  R                   S35        SnX%;  a"  [        SSR	                  U5       SU< S35      eSSKJn  Uc  0 nUc  0 nS	S
S.nSSSS.n[        Xs5      n[        X„5      n0 UEUEn0 UEUEnUc  UR                  5       u  p‘US:X  Ga:  [        [        R                  " U R                  5      [        R                  " U R                  5      5      n
[        [        R                  " U R                  5      [        R                  " U R                  5      5      nUR                  " Xº/Xº/40 UD6S   U l        U R                  U R                  pÜSu  pïUR                   " XÍ40 UD6U l        UR%                  SSS9  UR'                  [        R(                  " XºSS95        UR+                  [        R(                  " XºSS95        OšUR                  " [        R                  " U R                  5      [        R                  " U R                  5      /SS/40 UD6S   U l        UR                   " U R                  U R                  U R                  -
  40 UD6U l        Su  pïUR-                  XïS9  Xl        UR0                  U l        U $ )aã  Plot visualization.

Extra keyword arguments will be passed to matplotlib's ``plot``.

Parameters
----------
ax : matplotlib axes, default=None
    Axes object to plot on. If `None`, a new figure and axes is
    created.

kind : {"actual_vs_predicted", "residual_vs_predicted"},                 default="residual_vs_predicted"
    The type of plot to draw:

    - "actual_vs_predicted" draws the observed values (y-axis) vs.
      the predicted values (x-axis).
    - "residual_vs_predicted" draws the residuals, i.e. difference
      between observed and predicted values, (y-axis) vs. the predicted
      values (x-axis).

scatter_kwargs : dict, default=None
    Dictionary with keywords passed to the `matplotlib.pyplot.scatter`
    call.

line_kwargs : dict, default=None
    Dictionary with keyword passed to the `matplotlib.pyplot.plot`
    call to draw the optimal line.

Returns
-------
display : :class:`~sklearn.metrics.PredictionErrorDisplay`

    Object that stores computed values.
z.plot)Úactual_vs_predictedr   z`kind` must be one of z, z. Got z	 instead.r   Nztab:bluegš™™™™™é?)ÚcolorÚalphaÚblackgffffffæ?z--)r   r   Ú	linestyler   )úPredicted valueszActual valuesÚequalÚdatalim)Ú
adjustableé   )Únum)r   zResiduals (actual - predicted))ÚxlabelÚylabel)r   Ú	__class__Ú__name__Ú
ValueErrorÚjoinÚmatplotlib.pyplotÚpyplotr   ÚsubplotsÚmaxÚnpr   r   ÚminÚplotÚline_ÚscatterÚscatter_Ú
set_aspectÚ
set_xticksÚlinspaceÚ
set_yticksÚsetÚax_ÚfigureÚfigure_)r   Úaxr   r   r   Úexpected_kindÚpltÚdefault_scatter_kwargsÚdefault_line_kwargsÚ_Ú	max_valueÚ	min_valueÚx_dataÚy_datar$   r%   s                   r   r0   ÚPredictionErrorDisplay.plotU   sl  € ôT 	! D§N¡N×$;Ñ$;Ð#<¸EÐ!BÔCàHˆØÓ$ÜØ(¨¯©°=Ó)AÐ(Bð CØ‘h˜ið)óð õ
 	(àÑ!ØˆNØÑØˆKà+5ÀÑ!DÐØ(/¸#ÈDÑQÐä/Ð0FÓWˆÜ,Ð-@ÓNˆàEÐ2ÐE°nÐEˆØ<Ð,Ð<°Ð<ˆà‰:Ø—L‘L“N‰EˆAàÐ(Ô(ÜœBŸFšF 4§;¡;Ó/´·²¸¿¹Ó1DÓEˆIÜœBŸFšF 4§;¡;Ó/´·²¸¿¹Ó1DÓEˆIØŸšØÐ&¨Ð(>ñØBMñàñˆDŒJð "Ÿ[™[¨$¯+©+�FØ@‰NˆFàŸJšJ vÑH¸ÑHˆDŒMð �M‰M˜'¨iˆMÑ8Ø�M‰Mœ"Ÿ+š+ iÀÑBÔCØ�M‰Mœ"Ÿ+š+ iÀÑBÕCàŸšÜ—’˜Ÿ™Ó$¤b§f¢f¨T¯[©[Ó&9Ð:Ø�A�ñð ñð ñ	ˆDŒJð
 ŸJšJØ—‘˜TŸ[™[¨4¯;©;Ñ6ñØ:HñˆDŒMð R‰NˆFà
�‰�fˆÑ,àŒØ—y‘yˆŒàˆr   iè  )r   Ú	subsampleÚrandom_stater<   r   r   c                ó€   • [        U R                   S35        UR                  U5      n
U R                  UU
UUUUUU	S9$ )a[
  Plot the prediction error given a regressor and some data.

For general information regarding `scikit-learn` visualization tools,
read more in the :ref:`Visualization Guide <visualizations>`.
For details regarding interpreting these plots, refer to the
:ref:`Model Evaluation Guide <visualization_regression_evaluation>`.

.. versionadded:: 1.2

Parameters
----------
estimator : estimator instance
    Fitted regressor or a fitted :class:`~sklearn.pipeline.Pipeline`
    in which the last estimator is a regressor.

X : {array-like, sparse matrix} of shape (n_samples, n_features)
    Input values.

y : array-like of shape (n_samples,)
    Target values.

kind : {"actual_vs_predicted", "residual_vs_predicted"},                 default="residual_vs_predicted"
    The type of plot to draw:

    - "actual_vs_predicted" draws the observed values (y-axis) vs.
      the predicted values (x-axis).
    - "residual_vs_predicted" draws the residuals, i.e. difference
      between observed and predicted values, (y-axis) vs. the predicted
      values (x-axis).

subsample : float, int or None, default=1_000
    Sampling the samples to be shown on the scatter plot. If `float`,
    it should be between 0 and 1 and represents the proportion of the
    original dataset. If `int`, it represents the number of samples
    display on the scatter plot. If `None`, no subsampling will be
    applied. by default, 1000 samples or less will be displayed.

random_state : int or RandomState, default=None
    Controls the randomness when `subsample` is not `None`.
    See :term:`Glossary <random_state>` for details.

ax : matplotlib axes, default=None
    Axes object to plot on. If `None`, a new figure and axes is
    created.

scatter_kwargs : dict, default=None
    Dictionary with keywords passed to the `matplotlib.pyplot.scatter`
    call.

line_kwargs : dict, default=None
    Dictionary with keyword passed to the `matplotlib.pyplot.plot`
    call to draw the optimal line.

Returns
-------
display : :class:`~sklearn.metrics.PredictionErrorDisplay`
    Object that stores the computed values.

See Also
--------
PredictionErrorDisplay : Prediction error visualization for regression.
PredictionErrorDisplay.from_predictions : Prediction error visualization
    given the true and predicted targets.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from sklearn.metrics import PredictionErrorDisplay
>>> X, y = load_diabetes(return_X_y=True)
>>> ridge = Ridge().fit(X, y)
>>> disp = PredictionErrorDisplay.from_estimator(ridge, X, y)
>>> plt.show()
z.from_estimator)r   r   r   rG   rH   r<   r   r   )r   r'   ÚpredictÚfrom_predictions)ÚclsÚ	estimatorÚXÚyr   rG   rH   r<   r   r   r   s              r   Úfrom_estimatorÚ%PredictionErrorDisplay.from_estimator½   sX   € ôt 	! C§L¡L >°Ð!AÔBà×"Ñ" 1Ó%ˆà×#Ñ#ØØØØØ%ØØ)Ø#ð $ð 	
ð 		
r   c                ó  • [        U R                   S35        [        U5      n[        U5      n	[	        U[
        R                  5      (       a  US::  a  [        SU S35      eOG[	        U[
        R                  5      (       a(  US::  d  US:¼  a  [        SU S35      e[        X”-  5      nUb=  XI:  a8  UR                  [        R                  " U	5      US9n
[        XSS	9n[        X*SS	9nU " UUS
9nUR                  UUUUS9$ )aï	  Plot the prediction error given the true and predicted targets.

For general information regarding `scikit-learn` visualization tools,
read more in the :ref:`Visualization Guide <visualizations>`.
For details regarding interpreting these plots, refer to the
:ref:`Model Evaluation Guide <visualization_regression_evaluation>`.

.. versionadded:: 1.2

Parameters
----------
y_true : array-like of shape (n_samples,)
    True target values.

y_pred : array-like of shape (n_samples,)
    Predicted target values.

kind : {"actual_vs_predicted", "residual_vs_predicted"},                 default="residual_vs_predicted"
    The type of plot to draw:

    - "actual_vs_predicted" draws the observed values (y-axis) vs.
      the predicted values (x-axis).
    - "residual_vs_predicted" draws the residuals, i.e. difference
      between observed and predicted values, (y-axis) vs. the predicted
      values (x-axis).

subsample : float, int or None, default=1_000
    Sampling the samples to be shown on the scatter plot. If `float`,
    it should be between 0 and 1 and represents the proportion of the
    original dataset. If `int`, it represents the number of samples
    display on the scatter plot. If `None`, no subsampling will be
    applied. by default, 1000 samples or less will be displayed.

random_state : int or RandomState, default=None
    Controls the randomness when `subsample` is not `None`.
    See :term:`Glossary <random_state>` for details.

ax : matplotlib axes, default=None
    Axes object to plot on. If `None`, a new figure and axes is
    created.

scatter_kwargs : dict, default=None
    Dictionary with keywords passed to the `matplotlib.pyplot.scatter`
    call.

line_kwargs : dict, default=None
    Dictionary with keyword passed to the `matplotlib.pyplot.plot`
    call to draw the optimal line.

Returns
-------
display : :class:`~sklearn.metrics.PredictionErrorDisplay`
    Object that stores the computed values.

See Also
--------
PredictionErrorDisplay : Prediction error visualization for regression.
PredictionErrorDisplay.from_estimator : Prediction error visualization
    given an estimator and some data.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import load_diabetes
>>> from sklearn.linear_model import Ridge
>>> from sklearn.metrics import PredictionErrorDisplay
>>> X, y = load_diabetes(return_X_y=True)
>>> ridge = Ridge().fit(X, y)
>>> y_pred = ridge.predict(X)
>>> disp = PredictionErrorDisplay.from_predictions(y_true=y, y_pred=y_pred)
>>> plt.show()
z.from_predictionsr   zWhen an integer, subsample=z should be positive.é   z!When a floating-point, subsample=z should be in the (0, 1) range.)Úsize)Úaxisr   )r<   r   r   r   )r   r'   r   ÚlenÚ
isinstanceÚnumbersÚIntegralr(   ÚRealÚintÚchoicer.   Úaranger   r0   )rL   r   r   r   rG   rH   r<   r   r   Ú	n_samplesÚindicesÚvizs               r   rK   Ú'PredictionErrorDisplay.from_predictions&  s(  € ôl 	! C§L¡L >Ð1BÐ!CÔDä)¨,Ó7ˆä˜“Kˆ	Ü�i¤×!1Ñ!1×2Ñ2Ø˜A‹~Ü Ø1°)°Ð<PÐQóð ð ô ˜	¤7§<¡<×0Ñ0Ø˜A‹~ ¨a£Ü Ø7¸	°{ð C/ð /óð ô ˜IÑ1Ó2ˆIàÑ  YÓ%:Ø"×)Ñ)¬"¯)ª)°IÓ*>ÀYÐ)ÐOˆGÜ# F¸!Ñ<ˆFÜ# F¸!Ñ<ˆFáØØñ
ˆð
 �x‰xØØØ)Ø#ð	 ð 
ð 	
r   )r9   r;   r1   r3   r   r   r   )r'   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r0   ÚclassmethodrP   rK   Ú__static_attributes__© r   r   r   r      s€   † ñAòFð ðfð %ØØöfðP ð %ØØØØØôf
ó ðf
ðP ð %ØØØØØôv
ó óv
r   r   )rX   Únumpyr.   Úsklearn.utilsr   r   Ú$sklearn.utils._optional_dependenciesr   Úsklearn.utils._plottingr   r   rh   r   r   Ú<module>rm      s"   ðó ã ç <Ý IÝ :÷P
ò P
r   