
    ri1              #       L   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mZ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"	 	 	 	 	 	 	 	 	 	 	 	 	 	 dKd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$	 	 	 	 	 	 	 	 	 	 	 dLd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d0Z%	 	 	 	 	 	 	 	 	 	 	 dMdee	ef         d4ee         d5e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d6Z&d7e d8e d9ed:e#def
d;Z'd7e d<edefd=Z(d>e	eef         d?e
e         d@ee
e         df         dee!         dAedBee
e!                  dCeeej)        ef                  dDe!d'edefdEZ*	 	 	 	 	 	 dNdeeef         dHe!d?ee
e                  dee!         dAedCeeej)        ef                  dDe!d'edefdIZ+	 	 	 	 	 	 	 	 dOdeeef         dddHe!d$eee e f                  d%ee!         d?ee
e                  dee!         dAedCeeej)        ef                  d'edefdJZ,dS )PzPlotting library.    N)deepcopy)BytesIO)TYPE_CHECKINGAnyDictListOptionalTupleUnion   )Booster_data_from_pandas_is_zero_log_warning_MissingType)GRAPHVIZ_INSTALLEDMATPLOTLIB_INSTALLEDpd_DataFrame)	LGBMModel)create_tree_digraphplot_importanceplot_metricplot_split_value_histogram	plot_treeobjobj_namereturnc                 z    t          | t                    rt          |           dk    rt          | d          dS )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     g/var/www/html/pippo.cuttalo.com/services/trading/venv/lib/python3.11/site-packages/lightgbm/plotting.py_check_not_tuple_of_2_elementsr%      sA    c5!! FSXX]]8DDDEEE &3]    value	precisionc                 ^    |t          | t                    s| d| dnt          |           S )N.f)r    str)r'   r(   s     r$   
_float2strr-   !   s>    '0'<ZPUWZE[E['<e#i#####adejakakkr&   皙?Feature importanceFeaturesautoT   boosteraxzOptional[matplotlib.axes.Axes]heightxlimylimtitlexlabelylabelimportance_typemax_num_featuresignore_zerofigsizedpigridkwargsc           	         t           rddlm} nt          d          t	          | t
                    r|dk    r| j        }| j        } n-t	          | t                    r	|dk    rd}nt          d          | 
                    |          }|                                 }t          |          st          d          t          t          ||          d	 
          }|
rd |D             }|	|	dk    r||	 d         }t          | \  }}|.|t!          |d           |                    dd||          \  }}t%          j        t          |                    } |j        ||fd|d| t          ||          D ]7\  }}|                    |dz   ||dk    rt-          ||          n|d           8|                    |           |                    |           |t!          |d           ndt3          |          dz  f}|                    |           |t!          |d           ndt          |          f}|                    |           ||                    |           |+|                    d|          }|                    |           ||                    |           |                     |           |S )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.r1   split%booster must be Booster or LGBMModel.)r;   z&Booster's feature_importance is empty.c                     | d         S )Nr    )xs    r$   <lambda>z!plot_importance.<locals>.<lambda>   s
    1 r&   )keyc                 *    g | ]}|d          dk    |S )r   r   rF   ).0rG   s     r$   
<listcomp>z#plot_importance.<locals>.<listcomp>   s!    000qtaxx!xxxr&   r>   r   r>   r?   center)alignr5   gain)var6   皙?r7   z@importance_type@)!r   matplotlib.pyplotpyplotImportErrorr    r   r;   booster_r   r#   feature_importancefeature_namer"   
ValueErrorsortedzipr%   subplotsnparangebarhtextr-   
set_yticksset_yticklabelsmaxset_xlimset_ylim	set_titlereplace
set_xlabel
set_ylabelr@   )r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r(   rA   plt
importancerY   tupleslabelsvalues_ylocsrG   ys                             r$   r   r   %   s!   J  f'''''''deee'9%% Af$$%5O"	GW	%	% Af$$%O?@@@++O+LLJ''))Lz?? CABBBCj11~~FFFF 100V000#(81(<(<))**+&\NFF	z*7I>>>Q7<<2Ic&kk""EBGE6C&CCFCCCFE"" e e1
Aqo6O6O*Q	222UV[cddddMM%v&tV44443v;;$%KK&tV4444CKK KK
U 3_EE
f
fGGDMMMIr&   皙?=Split value histogram for feature with @index/name@ @feature@Feature split valueCountfeaturebins
width_coefc                    t           rddlm} ddlm} nt          d          t          | t                    r| j        } n$t          | t                    st          d          |                     ||d          \  }}t          j        |          dk    rt          d| d	          ||d
         |d         z
  z  }|dd         |d
d         z   dz  }|.|
t          |
d           |                    d
d
|
|          \  }} |j        ||fd|d| |t          |d           n-|d         |d         z
  }|d         |dz  z
  |d         |dz  z   f}|                    |           |j                             |d                     |t          |d           ndt+          |          dz  f}|                    |           |e|                    dt1          |                    }|                    dt          |t0                    rdnd          }|                    |           ||                    |           |	|                    |	           |                    |           |S )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.rD   F)rw   rx   xgboost_stylez3Cannot plot split value histogram, because feature z was not used in splittingr   rS   r   r>   rM   rN   )rO   widthr6   r.   T)integerr7   rR   z	@feature@z@index/name@nameindex)r   rT   rU   matplotlib.tickerr{   rV   r    r   rW   r   r#   get_split_value_histogramr^   count_nonzerorZ   r%   r]   barre   yaxisset_major_locatorrd   rf   rh   r,   rg   ri   rj   r@   )r3   rw   rx   r4   ry   r6   r7   r8   r9   r:   r>   r?   r@   rA   rk   r{   hist
split_binsr}   centredrp   range_results                         r$   r   r      s   D  q''''''1111111oppp'9%% A")) A?@@@88tch8iiD*	""rwrrrsss*Q-*Q-78E#2#ABB/14G	z*7I>>>Q7<<2
BF7D@@@@@@&tV4444!"~
151s 22JrN\TWEW4WXKKH{{4888999&tV44443t99s?#KKk3w<<88nGS9Q9Q/^vvW^``
U
f
fGGDMMMIr&   Metric during training
Iterations@metric@metricdataset_namesc                    t           rddlm} nt          d          t	          | t
                    rt          | j                  }nXt	          | t                    rt          |           }n3t	          | t                    rt          d          t          d          t          |          }|st          d          |.|	t          |	d           |                    dd|	|
	          \  }}|"t          |                                          }nBt	          |t"          t$          t&          f          r|st          d
          t          |          }t)          |          }||         }t          |          }|-|dk    rt+          d           |                                \  }}n||vrt/          d          ||         }t          |          }t1          |          }t3          |          }t5          |          }|                    |||           |D ]F}||         }||         }t1          g ||R  }t3          g ||R  }|                    |||           G|                    d           |t          |d           nd|f}|                    |           |t          |d           n||z
  }||dz  z
  ||dz  z   f}|                    |           ||                    |           ||                     |           |+|!                    d|          }|"                    |           |#                    |           |S )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.zbooster 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.r>   r   rM   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)locr6   r7   r.   r   )$r   rT   rU   rV   r    r   r   evals_result_dictr   r#   r"   rZ   r%   r]   iterkeyslistr!   setnextr   popitemKeyErrorrd   minrangeplotlegendre   rf   rg   ri   rh   rj   r@   )r3   r   r   r4   r6   r7   r8   r9   r:   r>   r?   r@   rk   eval_resultsnum_datarp   dataset_names_iterr   metrics_for_one
num_metricresultsnum_iteration
max_result
min_resultx_r   s                             r$   r   r     s   r  b'''''''`aaa'9%% 	> 566	GT	"	" >((	GW	%	% > E
 
 	
 <===<  H :8999	z*7I>>>Q7<<2!,"3"3"5"566eS'9:: 1- 1OPPP!-00"##D"4(O_%%J~>>OPPP)1133((=>>>!&)LLMWJWJ	}		BGGBtG$$$" ) )&t,!&).'.:...
.'.:...

G4((((II&I&tV4444=!KK&tV4444!J.\C//lS>P1PQKK
U
f
F33
fGGDMMMIr&   fval	thresholdmissing_type_strdefault_leftc                    t          |          }t          j        |           r|t           j        k    rd} |t           j        k    rt          |           s$|t           j        k    rt          j        |           r|rdnd}n
| |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1Lz$ LL,<<<)))htnn)(((TZ-=-=(*7FF		"i//FFW	r&   
thresholdsc                     t          j        |           st          |           dk     rdS d |                    d          D             }t          |           |v rdndS )Nr   r   c                 ,    h | ]}t          |          S rF   )int)rK   ts     r$   	<setcomp>z=_determine_direction_for_categorical_split.<locals>.<setcomp>  s    ===c!ff===r&   ||r   )r   r   r   rC   )r   r   int_thresholdss      r$   *_determine_direction_for_categorical_splitr     sb    z$ 3t99q==w==j&6&6t&<&<===NYY.0066g=r&   	tree_info	show_infofeature_namesorientationconstraintsexample_casemax_category_valuesc                    t           rddlm}	 nt          d          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}

                    ddd|
           d| d         v r% | d         | d         d         d
d
d
u           nt          d          rd}                    d|dd           S )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.roottotal_countparentdecision	highlightr   Nc           
      D   d}d}d}|rd}d}	nd}d}	d| v r7d	}
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}U| d         dk    rt          |         | d                   }n+t          |         | d         | d         | d                   }| d         dk    r_| d                             d          }t	          |          k    r1| d         }d                    |dd                   dz   |d          z   }|dt          |           d!z  }d"D ]}|v r|                    d#          d          }|d$v r |d%t          | |                    d| z  }E|d&k    r|d%| d'| |          z  }]|d(k    r#|d%t          | d&         |z  d)z  d           d*z  }r*| d                  d+k    rd,}| d                  d k    rd-}d.}d/| d0} | d1         ||||o|d2k    3            | d4         ||||o|d5k    3           nd6}
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}                    |||
||||	|?           |                    |||||	@           dS dS )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.rC   split_featurez<B>z</B> zfeature <B> )r   r   r   r   )r   r   r   r   r   r   z||...||rS   z</B>)
split_gaininternal_valueinternal_weightinternal_countdata_percentagerp   >   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   )	rZ   r   r   rC   r"   joinr-   nodeedge)r   r   r   r   r   r   r   r   r   r   r   l_decr_decr   operatorr   r   r   r   category_valuesinfooutputaddr   r   r   graphr   r(   r   s                         r$   r   z_to_graphviz.<locals>.add  s    	 	EHHEHD  EEE[)IO$,,$o&$.. !GHHH04.00D 1M(KmM:KKKKEmEE(EEEI'(D00 J)-8T+EV! ! !II !G)-8"&{"3)-n)=%).%9	! ! !I O$,,"&{"3"9"9$"?"?''*===";/G $		/"1"*= > > J_]_M` `IA:i;;AAAAEp n n9$$!ZZ__R0FRRR!UDJ	)J)J!U!UV!U!UU!111!?!?!?4:!?!??!222!mD9I4J[4X[^4^`a)b)b!m!m!mm !tO45:: )ItO45;; )I  LLLEC,''#;	V(;    C-('#<	W(<     E.$|,..D2D.222EJ:d<&8)DDJJJJE	))TD,?!K!KTTTTy((<\(:<<< I--aD,>,Ls,RTU!V!Vaaaa LLLE

 	 		
 		
 		
 JJvtXUXJNNNN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   rF   )r   graphvizr   rV   r   r,   r   r   r	   boolattr	Exceptionr   )r   r   r   r(   r   r   r   r   rA   r   r  r   r   r  s    ``` ```    @@r$   _to_graphvizr    s      ^$$$$$$$\]]]hO38nhO+.hO8@hOQYZ]Q^hOkohO	hO hO hO hO hO hO hO hO hO hO hO hO hOT GfE!\11ddtG	JJwwJGGG9%5666+,!"234DE"$.	
 	
 	
 	
 	
 9::: M 	

86G
LLLLr&   r  
   
tree_indexc                    t          | t                    r| j        } n$t          | t                    st	          d          |                                 }|d         }	|                    dd          }
|                    dd          }|t          |	          k     r	|	|         }nt          d          |g }|t          |t          j
        t          f          r|j        dk    rt          d          |j        d	         d
k    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.
    rD   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.r1   )datarY   categorical_featurepandas_categorical)r   r   r   r(   r   r   r   r   rF   )r    r   rW   r   r#   
dump_modelgetr"   
IndexErrorr^   ndarrayr   ndimrZ   r   r   r  r  )r3   r  r   r(   r   r   r   rA   model
tree_infosr   r  r   s                r$   r   r   f  s   b '9%% A")) A?@@@  E{#JIIot44M 99%;TBBC
OO##z*		6777	,\(BCC 	]|GX\]G]G][\\\a A%%CDDDlL11 	,!#$*#*#=	  
 L $A 
#(!/
 
 
 
 
r&   c	           
         t           rddl}
ddlm} nt	          d          |.|t          |d           |                    dd||          \  }}t          d| |||||d|	}t                      }|	                    |
                    d	                     |                    d           |
j                            |          }|                    |           |                    d
           |S )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.r>   r   rM   )r3   r  r   r(   r   r   png)formatoffrF   )r   matplotlib.imagerT   rU   rV   r%   r]   r   r   writepipeseekimageimreadimshowaxis)r3   r4   r  r>   r?   r   r(   r   r   rA   
matplotlibrk   rp   r  simgs                   r$   r   r     s   P  `'''''''^___	z*7I>>>Q7<<2 !   E 			AGGEJJeJ$$%%%FF1III


!
!!
$
$CIIcNNNGGENNNIr&   )Nr.   NNr/   r/   r0   r1   NTNNTr2   )NNrs   NNrt   ru   rv   NNT)NNNNNr   r   r   NNT)r   Nr2   r  Nr  )Nr   NNNr2   r  N)-__doc__r   copyr   ior   typingr   r   r   r   r	   r
   r   numpyr^   basicr   r   r   r   r   compatr   r   r   sklearnr   __all__r(  r,   r%   floatr   r-   r
  r   r   r   r   r   r  r  r   r   rF   r&   r$   <module>r5     s                  I I I I I I I I I I I I I I I I I I     S S S S S S S S S S S S S S J J J J J J J J J J          F Fs Ft F F F Fle l l# l l l l ,0*.*./0&!&*-1 C C7I%&C(C C 5&
'	C
 5&
'C C=C SMC SMC C smC C eE5L)*C 
#C C }C  !C" 	#C C C CR #'+/*.*.Z1#-1q q7I%&q38_q S$
q 	)	q
 q 5&
'q 5&
'q C=q SMq SMq eE5L)*q 
#q q q 	q q q ql !)-+/*.*.3(&-1I I4?#ISMI DI&I 	)	I
 5&
'I 5&
'I C=I SMI SMI eE5L)*I 
#I I 	I I I IX
  	
 	   $>U > >PS > > > >_CH~_Cy_ cD)_ }	_
 _ $s)$_ 5\!9:;_ _ _ 	_ _ _ _H %) #>B!{ {7I%&{{ S	"{ }	{
 { 5\!9:;{ { { 	{ { { {@ ,0-1%) #>Bd d7I%&d(d d eE5L)*	d
 
#d S	"d }d d 5\!9:;d d 	d d d d d dr&   