§
    qŠtjó�  ã                   ó>  — d 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mZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z- dgZ.d„ Z/d„ Z0	 d,d„Z1 e& e"ddg¦  «         e"ddg¦  «         e"ddg¦  «        gddgde#e2gddgddgddg e%h d£¦  «        ge3g e$e#ddd¬ ¦  «        g e%h d!£¦  «        g e%h d"£¦  «        ge4dgd#œd$¬%¦  «        dddd&d'd(dd&d)d*œ	d+„¦   «         Z5dS )-zBPartial dependence plots for regression and classification models.é    )ÚIterableN)Úsparse)Ú
mquantiles)Úis_classifierÚis_regressor)ÚRandomForestRegressor)ÚBaseGradientBoosting)ÚBaseHistGradientBoosting)Ú_check_feature_namesÚ_get_feature_index)ÚDecisionTreeRegressor)ÚBunchÚ_safe_indexingÚcheck_array)Ú_determine_key_typeÚ_get_column_indicesÚ_safe_assign)Úcheck_matplotlib_support)Ú
HasMethodsÚIntegralÚIntervalÚ
StrOptionsÚvalidate_params)Ú_get_response_values)Ú	cartesian)Ú_check_sample_weightÚcheck_is_fittedÚpartial_dependencec                 ó˜  ‡— t          |t          ¦  «        rt          |¦  «        dk    rt          d¦  «        ‚t	          d„ |D ¦   «         ¦  «        st          d¦  «        ‚|d         |d         k    rt          d¦  «        ‚|dk    rt          d¦  «        ‚d	„ Šˆfd
„|                     ¦   «         D ¦   «         }t          d„ |                     ¦   «         D ¦   «         ¦  «        rCd                     d„ |                     ¦   «         D ¦   «         ¦  «        }t          d|› �¦  «        ‚g }t          |¦  «        D �] \  }}||v r	||         }	nØ	 t          j        t          | |d¬¦  «        ¦  «        }
n&# t          $ r}t          d|› d�¦  «        |‚d}~ww xY w|s|
j        d         |k     r|
}	nvt          t          | |d¬¦  «        |d¬¦  «        }t          j        |d         |d         ¦  «        rt          d¦  «        ‚t          j        |d         |d         |d¬¦  «        }	|                     |	¦  «         �Œt'          |¦  «        |fS )a!  Generate a grid of points based on the percentiles of X.

    The grid is a cartesian product between the columns of ``values``. The
    ith column of ``values`` consists in ``grid_resolution`` equally-spaced
    points between the percentiles of the jth column of X.

    If ``grid_resolution`` is bigger than the number of unique values in the
    j-th column of X or if the feature is a categorical feature (by inspecting
    `is_categorical`) , then those unique values will be used instead.

    Parameters
    ----------
    X : array-like of shape (n_samples, n_target_features)
        The data.

    percentiles : tuple of float
        The percentiles which are used to construct the extreme values of
        the grid. Must be in [0, 1].

    is_categorical : list of bool
        For each feature, tells whether it is categorical or not. If a feature
        is categorical, then the values used will be the unique ones
        (i.e. categories) instead of the percentiles.

    grid_resolution : int
        The number of equally spaced points to be placed on the grid for each
        feature.

    custom_values: dict
        Mapping from column index of X to an array-like of values where
        the partial dependence should be calculated for that feature

    Returns
    -------
    grid : ndarray of shape (n_points, n_target_features)
        A value for each feature at each point in the grid. ``n_points`` is
        always ``<= grid_resolution ** X.shape[1]``.

    values : list of 1d ndarrays
        The values with which the grid has been created. The size of each
        array ``values[j]`` is either ``grid_resolution``, the number of
        unique values in ``X[:, j]``, if j is not in ``custom_range``.
        If j is in ``custom_range``, then it is the length of ``custom_range[j]``.
    é   z/'percentiles' must be a sequence of 2 elements.c              3   ó6   K  — | ]}d |cxk    odk    nc V — ŒdS )r   é   N© )Ú.0Úxs     úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/inspection/_partial_dependence.pyú	<genexpr>z_grid_from_X.<locals>.<genexpr>Z   s6   è è € Ð0Ð0˜qˆq�Aˆ{ˆ{Š{ˆ{˜Š{ˆ{ˆ{ˆ{Ð0Ð0Ð0Ð0Ð0Ð0ó    z''percentiles' values must be in [0, 1].r   r"   z9percentiles[0] must be strictly less than percentiles[1].z2'grid_resolution' must be strictly greater than 1.c                 ór   — t          d„ | D ¦   «         ¦  «        rt          nd }t          j        | |¬¦  «        S )Nc              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S ©N)Ú
isinstanceÚstr©r$   Úvs     r&   r'   z?_grid_from_X.<locals>._convert_custom_values.<locals>.<genexpr>d   s,   è è € ÐAÐA°Q�j¨­CÑ0Ô0ÐAÐAÐAÐAÐAÐAr(   )Údtype)ÚanyÚobjectÚnpÚasarray)Úvaluesr0   s     r&   Ú_convert_custom_valuesz,_grid_from_X.<locals>._convert_custom_valuesb   s<   € åÐAÐA¸&ÐAÑAÔAÑAÔAÐK•�ÀtˆÝŒz˜&¨Ð.Ñ.Ô.Ð.r(   c                 ó.   •— i | ]\  }}| ‰|¦  «        “ŒS r#   r#   )r$   Úkr/   r6   s      €r&   ú
<dictcomp>z _grid_from_X.<locals>.<dictcomp>g   s+   ø€ ÐTÐTÐT±d°a¸�QÐ.Ð.¨qÑ1Ô1ÐTÐTÐTr(   c              3   ó,   K  — | ]}|j         d k    V — ŒdS )r"   N©Úndimr.   s     r&   r'   z_grid_from_X.<locals>.<genexpr>h   s(   è è € Ð
7Ð
7˜1ˆ1Œ6�QŠ;Ð
7Ð
7Ð
7Ð
7Ð
7Ð
7r(   ú, c              3   óN   K  — | ] \  }}|j         d k    ¯d|› d|j         › d�V — Œ!dS )r"   zFeature z: z dimensionsNr;   )r$   r8   r/   s      r&   r'   z_grid_from_X.<locals>.<genexpr>i   sO   è è € ð !
ð !
á��1ØŒv˜Š{ˆ{ð 0�qÐ/Ð/˜AœFÐ/Ð/Ð/àˆ{ˆ{ˆ{ð!
ð !
r(   zBThe custom grid for some features is not a one-dimensional array. ©ÚaxiszThe column #zØ contains mixed data types. Finding unique categories fail due to sorting. It usually means that the column contains `np.nan` values together with `str` categories. Such use case is not yet supported in scikit-learn.N)Úprobr@   ztpercentiles are too close to each other, unable to build the grid. Please choose percentiles that are further apart.T)ÚnumÚendpoint)r,   r   ÚlenÚ
ValueErrorÚallÚitemsr1   r5   ÚjoinÚ	enumerater3   Úuniquer   Ú	TypeErrorÚshaper   ÚallcloseÚlinspaceÚappendr   )ÚXÚpercentilesÚis_categoricalÚgrid_resolutionÚcustom_valuesÚerror_stringr5   ÚfeatureÚis_catr@   ÚuniquesÚexcÚemp_percentilesr6   s                @r&   Ú_grid_from_Xr[   +   sù  ø€ õZ �k¥8Ñ,Ô,ð Lµ°KÑ0@Ô0@ÀAÒ0EÐ0EÝÐJÑKÔKÐKÝÐ0Ð0 KÐ0Ñ0Ô0Ñ0Ô0ð DÝÐBÑCÔCÐCØ�1„~˜ QœÒ'Ð'ÝÐTÑUÔUÐUà˜!ÒÐÝÐMÑNÔNÐNð/ð /ð /ð
 UÐTÐTÐT¸m×>QÒ>QÑ>SÔ>SÐTÑTÔT€MÝ
Ð
7Ð
7 × 4Ò 4Ñ 6Ô 6Ð
7Ñ
7Ô
7Ñ7Ô7ð 

Ø—y’yð !
ð !
à%×+Ò+Ñ-Ô-ð!
ñ !
ô !
ñ 
ô 
ˆõ ðØðð ñ
ô 
ð 	
ð
 €Fõ % ^Ñ4Ô4ð 'ñ '‰ˆ�Ø�mÐ#Ð#à  Ô)ˆDˆDð
Ýœ)¥N°1°gÀAÐ$FÑ$FÔ$FÑGÔG��øÝð ð ð õ !ðA 7ð Að Að Añô ð
 ðøøøøðøøøð ð ˜œ qÔ)¨OÒ;Ð;ð ��õ #-Ý" 1 g°AÐ6Ñ6Ô6¸[Èqð#ñ #ô #�õ ”;˜¨qÔ1°?À1Ô3EÑFÔFð Ý$ð2ñô ð õ
 ”{Ø# AÔ&Ø# AÔ&Ø'Ø!ð	ñ ô �ð 	�Š�dÑÔÐÑå�VÑÔ˜fÐ$Ð$s   Å$E2Å2
FÅ<FÆFc                 ót   — |                       ||¦  «        }|j        dk    r|                     dd¦  «        }|S )a}	  Calculate partial dependence via the recursion method.

    The recursion method is in particular enabled for tree-based estimators.

    For each `grid` value, a weighted tree traversal is performed: if a split node
    involves an input feature of interest, the corresponding left or right branch
    is followed; otherwise both branches are followed, each branch being weighted
    by the fraction of training samples that entered that branch. Finally, the
    partial dependence is given by a weighted average of all the visited leaves
    values.

    This method is more efficient in terms of speed than the `'brute'` method
    (:func:`~sklearn.inspection._partial_dependence._partial_dependence_brute`).
    However, here, the partial dependence computation is done explicitly with the
    `X` used during training of `est`.

    Parameters
    ----------
    est : BaseEstimator
        A fitted estimator object implementing :term:`predict` or
        :term:`decision_function`. Multioutput-multiclass classifiers are not
        supported. Note that `'recursion'` is only supported for some tree-based
        estimators (namely
        :class:`~sklearn.ensemble.GradientBoostingClassifier`,
        :class:`~sklearn.ensemble.GradientBoostingRegressor`,
        :class:`~sklearn.ensemble.HistGradientBoostingClassifier`,
        :class:`~sklearn.ensemble.HistGradientBoostingRegressor`,
        :class:`~sklearn.tree.DecisionTreeRegressor`,
        :class:`~sklearn.ensemble.RandomForestRegressor`,
        ).

    grid : array-like of shape (n_points, n_target_features)
        The grid of feature values for which the partial dependence is calculated.
        Note that `n_points` is the number of points in the grid and `n_target_features`
        is the number of features you are doing partial dependence at.

    features : array-like of {int, str}
        The feature (e.g. `[0]`) or pair of interacting features
        (e.g. `[(0, 1)]`) for which the partial dependency should be computed.

    Returns
    -------
    averaged_predictions : array-like of shape (n_targets, n_points)
        The averaged predictions for the given `grid` of features values.
        Note that `n_targets` is the number of targets (e.g. 1 for binary
        classification, `n_tasks` for multi-output regression, and `n_classes` for
        multiclass classification) and `n_points` is the number of points in the `grid`.
    r"   éÿÿÿÿ)Ú%_compute_partial_dependence_recursionr<   Úreshape)ÚestÚgridÚfeaturesÚaveraged_predictionss       r&   Ú_partial_dependence_recursionrd   £   sG   € ðb ×DÒDÀTÈ8ÑTÔTÐØÔ  AÒ%Ð%ð  4×;Ò;¸A¸rÑBÔBÐàÐr(   c                 ó  — g }g }|dk    rt          | ¦  «        rdnddg}|                     ¦   «         }|D ]ƒ}	t          |¦  «        D ]\  }
}t          ||	|
         |¬¦  «         Œt	          | ||¬¦  «        \  }}|                     |¦  «         |                     t          j        |d|¬¦  «        ¦  «         Œ„|j        d         }t          j	        |¦  «        j
        }t          | ¦  «        r"|j        d	k    r|                     |d
¦  «        }n>t          | ¦  «        r/|j        d         d	k    r|d         }|                     |d
¦  «        }t          j	        |¦  «        j
        }|j        dk    r|                     dd
¦  «        }||fS )a&  Calculate partial dependence via the brute force method.

    The brute method explicitly averages the predictions of an estimator over a
    grid of feature values.

    For each `grid` value, all the samples from `X` have their variables of
    interest replaced by that specific `grid` value. The predictions are then made
    and averaged across the samples.

    This method is slower than the `'recursion'`
    (:func:`~sklearn.inspection._partial_dependence._partial_dependence_recursion`)
    version for estimators with this second option. However, with the `'brute'`
    force method, the average will be done with the given `X` and not the `X`
    used during training, as it is done in the `'recursion'` version. Therefore
    the average can always accept `sample_weight` (even when the estimator was
    fitted without).

    Parameters
    ----------
    est : BaseEstimator
        A fitted estimator object implementing :term:`predict`,
        :term:`predict_proba`, or :term:`decision_function`.
        Multioutput-multiclass classifiers are not supported.

    grid : array-like of shape (n_points, n_target_features)
        The grid of feature values for which the partial dependence is calculated.
        Note that `n_points` is the number of points in the grid and `n_target_features`
        is the number of features you are doing partial dependence at.

    features : array-like of {int, str}
        The feature (e.g. `[0]`) or pair of interacting features
        (e.g. `[(0, 1)]`) for which the partial dependency should be computed.

    X : array-like of shape (n_samples, n_features)
        `X` is used to generate values for the complement features. That is, for
        each value in `grid`, the method will average the prediction of each
        sample from `X` having that grid value for `features`.

    response_method : {'auto', 'predict_proba', 'decision_function'},             default='auto'
        Specifies whether to use :term:`predict_proba` or
        :term:`decision_function` as the target response. For regressors
        this parameter is ignored and the response is always the output of
        :term:`predict`. By default, :term:`predict_proba` is tried first
        and we revert to :term:`decision_function` if it doesn't exist.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights are used to calculate weighted means when averaging the
        model output. If `None`, then samples are equally weighted. Note that
        `sample_weight` does not change the individual predictions.

    Returns
    -------
    averaged_predictions : array-like of shape (n_targets, n_points)
        The averaged predictions for the given `grid` of features values.
        Note that `n_targets` is the number of targets (e.g. 1 for binary
        classification, `n_tasks` for multi-output regression, and `n_classes` for
        multiclass classification) and `n_points` is the number of points in the `grid`.

    predictions : array-like
        The predictions for the given `grid` of features values over the samples
        from `X`. For non-multioutput regression and binary classification the
        shape is `(n_instances, n_points)` and for multi-output regression and
        multiclass classification the shape is `(n_targets, n_instances, n_points)`,
        where `n_targets` is the number of targets (`n_tasks` for multi-output
        regression, and `n_classes` for multiclass classification), `n_instances`
        is the number of instances in `X`, and `n_points` is the number of points
        in the `grid`.
    ÚautoÚpredictÚpredict_probaÚdecision_function)Úcolumn_indexer)Úresponse_methodr   )r@   Úweightsr    r]   r"   )r   ÚcopyrI   r   r   rO   r3   ÚaveragerL   ÚarrayÚTr<   r_   r   )r`   ra   rb   rP   rk   Úsample_weightÚpredictionsrc   ÚX_evalÚ
new_valuesÚiÚvariableÚpredÚ_Ú	n_sampless                  r&   Ú_partial_dependence_bruterz   Ý   sÅ  € ðP €KØÐà˜&Ò Ð å% cÑ*Ô*ÐVˆIˆI°ÐBUÐ0Vð 	ð �VŠV‰XŒX€FØð Uð Uˆ
Ý$ XÑ.Ô.ð 	Ið 	I‰KˆAˆxÝ˜ ¨A¤¸xÐHÑHÔHÐHÐHõ ' s¨FÀOÐTÑTÔT‰ˆˆaà×Ò˜4Ñ Ô Ð à×#Ò#¥B¤J¨t¸!À]Ð$SÑ$SÔ$SÑTÔTÐTÐTà”˜”
€Iõ ”(˜;Ñ'Ô'Ô)€KÝ�CÑÔð 9˜[Ô-°Ò2Ð2à!×)Ò)¨)°RÑ8Ô8ˆˆÝ	�sÑ	Ô	ð 9 Ô 1°!Ô 4¸Ò 9Ð 9ð " !”nˆØ!×)Ò)¨)°RÑ8Ô8ˆõ œ8Ð$8Ñ9Ô9Ô;ÐØÔ  AÒ%Ð%ð  4×;Ò;¸A¸rÑBÔBÐà Ð,Ð,r(   Úfitrg   rh   ri   z
array-likezsparse matrix>   rf   rh   ri   r"   Úleft)Úclosed>   rf   ÚbruteÚ	recursion>   Úbothrn   Ú
individual)Ú	estimatorrP   rb   rq   Úcategorical_featuresÚfeature_namesrk   rQ   rS   ÚmethodÚkindrT   T)Úprefer_skip_nested_validationrf   )gš™™™™™©?gffffffî?éd   rn   )	rq   rƒ   r„   rk   rQ   rS   rT   r…   r†   c       	         ó°	  ‡‡‡	‡— t          | ¦  «         t          | ¦  «        st          | ¦  «        st          d¦  «        ‚t          | ¦  «        r4t	          | j        d         t          j        ¦  «        rt          d¦  «        ‚t          |d¦  «        s+t          j
        |¦  «        st          |dt          ¬¦  «        }t          | ¦  «        r|dk    rt          d¦  «        ‚|d	k    r|
d
k    rt          d¦  «        ‚d}
|
d
k    r|�t          d¦  «        ‚|
dk    rK|�d}
nFt	          | t          ¦  «        r
| j        €d
}
n't	          | t          t           t"          f¦  «        rd
}
nd}
|
d
k    r€t	          | t          t          t           t"          f¦  «        s7d}t          d                     d                     |¦  «        ¦  «        ¦  «        ‚|dk    rd}|dk    rt          d|› d�¦  «        ‚|�t)          ||¦  «        }t+          |d¬¦  «        dk    rHt          j        t          j        |d¦  «        ¦  «        r!t          d|j        d         dz
  › d�¦  «        ‚t          j        t5          ||¦  «        t          j        d¬¦  «                             ¦   «         }t;          |‰¦  «        Š|j        d         }‰€dgt=          |¦  «        z  }n¶t          j        ‰¦  «        Š‰j        dk    rt          d¦  «        ‚‰j         j!        dk    r5‰j        |k    rt          d‰j        › d |› d!�¦  «        ‚ˆfd"„|D ¦   «         }nC‰j         j!        d#v rˆfd$„‰D ¦   «         Šˆfd%„|D ¦   «         }nt          d&‰j         › d'�¦  «        ‚‰	pi Š	t	          |tD          tF          f¦  «        r|g}tI          |||¦  «        D ]:\  }}}|rŒ	tK          ||d¬(¦  «        j         j!        d)v rt          d*|›d+�¦  «        ‚Œ;tK          ||d¬(¦  «        }ˆ	fd,„tM          |¦  «        D ¦   «         }tO          |||||¦  «        \  }}|
dk    r<tQ          | |||||¦  «        \  }} |j)        d-|j        d         gd.„ |D ¦   «         ¢R Ž }ntU          | ||¦  «        } |j)        d-gd/„ |D ¦   «         ¢R Ž }tW          |¬0¦  «        }|d	k    r||d	<   n|d1k    r||d1<   n
||d	<   ||d1<   |S )2a™#  Partial dependence of ``features``.

    Partial dependence of a feature (or a set of features) corresponds to
    the average response of an estimator for each possible value of the
    feature.

    Read more in
    :ref:`sphx_glr_auto_examples_inspection_plot_partial_dependence.py`
    and the :ref:`User Guide <partial_dependence>`.

    .. warning::

        For :class:`~sklearn.ensemble.GradientBoostingClassifier` and
        :class:`~sklearn.ensemble.GradientBoostingRegressor`, the
        `'recursion'` method (used by default) will not account for the `init`
        predictor of the boosting process. In practice, this will produce
        the same values as `'brute'` up to a constant offset in the target
        response, provided that `init` is a constant estimator (which is the
        default). However, if `init` is not a constant estimator, the
        partial dependence values are incorrect for `'recursion'` because the
        offset will be sample-dependent. It is preferable to use the `'brute'`
        method. Note that this only applies to
        :class:`~sklearn.ensemble.GradientBoostingClassifier` and
        :class:`~sklearn.ensemble.GradientBoostingRegressor`, not to
        :class:`~sklearn.ensemble.HistGradientBoostingClassifier` and
        :class:`~sklearn.ensemble.HistGradientBoostingRegressor`.

    Parameters
    ----------
    estimator : BaseEstimator
        A fitted estimator object implementing :term:`predict`,
        :term:`predict_proba`, or :term:`decision_function`.
        Multioutput-multiclass classifiers are not supported.

    X : {array-like, sparse matrix or dataframe} of shape (n_samples, n_features)
        ``X`` is used to generate a grid of values for the target
        ``features`` (where the partial dependence will be evaluated), and
        also to generate values for the complement features when the
        `method` is 'brute'.

    features : array-like of {int, str, bool} or int or str
        The feature (e.g. `[0]`) or pair of interacting features
        (e.g. `[(0, 1)]`) for which the partial dependency should be computed.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights are used to calculate weighted means when averaging the
        model output. If `None`, then samples are equally weighted. If
        `sample_weight` is not `None`, then `method` will be set to `'brute'`.
        Note that `sample_weight` is ignored for `kind='individual'`.

        .. versionadded:: 1.3

    categorical_features : array-like of shape (n_features,) or shape             (n_categorical_features,), dtype={bool, int, str}, default=None
        Indicates the categorical features.

        - `None`: no feature will be considered categorical;
        - boolean array-like: boolean mask of shape `(n_features,)`
            indicating which features are categorical. Thus, this array has
            the same shape has `X.shape[1]`;
        - integer or string array-like: integer indices or strings
            indicating categorical features.

        .. versionadded:: 1.2

    feature_names : array-like of shape (n_features,), dtype=str, default=None
        Name of each feature; `feature_names[i]` holds the name of the feature
        with index `i`.
        By default, the name of the feature corresponds to their numerical
        index for NumPy array and their column name for pandas dataframe.

        .. versionadded:: 1.2

    response_method : {'auto', 'predict_proba', 'decision_function'},             default='auto'
        Specifies whether to use :term:`predict_proba` or
        :term:`decision_function` as the target response. For regressors
        this parameter is ignored and the response is always the output of
        :term:`predict`. By default, :term:`predict_proba` is tried first
        and we revert to :term:`decision_function` if it doesn't exist. If
        ``method`` is 'recursion', the response is always the output of
        :term:`decision_function`.

    percentiles : tuple of float, default=(0.05, 0.95)
        The lower and upper percentile used to create the extreme values
        for the grid. Must be in [0, 1].
        This parameter is overridden by `custom_values` if that parameter is set.

    grid_resolution : int, default=100
        The number of equally spaced points on the grid, for each target
        feature.
        This parameter is overridden by `custom_values` if that parameter is set.

    custom_values : dict
        A dictionary mapping the index of an element of `features` to an array
        of values where the partial dependence should be calculated
        for that feature. Setting a range of values for a feature overrides
        `grid_resolution` and `percentiles`.

        See :ref:`how to use partial_dependence
        <plt_partial_dependence_custom_values>` for an example of how this parameter can
        be used.

        .. versionadded:: 1.7

    method : {'auto', 'recursion', 'brute'}, default='auto'
        The method used to calculate the averaged predictions:

        - `'recursion'` is only supported for some tree-based estimators
          (namely
          :class:`~sklearn.ensemble.GradientBoostingClassifier`,
          :class:`~sklearn.ensemble.GradientBoostingRegressor`,
          :class:`~sklearn.ensemble.HistGradientBoostingClassifier`,
          :class:`~sklearn.ensemble.HistGradientBoostingRegressor`,
          :class:`~sklearn.tree.DecisionTreeRegressor`,
          :class:`~sklearn.ensemble.RandomForestRegressor`,
          ) when `kind='average'`.
          This is more efficient in terms of speed.
          With this method, the target response of a
          classifier is always the decision function, not the predicted
          probabilities. Since the `'recursion'` method implicitly computes
          the average of the Individual Conditional Expectation (ICE) by
          design, it is not compatible with ICE and thus `kind` must be
          `'average'`.

        - `'brute'` is supported for any estimator, but is more
          computationally intensive.

        - `'auto'`: the `'recursion'` is used for estimators that support it,
          and `'brute'` is used otherwise. If `sample_weight` is not `None`,
          then `'brute'` is used regardless of the estimator.

        Please see :ref:`this note <pdp_method_differences>` for
        differences between the `'brute'` and `'recursion'` method.

    kind : {'average', 'individual', 'both'}, default='average'
        Whether to return the partial dependence averaged across all the
        samples in the dataset or one value per sample or both.
        See Returns below.

        Note that the fast `method='recursion'` option is only available for
        `kind='average'` and `sample_weights=None`. Computing individual
        dependencies and doing weighted averages requires using the slower
        `method='brute'`.

        .. versionadded:: 0.24

    Returns
    -------
    predictions : :class:`~sklearn.utils.Bunch`
        Dictionary-like object, with the following attributes.

        individual : ndarray of shape (n_outputs, n_instances,                 len(values[0]), len(values[1]), ...)
            The predictions for all the points in the grid for all
            samples in X. This is also known as Individual
            Conditional Expectation (ICE).
            Only available when `kind='individual'` or `kind='both'`.

        average : ndarray of shape (n_outputs, len(values[0]),                 len(values[1]), ...)
            The predictions for all the points in the grid, averaged
            over all samples in X (or over the training data if
            `method` is 'recursion').
            Only available when `kind='average'` or `kind='both'`.

        grid_values : seq of 1d ndarrays
            The values with which the grid has been created. The generated
            grid is a cartesian product of the arrays in `grid_values` where
            `len(grid_values) == len(features)`. The size of each array
            `grid_values[j]` is either `grid_resolution`, or the number of
            unique values in `X[:, j]`, whichever is smaller.

            .. versionadded:: 1.3

        `n_outputs` corresponds to the number of classes in a multi-class
        setting, or to the number of tasks for multi-output regression.
        For classical regression and binary classification `n_outputs==1`.
        `n_values_feature_j` corresponds to the size `grid_values[j]`.

    See Also
    --------
    PartialDependenceDisplay.from_estimator : Plot Partial Dependence.
    PartialDependenceDisplay : Partial Dependence visualization.

    Examples
    --------
    >>> X = [[0, 0, 2], [1, 0, 0]]
    >>> y = [0, 1]
    >>> from sklearn.ensemble import GradientBoostingClassifier
    >>> gb = GradientBoostingClassifier(random_state=0).fit(X, y)
    >>> partial_dependence(gb, features=[0], X=X, percentiles=(0, 1),
    ...                    grid_resolution=2) # doctest: +SKIP
    (array([[-4.52,  4.52]]), [array([ 0.,  1.])])
    z5'estimator' must be a fitted regressor or classifier.r   z3Multiclass-multioutput estimators are not supportedÚ	__array__z	allow-nan)Úensure_all_finiter0   rf   zKThe response_method parameter is ignored for regressors and must be 'auto'.rn   r   zCThe 'recursion' method only applies when 'kind' is set to 'average'r~   NzFThe 'recursion' method can only be applied when sample_weight is None.)ÚGradientBoostingClassifierÚGradientBoostingRegressorÚHistGradientBoostingClassifierÚHistGradientBoostingRegressorr�   r   r   z[Only the following estimators support the 'recursion' method: {}. Try using method='brute'.r=   ri   zRWith the 'recursion' method, the response_method must be 'decision_function'. Got ú.F)Úaccept_sliceÚintzall features must be in [0, r"   ú]ÚC)r0   Úorderz�Passing an empty list (`[]`) to `categorical_features` is not supported. Use `None` instead to indicate that there are no categorical features.ÚbzeWhen `categorical_features` is a boolean array-like, the array should be of shape (n_features,). Got z elements while `X` contains z
 features.c                 ó    •— g | ]
}‰|         ‘ŒS r#   r#   )r$   Úidxrƒ   s     €r&   ú
<listcomp>z&partial_dependence.<locals>.<listcomp>¶  s   ø€ ÐTÐTÐT¸CÐ2°3Ô7ÐTÐTÐTr(   )ru   ÚOÚUc                 ó2   •— g | ]}t          |‰¬ ¦  «        ‘ŒS ))r„   )r   )r$   Úcatr„   s     €r&   r™   z&partial_dependence.<locals>.<listcomp>¹  s6   ø€ ð (ð (ð (àõ # 3°mÐDÑDÔDð(ð (ð (r(   c                 ó   •— g | ]}|‰v ‘ŒS r#   r#   )r$   r˜   Úcategorical_features_idxs     €r&   r™   z&partial_dependence.<locals>.<listcomp>½  s,   ø€ ð ð ð Ø47�Ð/Ð/ðð ð r(   zXExpected `categorical_features` to be an array-like of boolean, integer, or string. Got z	 instead.r?   ÚiuzThe column a   contains integer data. Partial dependence plots are not supported for integer data: this can lead to implicit rounding with NumPy arrays or even errors with newer pandas versions. Please convert numerical features to floating point dtypes ahead of time to avoid problems.c                 óJ   •— i | ]\  }}|‰v ¯	|‰                      |¦  «        “Œ S r#   )Úget)r$   ÚindexrV   rT   s      €r&   r9   z&partial_dependence.<locals>.<dictcomp>Ù  sB   ø€ ð "ð "ð "áˆE�7Ø�mÐ#Ð#ð 	ˆ}× Ò  Ñ)Ô)à#Ð#Ð#r(   r]   c                 ó(   — g | ]}|j         d          ‘ŒS ©r   ©rL   ©r$   Úvals     r&   r™   z&partial_dependence.<locals>.<listcomp>ï  s   € Ð=Ð=Ð=¨s˜cœi¨œlÐ=Ð=Ð=r(   c                 ó(   — g | ]}|j         d          ‘ŒS r¥   r¦   r§   s     r&   r™   z&partial_dependence.<locals>.<listcomp>ù  s   € Ð-Ð-Ð-˜sˆcŒi˜ŒlÐ-Ð-Ð-r(   )Úgrid_valuesr�   ),r   r   r   rE   r,   Úclasses_r3   ÚndarrayÚhasattrr   Úissparser   r2   r	   Úinitr
   r   r   ÚformatrH   r   r   r1   ÚlessrL   r4   r   ÚintpÚravelr   rD   Úsizer0   r†   r-   r’   Úzipr   rI   r[   rz   r_   rd   r   )r‚   rP   rb   rq   rƒ   r„   rk   rQ   rS   rT   r…   r†   Úsupported_classes_recursionÚfeatures_indicesÚ
n_featuresrR   Úfeature_idxrV   rW   ÚX_subsetÚcustom_values_for_X_subsetra   r5   rc   rr   Úpdp_resultsrŸ   s       ``   `                @r&   r   r   ]  sÂ  øøøø€ õN �IÑÔÐå˜)Ñ$Ô$ð R­°YÑ(?Ô(?ð RÝÐPÑQÔQÐQå�YÑÔð P¥J¨yÔ/AÀ!Ô/DÅbÄjÑ$QÔ$Qð PÝÐNÑOÔOÐOõ �A�{Ñ#Ô#ð H¥v¤°qÑ'9Ô'9ð HÝ˜¨[ÅÐGÑGÔGˆå�IÑÔð 
 ?°fÒ#<Ð#<Ýðñ
ô 
ð 	
ð
 ˆyÒÐØ�[Ò Ð ÝØUñô ð ð ˆà�ÒÐ Ð!:ÝØTñ
ô 
ð 	
ð �ÒÐØÐ$ØˆFˆFÝ˜	Õ#7Ñ8Ô8ð 	¸Y¼^Ð=SØ ˆFˆFÝØÝ%Õ'<Õ>SÐTñ
ô 
ð 	ð !ˆFˆFàˆFà�ÒÐÝØå$Ý(Ý%Ý%ð	ñ
ô 
ð 	ð+Ð'õ ð8ß8>ºØ—I’IÐ9Ñ:Ô:ñ9ô 9ñô ð ð ˜fÒ$Ð$Ø1ˆOàÐ1Ò1Ð1Ýð?Ø,;ð?ð ?ð ?ñô ð ð
 Ð Ý,¨]¸AÑ>Ô>ˆå˜8°%Ð8Ñ8Ô8¸EÒAÐAõ Œ6•"”'˜( AÑ&Ô&Ñ'Ô'ð 	OÝÐM¸A¼GÀA¼JÈ¹NÐMÐMÐMÑNÔNÐNå”zÝ˜A˜xÑ(Ô(µ´¸sðñ ô ç‚e�g„gð õ )¨¨MÑ:Ô:€Mà”˜”€JØÐ#Ø˜¥3Ð'7Ñ#8Ô#8Ñ8ˆˆå!œzÐ*>Ñ?Ô?ÐØÔ$¨Ò)Ð)Ýð(ñô ð ð
  Ô%Ô*¨cÒ1Ð1à#Ô(¨JÒ6Ð6Ý ð.à+Ô0ð.ð .ð "ð.ð .ð .ñô ð ð UÐTÐTÐTÐCSÐTÑTÔTˆNˆNØ!Ô'Ô,°Ð?Ð?ð(ð (ð (ð (à/ð(ñ (ô (Ð$ðð ð ð Ø;Kðñ ô ˆNˆNõ ðRØ,@Ô,FðRð Rð Rñô ð ð
 "Ð' R€MÝ�(�S¥#˜JÑ'Ô'ð Ø�:ˆå(+Ð,<¸hÈÑ(WÔ(Wð ð Ñ$ˆ�W˜fØð 	Øå˜!˜[¨qÐ1Ñ1Ô1Ô7Ô<ÀÐDÐDÝðL˜gð Lð Lð Lñô ð ð Eõ ˜aÐ!1¸Ð:Ñ:Ô:€Hð"ð "ð "ð "å'¨Ñ1Ô1ð"ñ "ô "Ðõ  ØØØØØ"ñô �L€Dˆ&ð �ÒÐÝ,EØ�tÐ-¨q°/À=ñ-
ô -
Ñ)Ð˜kð *�kÔ)Ø�”˜”
ð
Ø=Ð=°fÐ=Ñ=Ô=ð
ð 
ð 
ˆˆõ  =Ø�tÐ-ñ 
ô  
Ðð 8Ð/Ô7Ø
ðØ-Ð- fÐ-Ñ-Ô-ðð ð Ðõ  FÐ+Ñ+Ô+€KàˆyÒÐØ!5ˆ�IÑÐØ	�Ò	Ð	Ø$/ˆ�LÑ!Ð!à!5ˆ�IÑØ$/ˆ�LÑ!àÐr(   r+   )6Ú__doc__Úcollections.abcr   Únumpyr3   Úscipyr   Úscipy.stats.mstatsr   Úsklearn.baser   r   Úsklearn.ensembler   Úsklearn.ensemble._gbr	   Ú:sklearn.ensemble._hist_gradient_boosting.gradient_boostingr
   Úsklearn.inspection._pd_utilsr   r   Úsklearn.treer   Úsklearn.utilsr   r   r   Úsklearn.utils._indexingr   r   r   Ú$sklearn.utils._optional_dependenciesr   Úsklearn.utils._param_validationr   r   r   r   r   Úsklearn.utils._responser   Úsklearn.utils.extmathr   Úsklearn.utils.validationr   r   Ú__all__r[   rd   rz   r-   ÚtupleÚdictr   r#   r(   r&   ú<module>rÒ      sW  ðØ HÐ Hð
 %Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )à 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5ðð ð ð ð ð ð RÐ QÐ QÐ QÐ QÐ QÐ QÐ QØ .Ð .Ð .Ð .Ð .Ð .Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <ðð ð ð ð ð ð ð ð ð ð
 JÐ IÐ IÐ IÐ IÐ Iðð ð ð ð ð ð ð ð ð ð ð ð ð ð 9Ð 8Ð 8Ð 8Ð 8Ð 8Ø +Ð +Ð +Ð +Ð +Ð +Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jð ð€ð
u%ð u%ð u%ðp7 ð 7 ð 7 ðv <@ð}-ð }-ð }-ð }-ð@ €ð ˆJ˜˜yÐ)Ñ*Ô*ØˆJ˜˜Ð/Ñ0Ô0ØˆJ˜Ð2Ð3Ñ4Ô4ð
ð
 ˜OÐ,Ø! 8¨SÐ1Ø&¨Ð-Ø!-¨tÐ 4Ø&¨Ð-Ø&˜JÐ'UÐ'UÐ'UÑVÔVÐWØ�wØ$˜H X¨q°$¸vÐFÑFÔFÐGØ�:Ð<Ð<Ð<Ñ=Ô=Ð>Ø�Ð=Ð=Ð=Ñ>Ô>Ð?Ø ˜ð!ð ð$ #'ð'ñ ô ð4 ØØØØØØØØ	ðSð Sð Sð Sñ+ô ð*Sð Sð Sr(   