Ë
    »Ó^jÉ€  ã            #       óÚ  — d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlZddlmZmZmZmZmZ ddlmZ dd	lmZ g d
¢ZerddlZdededdfd„Zdedee   defd„Z 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<deeef   dddedeeeef      deeeef      dee   dee   dee   dedee   de!deeeef      dee   d e!dee   d!edef"d"„Z"	 	 	 	 	 	 	 	 	 	 	 d=deeef   d#eeef   d$eeedf   ddd%edeeeef      deeeef      dee   dee   dee   deeeef      dee   d e!d!edefd&„Z#	 	 	 	 	 	 	 	 	 	 	 d>dee	ef   d'ee   d(ee
e      dddeeeef      deeeef      dee   dee   dee   deeeef      dee   d e!defd)„Z$d*ed+ed,ed-e!def
d.„Z%d*ed/edefd0„Z&d1e	eef   d2e
e   d3ee
e   df   dee   d4ed5ee
e      d6eeejN                  ef      d7ed!edefd8„Z(	 	 	 	 	 	 d?deeef   d9ed2ee
e      dee   d4ed6eeejN                  ef      d7ed!edefd:„Z)	 	 	 	 	 	 	 	 d@deeef   ddd9edeeeef      dee   d2ee
e      dee   d4ed6eeejN                  ef      d!edefd;„Z*y)AzPlotting library.é    N)Údeepcopy)ÚBytesIO)ÚTYPE_CHECKINGÚAnyÚDictÚListÚOptionalÚTupleÚUnioné   )ÚBoosterÚ_data_from_pandasÚ_is_zeroÚ_log_warningÚ_MissingType)Úpd_DataFrame)Ú	LGBMModel)Úcreate_tree_digraphÚplot_importanceÚplot_metricÚplot_split_value_histogramÚ	plot_treeÚobjÚobj_nameÚreturnc                 ó\   — t        | t        «      rt        | «      dk7  rt        |› d�«      ‚y)z6Check object is not tuple or does not have 2 elements.é   z must be a tuple of 2 elements.N)Ú
isinstanceÚtupleÚlenÚ	TypeError)r   r   s     ú\/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/lightgbm/plotting.pyÚ_check_not_tuple_of_2_elementsr#      s.   € ä�cœ5Ô!¤S¨£X°¢]Ü˜8˜*Ð$CÐDÓEÐEð &3ó    ÚvalueÚ	precisionc                 óL   — |�t        | t        «      s| d|› d�›S t        | «      S )Nú.Úf)r   Ústr)r%   r&   s     r"   Ú
_float2strr+   !   s1   € Ø'0Ð'<ÄZÐPUÔWZÔE[ˆe�A�i�[ �>Ð"ÐkÔadÐejÓakÐkr$   ÚboosterÚaxzOptional[matplotlib.axes.Axes]ÚheightÚxlimÚylimÚtitleÚxlabelÚylabelÚimportance_typeÚmax_num_featuresÚignore_zeroÚfigsizeÚdpiÚgridÚkwargsc           	      ó"  — 	 ddl m} t        | t        «      r|dk(  r| j
                  }| j                  } n#t        | t        «      r|dk(  rd}nt        d«      ‚| j                  |¬«      }| j                  «       }t        |«      st        d«      ‚t        t        ||d	¬
«      d„ ¬«      }|
r|D �cg c]  }|d   dkD  sŒ|‘Œ }}|	�|	dkD  r||	 d }|st        d«      ‚t        |dd	iŽ\  }}|€&|�t        |d«       |j!                  dd||¬«      \  }}t#        j$                  t        |«      «      } |j&                  ||fd|dœ|¤Ž t        ||d	¬
«      D ]7  \  }}|j)                  |dz   t+        |«      |dk(  rt-        ||«      n|d¬«       Œ9 |j/                  |«       |j1                  |«       |�t        |d«       ndt3        |«      dz  f}|j5                  |«       |�t        |d«       ndt        |«      f}|j7                  |«       |�|j9                  |«       |�#|j;                  d|«      }|j=                  |«       |�|j?                  |«       |jA                  |«       |S # t        $ r}t        d«      |‚d}~ww xY wc c}w )a	  Plot model's feature importances.

    Parameters
    ----------
    booster : Booster or LGBMModel
        Booster or LGBMModel instance which feature importance should be plotted.
    ax : matplotlib.axes.Axes or None, optional (default=None)
        Target axes instance.
        If None, new figure and axes will be created.
    height : float, optional (default=0.2)
        Bar height, passed to ``ax.barh()``.
    xlim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.xlim()``.
    ylim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.ylim()``.
    title : str or None, optional (default="Feature importance")
        Axes title.
        If None, title is disabled.
    xlabel : str or None, optional (default="Feature importance")
        X-axis title label.
        If None, title is disabled.
        @importance_type@ placeholder can be used, and it will be replaced with the value of ``importance_type`` parameter.
    ylabel : str or None, optional (default="Features")
        Y-axis title label.
        If None, title is disabled.
    importance_type : str, optional (default="auto")
        How the importance is calculated.
        If "auto", if ``booster`` parameter is LGBMModel, ``booster.importance_type`` attribute is used; "split" otherwise.
        If "split", result contains numbers of times the feature is used in a model.
        If "gain", result contains total gains of splits which use the feature.
    max_num_features : int or None, optional (default=None)
        Max number of top features displayed on plot.
        If None or <1, all features will be displayed.
    ignore_zero : bool, optional (default=True)
        Whether to ignore features with zero importance.
    figsize : tuple of 2 elements or None, optional (default=None)
        Figure size.
    dpi : int or None, optional (default=None)
        Resolution of the figure.
    grid : bool, optional (default=True)
        Whether to add a grid for axes.
    precision : int or None, optional (default=3)
        Used to restrict the display of floating point values to a certain precision.
    **kwargs
        Other parameters passed to ``ax.barh()``.

    Returns
    -------
    ax : matplotlib.axes.Axes
        The plot with model's feature importances.
    r   NzHYou must install matplotlib and restart your session to plot importance.ÚautoÚsplitú%booster must be Booster or LGBMModel.)r4   z&Booster's feature_importance is empty.T)Ústrictc                 ó   — | d   S )Nr   © )Úxs    r"   ú<lambda>z!plot_importance.<locals>.<lambda>   s   € ÈaÐPQÉd€ r$   )Úkeyr   zpNo non-zero feature importances found. The model may have no splits. Use ignore_zero=False to show all features.r?   r7   ©r7   r8   Úcenter)Úalignr.   Úgain)Úvar/   çš™™™™™ñ?r0   éÿÿÿÿz@importance_type@)!Úmatplotlib.pyplotÚpyplotÚImportErrorr   r   r4   Úbooster_r   r!   Úfeature_importanceÚfeature_namer    Ú
ValueErrorÚsortedÚzipr#   ÚsubplotsÚnpÚarangeÚbarhÚtextÚfloatr+   Ú
set_yticksÚset_yticklabelsÚmaxÚset_xlimÚset_ylimÚ	set_titleÚreplaceÚ
set_xlabelÚ
set_ylabelr9   )r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r&   r:   ÚpltÚerrÚ
importancerQ   ÚtuplesrB   ÚlabelsÚvaluesÚ_ÚylocsÚys                              r"   r   r   %   s©  € ðJoÝ'ô �'œ9Ô%Ø˜fÒ$Ø%×5Ñ5ˆOØ×"Ñ"‰Ü	�GœWÔ	%Ø˜fÒ$Ø%‰OäÐ?Ó@Ð@à×+Ñ+¸OÐ+ÓL€JØ×'Ñ'Ó)€LäˆzŒ?ÜÐAÓBÐBä”C˜ j¸Ô>ÁNÔS€FÙØ#Ö0˜ q¨¡t¨a£x’!Ð0ˆÐ0ØÐ#Ð(8¸1Ò(<ØÐ)Ð)Ð*Ð+ˆÙÜð:ó
ð 	
ô ˜&Ð.¨Ñ.�N€FˆFà	€zØÐÜ*¨7°IÔ>Ø—‘˜Q ¨7¸�Ó<‰ˆˆ2ä�I‰I”c˜&“kÓ"€EØ€B‡G�GˆE�6ÐC °&ÑC¸FÒCä�F˜E¨$Ô/ò l‰ˆˆ1Ø
�‰��A‘”u˜Q“x¸_ÐPVÒ=V¤¨A¨yÔ!9Ð\]ÐbjˆÕkðlð ‡M�M�%ÔØ×Ñ�vÔàÐÜ& t¨VÕ4à”3�v“; Ñ$Ð%ˆØ‡K�K�ÔàÐÜ& t¨VÕ4à”C˜“KÐ ˆØ‡K�K�ÔàÐØ
�‰�UÔØÐØ—‘Ð 3°_ÓEˆØ
�‰�fÔØÐØ
�‰�fÔØ‡G�GˆD„MØ€IøôC ò oÜÐdÓeÐknÐnûðoüò* 1s#   ‚I/ Â1JÂ?JÉ/	J	É8JÊJ	ÚfeatureÚbinsÚ
width_coefc                 ó4  — 	 ddl m} ddlm} t        | t        «      r| j                  } nt        | t        «      st        d«      ‚| j                  ||d¬«      \  }}t        j                  |«      dk(  rt        d|› d	�«      ‚||d
   |d   z
  z  }|dd |d
d z   dz  }|€&|
�t        |
d«       |j                  d
d
|
|¬«      \  }} |j                   ||fd|dœ|¤Ž |�t        |d«       n!|d   |d   z
  }|d   |dz  z
  |d   |dz  z   f}|j#                  |«       |j$                  j'                   |d¬«      «       |�t        |d«       ndt)        |«      dz  f}|j+                  |«       |�P|j-                  dt/        |«      «      }|j-                  dt        |t.        «      rdnd«      }|j1                  |«       |�|j3                  |«       |	�|j5                  |	«       |j7                  |«       |S # t        $ r}t	        d«      |‚d}~ww xY w)aí  Plot split value histogram for the specified feature of the model.

    Parameters
    ----------
    booster : Booster or LGBMModel
        Booster or LGBMModel instance of which feature split value histogram should be plotted.
    feature : int or str
        The feature name or index the histogram is plotted for.
        If int, interpreted as index.
        If str, interpreted as name.
    bins : int, str or None, optional (default=None)
        The maximum number of bins.
        If None, the number of bins equals number of unique split values.
        If str, it should be one from the list of the supported values by ``numpy.histogram()`` function.
    ax : matplotlib.axes.Axes or None, optional (default=None)
        Target axes instance.
        If None, new figure and axes will be created.
    width_coef : float, optional (default=0.8)
        Coefficient for histogram bar width.
    xlim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.xlim()``.
    ylim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.ylim()``.
    title : str or None, optional (default="Split value histogram for feature with @index/name@ @feature@")
        Axes title.
        If None, title is disabled.
        @feature@ placeholder can be used, and it will be replaced with the value of ``feature`` parameter.
        @index/name@ placeholder can be used,
        and it will be replaced with ``index`` word in case of ``int`` type ``feature`` parameter
        or ``name`` word in case of ``str`` type ``feature`` parameter.
    xlabel : str or None, optional (default="Feature split value")
        X-axis title label.
        If None, title is disabled.
    ylabel : str or None, optional (default="Count")
        Y-axis title label.
        If None, title is disabled.
    figsize : tuple of 2 elements or None, optional (default=None)
        Figure size.
    dpi : int or None, optional (default=None)
        Resolution of the figure.
    grid : bool, optional (default=True)
        Whether to add a grid for axes.
    **kwargs
        Other parameters passed to ``ax.bar()``.

    Returns
    -------
    ax : matplotlib.axes.Axes
        The plot with specified model's feature split value histogram.
    r   N)ÚMaxNLocatorzSYou must install matplotlib and restart your session to plot split value histogram.r>   F)rm   rn   Úxgboost_stylez3Cannot plot split value histogram, because feature z was not used in splittingr   rK   r   r7   rE   rF   )rG   Úwidthr/   çš™™™™™É?T)Úintegerr0   rJ   z	@feature@z@index/name@ÚnameÚindex)rL   rM   Úmatplotlib.tickerrq   rN   r   r   rO   r   r!   Úget_split_value_histogramrV   Úcount_nonzerorR   r#   rU   Úbarr^   ÚyaxisÚset_major_locatorr]   r_   ra   r*   r`   rb   rc   r9   )r,   rm   rn   r-   ro   r/   r0   r1   r2   r3   r7   r8   r9   r:   rd   rq   re   ÚhistÚ
split_binsrs   Úcentredrj   Úrange_results                          r"   r   r   °   s4  € ðDÝ'Ý1ô �'œ9Ô%Ø×"Ñ"‰Ü˜¤Ô)ÜÐ?Ó@Ð@à×8Ñ8ÀÈtÐchÐ8ÓiÑ€Dˆ*Ü	×Ñ˜Ó Ò"ÜÐNÈwÈiÐWqÐrÓsÐsØ˜* Q™-¨*°Q©-Ñ7Ñ8€EØ˜#˜2ˆ ¨A¨B Ñ/°1Ñ4€Gà	€zØÐÜ*¨7°IÔ>Ø—‘˜Q ¨7¸�Ó<‰ˆˆ2à
€B‡F�Fˆ7�DÐ@ °Ñ@¸Ò@àÐÜ& t¨VÕ4à! "‘~¨
°1©Ñ5ˆØ˜1‘ ¨sÑ 2Ñ2°J¸r±NÀ\ÐTWÑEWÑ4WÐXˆØ‡K�K�Ôà‡H�H×Ñ™{°4Ô8Ô9ØÐÜ& t¨VÕ4à”3�t“9˜s‘?Ð#ˆØ‡K�K�ÔàÐØ—‘˜k¬3¨w«<Ó8ˆØ—‘˜n¼ÀGÌSÔ9Q©vÐW^Ó`ˆØ
�‰�UÔØÐØ
�‰�fÔØÐØ
�‰�fÔØ‡G�GˆD„MØ€Iøô] ò ÜØaó
àð	ûðús   ‚G= Ç=	HÈHÈHÚmetricÚdataset_namesc                 ór  — 	 ddl m} t        | t        «      rt        | j                  «      }nBt        | t        «      rt        | «      }n&t        | t        «      rt        d«      ‚t        d«      ‚t        |«      }|st        d«      ‚|€&|	�t        |	d«       |j                  dd|	|
¬	«      \  }}|€t        |j                  «       «      }n3t        |t         t"        t$        f«      r|st        d
«      ‚t        |«      }t'        |«      }||   }t        |«      }|€$|dkD  rt)        d«       |j+                  «       \  }}n||vrt-        d«      ‚||   }t        |«      }t/        |«      }t1        |«      }t3        |«      }|j5                  |||¬«       |D ]:  }||   }||   }t/        g |¢|‘­Ž }t1        g |¢|‘­Ž }|j5                  |||¬«       Œ< |j7                  d¬«       |�t        |d«       nd|f}|j9                  |«       |�t        |d«       n||z
  }||dz  z
  ||dz  z   f}|j;                  |«       |�|j=                  |«       |�|j?                  |«       |�#|jA                  d|«      }|jC                  |«       |jE                  |«       |S # t        $ r}t        d«      |‚d}~ww xY w)a  Plot one metric during training.

    Parameters
    ----------
    booster : dict or LGBMModel
        Dictionary returned from ``lightgbm.train()`` or LGBMModel instance.
    metric : str or None, optional (default=None)
        The metric name to plot.
        Only one metric supported because different metrics have various scales.
        If None, first metric picked from dictionary (according to hashcode).
    dataset_names : list of str, or None, optional (default=None)
        List of the dataset names which are used to calculate metric to plot.
        If None, all datasets are used.
    ax : matplotlib.axes.Axes or None, optional (default=None)
        Target axes instance.
        If None, new figure and axes will be created.
    xlim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.xlim()``.
    ylim : tuple of 2 elements or None, optional (default=None)
        Tuple passed to ``ax.ylim()``.
    title : str or None, optional (default="Metric during training")
        Axes title.
        If None, title is disabled.
    xlabel : str or None, optional (default="Iterations")
        X-axis title label.
        If None, title is disabled.
    ylabel : str or None, optional (default="@metric@")
        Y-axis title label.
        If 'auto', metric name is used.
        If None, title is disabled.
        @metric@ placeholder can be used, and it will be replaced with metric name.
    figsize : tuple of 2 elements or None, optional (default=None)
        Figure size.
    dpi : int or None, optional (default=None)
        Resolution of the figure.
    grid : bool, optional (default=True)
        Whether to add a grid for axes.

    Returns
    -------
    ax : matplotlib.axes.Axes
        The plot with metric's history over the training.
    r   NzDYou must install matplotlib and restart your session to plot metric.z¶booster must be dict or LGBMModel. To use plot_metric with Booster type, first record the metrics using record_evaluation callback then pass that to plot_metric as argument `booster`z"booster must be dict or LGBMModel.zeval results cannot be empty.r7   r   rE   z4dataset_names should be iterable and cannot be emptyz4More than one metric available, picking one to plot.z No given metric in eval results.)ÚlabelÚbest)Úlocr/   r0   rt   ú@metric@)#rL   rM   rN   r   r   r   Úevals_result_Údictr   r!   r    rR   r#   rU   ÚiterÚkeysÚlistr   ÚsetÚnextr   ÚpopitemÚKeyErrorr]   ÚminÚrangeÚplotÚlegendr^   r_   r`   rb   ra   rc   r9   )r,   r‚   rƒ   r-   r/   r0   r1   r2   r3   r7   r8   r9   rd   re   Úeval_resultsÚnum_datarj   Údataset_names_iterrv   Úmetrics_for_oneÚ
num_metricÚresultsÚnum_iterationÚ
max_resultÚ
min_resultÚx_r�   s                              r"   r   r   &  sÛ  € ðrkÝ'ô �'œ9Ô%Ü × 5Ñ 5Ó6‰Ü	�GœTÔ	"Ü Ó(‰Ü	�GœWÔ	%Üð Eó
ð 	
ô Ð<Ó=Ð=ä�<Ó €HáÜÐ8Ó9Ð9à	€zØÐÜ*¨7°IÔ>Ø—‘˜Q ¨7¸�Ó<‰ˆˆ2àÐÜ! ,×"3Ñ"3Ó"5Ó6ÑÜ˜¬¬e´SÐ'9Ô:Á-ÜÐOÓPÐPä! -Ó0ÐäÐ"Ó#€DØ" 4Ñ(€OÜ�_Ó%€JØ€~Ø˜Š>ÜÐOÔPØ)×1Ñ1Ó3‰ˆ‘à˜Ñ(ÜÐ=Ó>Ð>Ø! &Ñ)ˆÜ˜“L€MÜ�W“€JÜ�W“€JÜ	ˆ}Ó	€BØ‡G�GˆB�˜t€GÔ$à"ò )ˆØ& tÑ,ˆØ! &Ñ)ˆÜÐ.˜'Ð. :Ò.ˆ
ÜÐ.˜'Ð. :Ò.ˆ
Ø
�‰��G 4ˆÕ(ð)ð ‡I�I�&€IÔàÐÜ& t¨VÕ4à�=Ð!ˆØ‡K�K�ÔàÐÜ& t¨VÕ4à! JÑ.ˆØ˜\¨CÑ/Ñ/°¸lÈSÑ>PÑ1PÐQˆØ‡K�K�ÔàÐØ
�‰�UÔØÐØ
�‰�fÔØÐØ—‘ 
¨FÓ3ˆØ
�‰�fÔØ‡G�GˆD„MØ€Iøô] ò kÜÐ`ÓaÐgjÐjûðkús   ‚J Ê	J6Ê%J1Ê1J6ÚfvalÚ	thresholdÚmissing_type_strÚdefault_leftc                 ó"  — t        |«      }t        j                  | «      r|t         j                  k7  rd} |t         j                  k(  rt        | «      s(|t         j                  k(  rt        j                  | «      r
|rd}|S d}|S | |k  rdnd}|S )Ng        ÚleftÚright)r   ÚmathÚisnanÚNANÚZEROr   )r    r¡   r¢   r£   Úmissing_typeÚ	directions         r"   Ú&_determine_direction_for_numeric_splitr­   ²  sŽ   € ô  Ð 0Ó1€LÜ‡z�z�$Ô˜L¬L×,<Ñ,<Ò<ØˆØœ×)Ñ)Ò)¬h°t¬nØœ×(Ñ(Ò(¬T¯Z©Z¸Ô-=á*�Fˆ	ð Ðð 18ˆ	ð Ðð # iÒ/‘F°Wˆ	ØÐr$   Ú
thresholdsc                 óÄ   — t        j                  | «      st        | «      dk  ry|j                  d«      D �ch c]  }t        |«      ’Œ }}t        | «      |v rdS dS c c}w )Nr   r¦   ú||r¥   )r§   r¨   Úintr=   )r    r®   ÚtÚint_thresholdss       r"   Ú*_determine_direction_for_categorical_splitr´   Å  sX   € Ü‡z�z�$Ôœ3˜t›9 qš=ØØ&0×&6Ñ&6°tÓ&<Ö= ”c˜!•fÐ=€NÐ=Ü˜“Y .Ñ0ˆ6Ð=°gÐ=ùò >s   ¸AÚ	tree_infoÚ	show_infoÚfeature_namesÚorientationÚconstraintsÚexample_caseÚmax_category_valuesc                 óÂ  ‡‡‡‡‡‡‡‡— 	 ddl m}	 dt        t        t
        f   dt        dt        t           dt        t           d	t        d
dfˆˆˆˆˆˆˆˆfd„Š |	di |¤ŽŠ|dk(  rdnd}‰j                  ddd|¬«       d| d   v r ‰| d   | d   d   dd‰du¬«       nt        d«      ‚‰rd}‰j                  d|dd¬«       ‰S # t        $ r}
t        d«      |
‚d}
~
ww xY w)z~Convert specified tree to graphviz instance.

    See:
      - https://graphviz.readthedocs.io/en/stable/api.html#digraph
    r   )ÚDigraphz@You must install graphviz and restart your session to plot tree.NÚrootÚtotal_countÚparentÚdecisionÚ	highlightr   c           
      óæ  •— d}d}d}|rd}d}	nd}d}	d| v �r°d	}
d
}d}| d   }| d   dk(  rd}n| d   dk(  rd}nt        d«      ‚d| d   › �}| d   }‰�d‰|   › d|› �}n	d|› d|› d�}d}‰�7| d   dk(  rt        ‰|   | d   ¬«      }nt        ‰|   | d   | d   | d   ¬«      }| d   dk(  rD| d   j                  d«      }t	        |«      ‰kD  r"| d   }dj                  |dd «      dz   |d    z   }|dt        |‰«      › d!�z  }d"D ]n  }|‰v sŒ|j                  d#«      d    }|d$v r|d%t        | |   ‰«      › d|› �z  }Œ9|d&k(  r|d%|› d'| |   › �z  }ŒM|d(k(  sŒS|d%t        | d&   |z  d)z  d«      › d*�z  }Œp ‰r‰| d      d+k(  rd,}‰| d      d k(  rd-}d.}d/|› d0�} ‰| d1   ||||xr |d2k(  ¬3«        ‰| d4   ||||xr |d5k(  ¬3«       nxd6}
d7| d8   › �}d9| d8   › d'�}|dt        | d:   ‰«      › d!�z  }d;‰v r|d%t        | d;   ‰«      › d<�z  }d=‰v r|d>| d=   › �z  }d(‰v r|d%t        | d=   |z  d)z  d«      › d*�z  }d/|› d0�}‰j                  |||
||||	|¬?«       |�‰j                  |||||	¬@«       yy)AzRecursively add node or edge.ÚwhiteÚ NÚblueÚ3ÚblackÚ1Úsplit_indexÚ	rectangleÚyesÚnor¡   Údecision_typez<=z&#8804;z==ú=z$Invalid decision type in tree model.r=   Úsplit_featurez<B>z</B> zfeature <B>ú )r    r®   r«   r£   )r    r¡   r¢   r£   r°   r   z||...||rK   z</B>)Ú
split_gainÚinternal_valueÚinternal_weightÚinternal_countÚdata_percentagerj   >   rÒ   rÓ   rÔ   z<br/>rÕ   z: rÖ   éd   z	% of datar   z#ddffddz#ffddddÚfilledú<ú>Ú
left_childr¥   ©r¾   r¿   rÀ   rÁ   rÂ   Úright_childr¦   ÚellipseÚleafÚ
leaf_indexzleaf Ú
leaf_valueÚleaf_weightz weightÚ
leaf_countz<br/>count: )r…   ÚshapeÚstyleÚ	fillcolorÚcolorÚpenwidthÚtooltip)rç   rè   )	rR   r´   r­   r=   r    Újoinr+   ÚnodeÚedge)r¾   r¿   rÀ   rÁ   rÂ   ræ   rå   ré   rç   rè   rä   Úl_decÚr_decr¡   Úoperatorrv   rÐ   r…   r¬   Úcategory_valuesÚinfoÚoutputÚaddr¹   rº   r·   Úgraphr»   r&   r¶   s                         €€€€€€€€r"   ró   z_to_graphviz.<locals>.addâ  s
  ø€ ð ˆ	ØˆØˆÙØˆEØ‰HàˆEØˆHØ˜DÒ ØˆEØˆEØˆEØ˜[Ñ)ˆIØ�OÑ$¨Ò,Ø$‘Ø�oÑ&¨$Ò.Ø‘ä Ð!GÓHÐHØ˜4 Ñ.Ð/Ð0ˆDØ  Ñ1ˆMØÐ(Ø˜m¨MÑ:Ð;¸5ÀÀ
ÐK‘à% m _°E¸(¸À1ÐE�ØˆIØÐ'Ø˜Ñ(¨DÒ0Ü JØ)¨-Ñ8ÀTÈ+ÑEVô!‘Iô !GØ)¨-Ñ8Ø"& {Ñ"3Ø)-¨nÑ)=Ø%)¨.Ñ%9ô	!�Ið �OÑ$¨Ò,Ø"& {Ñ"3×"9Ñ"9¸$Ó"?�Ü�Ó'Ð*=Ò=Ø" ;Ñ/�GØ $§	¡	¨/¸"¸1Ð*=Ó >ÀÑ JÈ_Ð]_ÑM`Ñ `�Ià�sœ: i°Ó;Ð<¸DÐAÑAˆEØpò n�Ø˜9Ò$Ø!ŸZ™Z¨›_¨RÑ0�FØÐRÑRØ 5¬°D¸±JÀ	Ó)JÐ(KÈ1ÈVÈHÐ!UÑU™ØÐ!1Ò1Ø 5¨¨°°4¸±:°,Ð!?Ñ?™ØÐ!2Ó2Ø 5¬°DÐ9IÑ4JÈ[Ñ4XÐ[^Ñ4^Ð`aÓ)bÐ(cÐclÐ!mÑm™ðnñ Ø˜t OÑ4Ñ5¸Ò:Ø )�IØ˜t OÑ4Ñ5¸Ò;Ø )�IØ �Ø˜�w˜a�LˆEÙØ˜,Ñ'Ø'ØØØ#Ò;¨	°VÑ(;õñ Ø˜-Ñ(Ø'ØØØ#Ò<¨	°WÑ(<öð ˆEØ˜$˜|Ñ,Ð-Ð.ˆDØ˜D Ñ.Ð/¨rÐ2ˆEØ�sœ: d¨<Ñ&8¸)ÓDÐEÀTÐJÑJˆEØ 	Ñ)Ø˜5¤¨D°Ñ,?ÀÓ!KÐ LÈGÐTÑT�Ø˜yÑ(Ø˜<¨¨\Ñ(:Ð';Ð<Ñ<�Ø  IÑ-Ø˜5¤¨D°Ñ,>ÀÑ,LÈsÑ,RÐTUÓ!VÐ WÐW`ÐaÑa�Ø˜�w˜a�LˆEØ�
‰
ØØØØØØØØð 	ô 		
ð ÐØ�J‰J�v˜t X°UÀXˆJÕNð r$   Ú
horizontalÚLRÚTBrô   z0.05z0.3)ÚnodesepÚranksepÚrankdirrÕ   Útree_structurerÜ   zCannot plot trees with no splita·  <
            <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
             <TR>
              <TD COLSPAN="2"><B>Monotone constraints</B></TD>
             </TR>
             <TR>
              <TD>Increasing</TD>
              <TD BGCOLOR="#ddffdd"></TD>
             </TR>
             <TR>
              <TD>Decreasing</TD>
              <TD BGCOLOR="#ffdddd"></TD>
             </TR>
            </TABLE>
           >r•   rË   rÄ   )r…   rä   rç   rA   )Úgraphvizr½   rN   r   r*   r   r±   r	   ÚboolÚattrÚ	Exceptionrë   )rµ   r¶   r·   r&   r¸   r¹   rº   r»   r:   r½   re   rú   r•   ró   rô   s    ``` ```     @@r"   Ú_to_graphvizr   Ì  s-  ÿ€ ð"gÝ$ðhOÜ”3œ�8‰nðhOÜ+.ðhOÜ8@Ä¹ðhOÜQYÔZ]ÑQ^ðhOÜkoðhOà	÷hOô hOñT Ñ�fÑ€EØ! \Ò1‰d°t€GØ	‡J�Jˆw °¸w€JÔGØ˜9Ð%5Ñ6Ñ6ÙØÐ+Ñ,Ø!Ð"2Ñ3Ð4DÑEØØØ"¨$Ð.ö	
ô Ð9Ó:Ð:áðˆð 	�
‰
�8 6°ÀGˆ
ÔLØ€Løô[ ò gÜÐ\Ó]ÐcfÐfûðgús   ŠC Ã	CÃCÃCÚ
tree_indexc                 óf  — t        | t        «      r| j                  } nt        | t        «      st	        d«      ‚| j                  «       }|d   }	|j                  dd«      }
|j                  dd«      }|t        |	«      k  r|	|   }nt        d«      ‚|€g }|�ˆt        |t        j                  t        f«      r|j                  dk7  rt        d«      ‚|j                  d	   d
k7  rt        d«      ‚t        |t        «      rt        |dd| j                   ¬«      d	   }|d	   }t#        d|||
|||||dœ|¤ŽS )aÊ  Create a digraph representation of specified tree.

    Each node in the graph represents a node in the tree.

    Non-leaf nodes have labels like ``Column_10 <= 875.9``, which means
    "this node splits on the feature named "Column_10", with threshold 875.9".

    Leaf nodes have labels like ``leaf 2: 0.422``, which means "this node is a
    leaf node, and the predicted value for records that fall into this node
    is 0.422". The number (``2``) is an internal unique identifier and doesn't
    have any special meaning.

    .. note::

        For more information please visit
        https://graphviz.readthedocs.io/en/stable/api.html#digraph.

    Parameters
    ----------
    booster : Booster or LGBMModel
        Booster or LGBMModel instance to be converted.
    tree_index : int, optional (default=0)
        The index of a target tree to convert.
    show_info : list of str, or None, optional (default=None)
        What information should be shown in nodes.

            - ``'split_gain'`` : gain from adding this split to the model
            - ``'internal_value'`` : raw predicted value that would be produced by this node if it was a leaf node
            - ``'internal_count'`` : number of records from the training data that fall into this non-leaf node
            - ``'internal_weight'`` : total weight of all nodes that fall into this non-leaf node
            - ``'leaf_count'`` : number of records from the training data that fall into this leaf node
            - ``'leaf_weight'`` : total weight (sum of Hessian) of all observations that fall into this leaf node
            - ``'data_percentage'`` : percentage of training data that fall into this node
    precision : int or None, optional (default=3)
        Used to restrict the display of floating point values to a certain precision.
    orientation : str, optional (default='horizontal')
        Orientation of the tree.
        Can be 'horizontal' or 'vertical'.
    example_case : numpy 2-D array, pandas DataFrame or None, optional (default=None)
        Single row with the same structure as the training data.
        If not None, the plot will highlight the path that sample takes through the tree.

        .. versionadded:: 4.0.0

    max_category_values : int, optional (default=10)
        The maximum number of category values to display in tree nodes, if the number of thresholds is greater than this value, thresholds will be collapsed and displayed on the label tooltip instead.

        .. warning::

            Consider wrapping the SVG string of the tree graph with ``IPython.display.HTML`` when running on JupyterLab to get the `tooltip <https://graphviz.org/docs/attrs/tooltip>`_ working right.

            Example:

            .. code-block:: python

                from IPython.display import HTML

                graph = lgb.create_tree_digraph(clf, max_category_values=5)
                HTML(graph._repr_image_svg_xml())

        .. versionadded:: 4.0.0

    **kwargs
        Other parameters passed to ``Digraph`` constructor.
        Check https://graphviz.readthedocs.io/en/stable/api.html#digraph for the full list of supported parameters.

    Returns
    -------
    graph : graphviz.Digraph
        The digraph representation of specified tree.
    r>   rµ   r·   NÚmonotone_constraintsztree_index is out of range.r   z<example_case must be a numpy 2-D array or a pandas DataFramer   r   z$example_case must have a single row.r<   )ÚdatarQ   Úcategorical_featureÚpandas_categorical)rµ   r¶   r·   r&   r¸   r¹   rº   r»   rA   )r   r   rO   r   r!   Ú
dump_modelÚgetr    Ú
IndexErrorrV   Úndarrayr   ÚndimrR   rä   r   r  r   )r,   r  r¶   r&   r¸   rº   r»   r:   ÚmodelÚ
tree_infosr·   r  rµ   s                r"   r   r   o  sX  € ôb �'œ9Ô%Ø×"Ñ"‰Ü˜¤Ô)ÜÐ?Ó@Ð@à×ÑÓ €EØ�{Ñ#€JØ—I‘I˜o¨tÓ4€MØ Ÿ9™9Ð%;¸TÓBÐà”C˜
“OÒ#Ø˜zÑ*‰	äÐ6Ó7Ð7àÐØˆ	àÐÜ˜,¬¯©´\Ð(BÔCÀ|×GXÑGXÐ\]ÒG]ÜÐ[Ó\Ð\Ø×Ñ˜aÑ  AÒ%ÜÐCÓDÐDÜ�l¤LÔ1Ü,Ø!Ø#Ø$*Ø#*×#=Ñ#=ô	ð
 ñˆLð $ A‘ˆäð 
ØØØ#ØØØ(Ø!Ø/ñ
ð ñ
ð 
r$   c	           
      ó¼  — 	 ddl }
ddlm} |€&|�t	        |d«       |j                  dd||¬«      \  }}t        d| |||||dœ|	¤Ž}t        «       }|j                  |j                  d¬	«      «       |j                  d«       |
j                  j                  |«      }|j                  |«       |j                  d
«       |S # t        $ r}t        d«      |‚d}~ww xY w)a8  Plot specified tree.

    Each node in the graph represents a node in the tree.

    Non-leaf nodes have labels like ``Column_10 <= 875.9``, which means
    "this node splits on the feature named "Column_10", with threshold 875.9".

    Leaf nodes have labels like ``leaf 2: 0.422``, which means "this node is a
    leaf node, and the predicted value for records that fall into this node
    is 0.422". The number (``2``) is an internal unique identifier and doesn't
    have any special meaning.

    .. note::

        It is preferable to use ``create_tree_digraph()`` because of its lossless quality
        and returned objects can be also rendered and displayed directly inside a Jupyter notebook.

    Parameters
    ----------
    booster : Booster or LGBMModel
        Booster or LGBMModel instance to be plotted.
    ax : matplotlib.axes.Axes or None, optional (default=None)
        Target axes instance.
        If None, new figure and axes will be created.
    tree_index : int, optional (default=0)
        The index of a target tree to plot.
    figsize : tuple of 2 elements or None, optional (default=None)
        Figure size.
    dpi : int or None, optional (default=None)
        Resolution of the figure.
    show_info : list of str, or None, optional (default=None)
        What information should be shown in nodes.

            - ``'split_gain'`` : gain from adding this split to the model
            - ``'internal_value'`` : raw predicted value that would be produced by this node if it was a leaf node
            - ``'internal_count'`` : number of records from the training data that fall into this non-leaf node
            - ``'internal_weight'`` : total weight of all nodes that fall into this non-leaf node
            - ``'leaf_count'`` : number of records from the training data that fall into this leaf node
            - ``'leaf_weight'`` : total weight (sum of Hessian) of all observations that fall into this leaf node
            - ``'data_percentage'`` : percentage of training data that fall into this node
    precision : int or None, optional (default=3)
        Used to restrict the display of floating point values to a certain precision.
    orientation : str, optional (default='horizontal')
        Orientation of the tree.
        Can be 'horizontal' or 'vertical'.
    example_case : numpy 2-D array, pandas DataFrame or None, optional (default=None)
        Single row with the same structure as the training data.
        If not None, the plot will highlight the path that sample takes through the tree.

        .. versionadded:: 4.0.0

    **kwargs
        Other parameters passed to ``Digraph`` constructor.
        Check https://graphviz.readthedocs.io/en/stable/api.html#digraph for the full list of supported parameters.

    Returns
    -------
    ax : matplotlib.axes.Axes
        The plot with single tree.
    r   NzBYou must install matplotlib and restart your session to plot tree.r7   r   rE   )r,   r  r¶   r&   r¸   rº   Úpng)ÚformatÚoffrA   )Úmatplotlib.imagerL   rM   rN   r#   rU   r   r   ÚwriteÚpipeÚseekÚimageÚimreadÚimshowÚaxis)r,   r-   r  r7   r8   r¶   r&   r¸   rº   r:   Ú
matplotlibrd   re   rj   rô   ÚsÚimgs                    r"   r   r   í  sê   € ðPiÛÝ'ð 
€zØÐÜ*¨7°IÔ>Ø—‘˜Q ¨7¸�Ó<‰ˆˆ2äð ØØØØØØ!ñð ñ€Eô 	‹	€AØ‡G�GˆE�J‰J˜eˆJÓ$Ô%Ø‡F�Fˆ1„IØ
×
Ñ
×
!Ñ
! !Ó
$€Cà‡I�Iˆc„NØ‡G�GˆE„NØ€Iøô3 ò iÜÐ^Ó_ÐehÐhûðiús   ‚
C Ã	CÃ
CÃC)Nrt   NNúFeature importancer  ÚFeaturesr<   NTNNTé   )NNgš™™™™™é?NNz=Split value histogram for feature with @index/name@ @feature@zFeature split valueÚCountNNT)NNNNNzMetric during trainingÚ
Iterationsrˆ   NNT)r   Nr  rõ   Né
   )Nr   NNNr  rõ   N)+Ú__doc__r§   Úcopyr   Úior   Útypingr   r   r   r   r	   r
   r   ÚnumpyrV   Úbasicr   r   r   r   r   Úcompatr   Úsklearnr   Ú__all__r  r*   r#   rZ   r±   r+   rý   r   r   r   r­   r´   r
  r   r   r   rA   r$   r"   ú<module>r,     sF  ðá ã Ý Ý ß I× IÑ Iã ç SÕ SÝ  Ý ò€ñ ÛðF¨ð F°sð F¸tó Fðl�eð l¨°©ð l¸#ó lð ,0ØØ*.Ø*.Ø/Ø0Ø&Ø!Ø&*ØØ-1ØØØ ñHØ�7˜IÐ%Ñ&ðHà(ðHð ðHð �5˜ ˜Ñ&Ñ
'ð	Hð
 �5˜ ˜Ñ&Ñ
'ðHð �C‰=ðHð �S‰MðHð �S‰MðHð ðHð ˜s‘mðHð ðHð �e˜E 5˜LÑ)Ñ*ðHð 
�#‰ðHð ðHð ˜‰}ðHð  ð!Hð" 	ó#Hð\ #'Ø+/ØØ*.Ø*.ØZØ1Ø#Ø-1ØØñsØ�7˜IÐ%Ñ&ðsà�3˜�8‰_ðsð ��S˜$�Ñ
ðsð 	)ð	sð
 ðsð �5˜ ˜Ñ&Ñ
'ðsð �5˜ ˜Ñ&Ñ
'ðsð �C‰=ðsð �S‰Mðsð �S‰Mðsð �e˜E 5˜LÑ)Ñ*ðsð 
�#‰ðsð ðsð ðsð 	ósðp !Ø)-Ø+/Ø*.Ø*.Ø3Ø(Ø&Ø-1ØØñIØ�4˜�?Ñ#ðIà�S‰MðIð ˜D ™IÑ&ðIð 	)ð	Ið
 �5˜ ˜Ñ&Ñ
'ðIð �5˜ ˜Ñ&Ñ
'ðIð �C‰=ðIð �S‰MðIð �S‰MðIð �e˜E 5˜LÑ)Ñ*ðIð 
�#‰ðIð ðIð 	óIðXà
ðð ðð ð	ð
 ðð 	óð&>°Uð >Èð >ÐPSó >ð`à�C˜�H‰~ð`ð �C‰yð`ð ˜˜c™ D˜Ñ)ð	`ð
 ˜‰}ð`ð ð`ð ˜$˜s™)Ñ$ð`ð ˜5 §¡¨\Ð!9Ñ:Ñ;ð`ð ð`ð ð`ð 	ó`ðJ Ø%)Ø Ø#Ø>BØ!ñ{Ø�7˜IÐ%Ñ&ð{àð{ð ˜˜S™	Ñ"ð{ð ˜‰}ð	{ð
 ð{ð ˜5 §¡¨\Ð!9Ñ:Ñ;ð{ð ð{ð ð{ð 	ó{ð@ ,0ØØ-1ØØ%)Ø Ø#Ø>BñdØ�7˜IÐ%Ñ&ðdà(ðdð ðdð �e˜E 5˜LÑ)Ñ*ð	dð
 
�#‰ðdð ˜˜S™	Ñ"ðdð ˜‰}ðdð ðdð ˜5 §¡¨\Ð!9Ñ:Ñ;ðdð ðdð 	ôdr$   