§
    rŠtjr9  ã                   óX   — d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	  G d„ d¦  «        Z
dS )é    N)Ú_safe_indexingÚcheck_random_state)Úcheck_matplotlib_support)Ú_validate_style_kwargsc                   óx   — e Zd ZdZd„ Z	 dddddœd„Zedddddddœd	„¦   «         Zedddddddœd
„¦   «         ZdS )ÚPredictionErrorDisplayaé  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                ó"   — || _         || _        d S ©N©Úy_trueÚy_pred)Úselfr   r   s      ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/metrics/_plot/regression.pyÚ__init__zPredictionErrorDisplay.__init__Q   s   € ØˆŒØˆŒˆˆó    NÚresidual_vs_predicted)ÚkindÚscatter_kwargsÚline_kwargsc                ó  — t          | j        j        › d�¦  «         d}||vr)t          dd                     |¦  «        › d|›d�¦  «        ‚ddlm} |€i }|€i }d	d
dœ}ddddœ}t          ||¦  «        }t          ||¦  «        }i |¥|¥}i |¥|¥}|€|                     ¦   «         \  }	}|dk    �r-t          t          j	        | j        ¦  «        t          j	        | j        ¦  «        ¦  «        }
t          t          j        | j        ¦  «        t          j        | j        ¦  «        ¦  «        } |j        ||
g||
gfi |¤Žd         | _        | j        | j        }}d\  }} |j        ||fi |¤Ž| _        |                     dd¬¦  «         |                     t          j        ||
d¬¦  «        ¦  «         |                     t          j        ||
d¬¦  «        ¦  «         nw |j        t          j        | j        ¦  «        t          j	        | j        ¦  «        gddgfi |¤Žd         | _         |j        | j        | j        | j        z
  fi |¤Ž| _        d\  }}|                     ||¬¦  «         || _        |j        | _        | S )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   r.   zPredictionErrorDisplay.plotU   sù  € õT 	! D¤NÔ$;Ð!BÐ!BÐ!BÑCÔCÐCàHˆØ�}Ð$Ð$Ýð)¨¯ª°=Ñ)AÔ)Að )ð )Øð)ð )ð )ñô ð ð
 	(Ð'Ð'Ð'Ð'Ð'àÐ!ØˆNØÐØˆKà+5ÀÐ!DÐ!DÐØ(/¸#ÈDÐQÐQÐå/Ð0FÈÑWÔWˆÝ,Ð-@À+ÑNÔNˆàEÐ2ÐE°nÐEˆØ<Ð,Ð<°Ð<ˆàˆ:Ø—L’L‘N”N‰EˆAˆràÐ(Ò(Ñ(Ý�BœF 4¤;Ñ/Ô/µ´¸¼Ñ1DÔ1DÑEÔEˆIÝ�BœF 4¤;Ñ/Ô/µ´¸¼Ñ1DÔ1DÑEÔEˆIØ ˜œØ˜IÐ&¨°IÐ(>ðð ØBMðð àôˆDŒJð "œ[¨$¬+�FˆFØ@‰NˆF�Fà&˜BœJ v¨vÐHÐH¸ÐHÐHˆDŒMð �MŠM˜'¨iˆMÑ8Ô8Ð8Ø�MŠM�"œ+ i°ÀÐBÑBÔBÑCÔCÐCØ�MŠM�"œ+ i°ÀÐBÑBÔBÑCÔCÐCÐCà ˜œÝ”˜œÑ$Ô$¥b¤f¨T¬[Ñ&9Ô&9Ð:Ø�A�ðð ð ðð ð ô	ˆDŒJð
 '˜BœJØ”˜Tœ[¨4¬;Ñ6ðð Ø:Hðð ˆDŒMð R‰NˆF�Fà
�Š�f VˆÑ,Ô,Ð,àˆŒØ”yˆŒàˆr   iè  )r   Ú	subsampleÚrandom_stater:   r   r   c          
      ó”   — t          | j        › d�¦  «         |                     |¦  «        }
|                      ||
||||||	¬¦  «        S )a3  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   rD   rE   r:   r   r   )r   r%   ÚpredictÚfrom_predictions)ÚclsÚ	estimatorÚXÚyr   rD   rE   r:   r   r   r   s              r   Úfrom_estimatorz%PredictionErrorDisplay.from_estimator½   sf   € õt 	! C¤LÐ!AÐ!AÐ!AÑBÔBÐBà×"Ò" 1Ñ%Ô%ˆà×#Ò#ØØØØØ%ØØ)Ø#ð $ñ 	
ô 	
ð 		
r   c                ó`  — t          | j        › d�¦  «         t          |¦  «        }t          |¦  «        }	t	          |t
          j        ¦  «        r|dk    rt          d|› d�¦  «        ‚nKt	          |t
          j        ¦  «        r1|dk    s|dk    rt          d|› d�¦  «        ‚t          |	|z  ¦  «        }|�S||	k     rM| 
                    t          j        |	¦  «        |¬	¦  «        }
t          ||
d¬
¦  «        }t          ||
d¬
¦  «        } | ||¬¦  «        }|                     ||||¬¦  «        S )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.N)Úsize)Úaxisr   )r:   r   r   r   )r   r%   r   ÚlenÚ
isinstanceÚnumbersÚIntegralr&   ÚRealÚintÚchoicer,   Úaranger   r.   )rI   r   r   r   rD   rE   r:   r   r   Ú	n_samplesÚindicesÚvizs               r   rH   z'PredictionErrorDisplay.from_predictions&  s{  € õl 	! C¤LÐ!CÐ!CÐ!CÑDÔDÐDå)¨,Ñ7Ô7ˆå˜‘K”Kˆ	Ý�i¥Ô!1Ñ2Ô2ð 	3Ø˜AŠ~ˆ~Ý ØQ°)ÐQÐQÐQñô ð ð õ ˜	¥7¤<Ñ0Ô0ð 	3Ø˜AŠ~ˆ~ ¨a¢ Ý ð/¸	ð /ð /ð /ñô ð õ ˜I¨	Ñ1Ñ2Ô2ˆIàÐ  Y°Ò%:Ð%:Ø"×)Ò)­"¬)°IÑ*>Ô*>ÀYÐ)ÑOÔOˆGÝ# F¨G¸!Ð<Ñ<Ô<ˆFÝ# F¨G¸!Ð<Ñ<Ô<ˆFàˆcØØð
ñ 
ô 
ˆð
 �xŠxØØØ)Ø#ð	 ñ 
ô 
ð 	
r   r
   )	r%   Ú
__module__Ú__qualname__Ú__doc__r   r.   ÚclassmethodrM   rH   © r   r   r   r      sä   € € € € € ðAð AðFð ð ð ðfð %ØØðfð fð fð fð fðP ð %ØØØØØðf
ð f
ð f
ð f
ñ „[ðf
ðP ð %ØØØØØðv
ð v
ð v
ð v
ñ „[ðv
ð v
ð v
r   r   )rT   Únumpyr,   Úsklearn.utilsr   r   Ú$sklearn.utils._optional_dependenciesr   Úsklearn.utils._plottingr   r   ra   r   r   ú<module>rf      s”   ðð €€€à Ð Ð Ð à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø IÐ IÐ IÐ IÐ IÐ IØ :Ð :Ð :Ð :Ð :Ð :ðP
ð P
ð P
ð P
ð P
ñ P
ô P
ð P
ð P
ð P
r   