U
    Ùf  ã                   @   s(   d dl mZ ddlZG dd„ deƒZdS )é   )Ú	Explaineré    Nc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTreeGainExplainerz§ Simply returns the global gain/gini feature importances for tree models.

    This is only for benchmark comparisons and is not meant to approximate SHAP values.
    c                 C   s¨   t t|ƒƒ d¡rnxt t|ƒƒ d¡r(ndt t|ƒƒ d¡r<nPt t|ƒƒ d¡rPn<t t|ƒƒ d¡rdn(t t|ƒƒ d¡rxntdt t|ƒƒ ƒ‚t|dƒsžtd	ƒ‚|| _d S )
Nz)sklearn.tree.tree.DecisionTreeRegressor'>z*sklearn.tree.tree.DecisionTreeClassifier'>z/sklearn.ensemble.forest.RandomForestRegressor'>z0sklearn.ensemble.forest.RandomForestClassifier'>zxgboost.sklearn.XGBRegressor'>zxgboost.sklearn.XGBClassifier'>z<The passed model is not yet supported by TreeGainExplainer: Úfeature_importances_z@The passed model does not have a feature_importances_ attribute!)ÚstrÚtypeÚendswithÚ	ExceptionÚhasattrÚAssertionErrorÚmodel)Úselfr   © r   úE/tmp/pip-target-lpfmz8o1/lib/python/shap/explainers/other/treegain.pyÚ__init__	   s    zTreeGainExplainer.__init__c                 C   s   t  | jj|jd df¡S )Nr   é   )ÚnpZtiler   r   Úshape)r   ÚXr   r   r   Úattributions   s    zTreeGainExplainer.attributionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   )Z	explainerr   Únumpyr   r   r   r   r   r   Ú<module>   s   