Ë
    ®Ó^jå  ã                   ó.  — d Z ddlmZmZmZ ddlZddlmZm	Z	m
Z
 ddlmZmZ dedefd	„Zded
ee
   de
fd„Zdedeeef   dee	   defd„Zddddddœdedeeef   deeeef      ded
ee
   dee	   dedeej&                  ej&                  f   fd„ZdgZy)z.Interpretability functions for XGBoost models.é    )ÚOptionalÚTupleÚUnionNé   )Ú	ArrayLikeÚFloatCompatibleÚIterationRange)ÚBoosterÚDMatrixÚmodelÚreturnc                 ó´   — t        | t        «      r| S t        | dd «      }t        |«      st	        d«      ‚ |«       }t        |t        «      st	        d«      ‚|S )NÚget_boosterzC`model` must be an xgboost.Booster or an object with get_booster().z5`model.get_booster()` must return an xgboost.Booster.)Ú
isinstancer
   ÚgetattrÚcallableÚ	TypeError)r   r   Úboosters      ú\/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/xgboost/interpret.pyÚ_as_boosterr      s[   € Ü�%œÔ!ØˆÜ˜% °Ó5€KÜ�KÔ ÜØQó
ð 	
ñ ‹m€GÜ�gœwÔ'ÜÐOÓPÐPØ€Nó    Úiteration_rangec                 ó:   — t        | dd «      }|� ||«      S |€y|S )NÚ_get_iteration_range)r   r   )r   )r   r   Úget_iteration_ranges      r   r   r      s4   € ô " %Ð)?ÀÓFÐØÐ&Ù" ?Ó3Ð3ØÐØØÐr   ÚXÚmissingc                 óÀ   — t        |t        «      r|�t        d«      ‚|S t        ||�|nt        | dd «      t        | dd «      t        | dd «      t        | dd«      ¬«      S )Nz6`missing` must not be specified when `X` is a DMatrix.r   Ún_jobsÚfeature_typesÚenable_categoricalF)r   Únthreadr    r!   )r   r   Ú
ValueErrorr   )r   r   r   s      r   Ú_as_prediction_dmatrixr$   $   sm   € ô �!”WÔØÐÜÐUÓVÐVØˆäØ	Ø"Ð.‘´G¸EÀ9ÈdÓ4SÜ˜˜x¨Ó.Ü˜e _°dÓ;Ü" 5Ð*>ÀÓFôð r   FT)ÚX_backgroundÚoutput_marginr   r   Úvalidate_featuresr%   r&   r'   c          	      ó²   — |�t        d«      ‚|}t        | «      }t        | ||«      }	|j                  |	d|t	        | |«      ¬«      }
|
ddd…f   }|
d   }||fS )aF  Return SHAP values for an XGBoost model.

    .. warning::

      This function is still working in progress.

    This function accepts either a :py:class:`xgboost.Booster` or an sklearn-style
    XGBoost model and returns feature contributions together with the separated
    bias term.

    Parameters
    ----------
    model :
        XGBoost booster or sklearn-style XGBoost model.
    X :
        Input data.
    X_background :
        Background data for interventional SHAP values. This is reserved for a
        future implementation and is currently unsupported.
    output_margin :
        Accepted for API compatibility. SHAP contributions currently correspond
        to the model margin.
    iteration_range :
        Specifies which layer of trees are used in prediction.
    missing :
        Value in array-like ``X`` to treat as missing. When None, use the
        model's missing value if available, otherwise ``np.nan``. This must not
        be specified when ``X`` is already a DMatrix.
    validate_features :
        Validate feature names between the model and input data.

    Returns
    -------
    values, bias :
        ``values`` contains feature SHAP values with the bias term removed.
        ``bias`` contains the separated bias term. For multi-target models, the
        output shape follows the corresponding prediction shape with the final
        feature dimension split into ``values`` and ``bias``.

    Notes
    -----
    To use GPU algorithms, configure the model before calling this function, for
    example with ``booster.set_param({"device": "cuda"})``.
    Nz$`X_background` is not yet supported.T)Úpred_contribsr'   r   .éÿÿÿÿ).r*   )ÚNotImplementedErrorr   r$   Úpredictr   )r   r   r%   r&   r   r   r'   Ú_r   ÚdataÚcontribsÚvaluesÚbiass                r   Úshap_valuesr2   5   s„   € ðl ÐÜ!Ð"HÓIÐIð 	€Aä˜%Ó €GÜ! %¨¨GÓ4€DØ�‰ØØØ+Ü,¨U°OÓDð	 ó €Hð �c˜3˜B˜3�hÑ€FØ�GÑ€DØ�4ˆ<Ðr   r2   )Ú__doc__Útypingr   r   r   ÚnumpyÚnpÚ_typingr   r   r	   Úcorer
   r   Úobjectr   r   r$   ÚboolÚndarrayr2   Ú__all__© r   r   ú<module>r>      s-  ðÙ 4ç )Ñ )ã ç ?Ñ ?ß "ð�vð  'ó ðØðØ$,¨^Ñ$<ðàóðØðØ˜G YÐ.Ñ/ðØ:BÀ?Ñ:Sðàóð* 9=ØØ04Ø)-Ø"òGØðGàˆW�iÐÑ ðGð ˜5 ¨)Ð!3Ñ4Ñ5ð	Gð
 ðGð ˜nÑ-ðGð �oÑ&ðGð ðGð ˆ2�:‰:�r—z‘zÐ!Ñ"óGðT ˆ/�r   