
    -i                     4   S r SSKJr  SSKJr  SSKJr  SSKrSSK	J
r
  SSKJrJrJrJr  SS	KJrJr  S
SKJrJrJrJr  S
SKJrJr  S r " S S5      r\" 5       r\" \\/\" \SSSS9S/SS// SQ\" 1 Sk5      /S/S/S/S/S/\" \SSSS9S/S\" \SSSS9S/S.SS9SSSSSSSSSSSSS.S j5       r " S S 5      r " S! S"\5      r  " S# S$\5      r!\" 0 S%S_S&\"S\" S'5      /_S(\" \SSSS9S/_S)SS/_S*/ SQ_S+\" 1 Sk5      /_S,S/_S-S/_S.S/_S/S/_S0S/_S1S/_S2S/_S3S/_S4\" \SSSS9S/_S5\"/_SS9 S>SSSSSSSSSSSSSS6S7.S8 jj5       r#S9 r$\" \\/SS/SS/\" \SSSS9S/\" \S
SSS9S/\" \SSSS9S/S/S:.SS9SSS;SSSS<.S= j5       r%g)?z:
This module defines export functions for decision trees.
    )Iterable)StringIO)IntegralN   )is_classifier)
HasMethodsInterval
StrOptionsvalidate_params)check_arraycheck_is_fitted   )DecisionTreeClassifierDecisionTreeRegressor
_criterion_tree)Treebuchheimc           
         / nSu  p#X#-  nX4-
  n[         R                  " SSSU -  5      R                  [        5       H  nUS-  nUS[	        US-  S-
  5      -
  -  nXHS4XS4SXH4SX4USU4USU4XHS4/n	U	[        U5         u  pn[        S	X-   -  5      [        S	X-   -  5      [        S	X-   -  5      /n	UR                  U	5        M     U$ )
zGenerate n colors with equally spaced hues.

Parameters
----------
n : int
    The number of colors required.

Returns
-------
color_list : list, length n
    List of n tuples of form (R, G, B) being the components of each color.
)g      ?g?   i  g     v@g      N@r   r   r      )nparangeastypeintabsappend)n
color_listsvcmhh_barxrgbrgbs                G/var/www/html/venv/lib/python3.13/site-packages/sklearn/tree/_export.py_color_brewr,      s     J DA	A	AYYr3	*11#6DS%!)q))* 1I1III1I1I1I
 c%j/aC15M"c#-&8Cqu<NP## 7&     c                       \ rS rSrS rSrg)Sentinel?   c                     g)Nz
"tree.dot" )selfs    r+   __repr__Sentinel.__repr__@   s    r-   r2   N)__name__
__module____qualname____firstlineno__r4   __static_attributes__r2   r-   r+   r/   r/   ?   s    r-   r/   left)closed
array-like)r=   booleanN>   allnonerootr>   no_validation)decision_tree	max_depthfeature_namesclass_nameslabelfilledimpuritynode_ids
proportionrounded	precisionaxfontsizeT)prefer_skip_nested_validationr?   F   )rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   c                \    [        U 5        [        UUUUUUUUU	U
US9nUR                  XS9$ )ac
  Plot a decision tree.

The sample counts that are shown are weighted with any sample_weights that
might be present.

The visualization is fit automatically to the size of the axis.
Use the ``figsize`` or ``dpi`` arguments of ``plt.figure``  to control
the size of the rendering.

Read more in the :ref:`User Guide <tree>`.

.. versionadded:: 0.21

Parameters
----------
decision_tree : decision tree regressor or classifier
    The decision tree to be plotted.

max_depth : int, default=None
    The maximum depth of the representation. If None, the tree is fully
    generated.

feature_names : array-like of str, default=None
    Names of each of the features.
    If None, generic names will be used ("x[0]", "x[1]", ...).

class_names : array-like of str or True, default=None
    Names of each of the target classes in ascending numerical order.
    Only relevant for classification and not supported for multi-output.
    If ``True``, shows a symbolic representation of the class name.

label : {'all', 'root', 'none'}, default='all'
    Whether to show informative labels for impurity, etc.
    Options include 'all' to show at every node, 'root' to show only at
    the top root node, or 'none' to not show at any node.

filled : bool, default=False
    When set to ``True``, paint nodes to indicate majority class for
    classification, extremity of values for regression, or purity of node
    for multi-output.

impurity : bool, default=True
    When set to ``True``, show the impurity at each node.

node_ids : bool, default=False
    When set to ``True``, show the ID number on each node.

proportion : bool, default=False
    When set to ``True``, change the display of 'values' and/or 'samples'
    to be proportions and percentages respectively.

rounded : bool, default=False
    When set to ``True``, draw node boxes with rounded corners and use
    Helvetica fonts instead of Times-Roman.

precision : int, default=3
    Number of digits of precision for floating point in the values of
    impurity, threshold and value attributes of each node.

ax : matplotlib axis, default=None
    Axes to plot to. If None, use current axis. Any previous content
    is cleared.

fontsize : int, default=None
    Size of text font. If None, determined automatically to fit figure.

Returns
-------
annotations : list of artists
    List containing the artists for the annotation boxes making up the
    tree.

Examples
--------
>>> from sklearn.datasets import load_iris
>>> from sklearn import tree

>>> clf = tree.DecisionTreeClassifier(random_state=0)
>>> iris = load_iris()

>>> clf = clf.fit(iris.data, iris.target)
>>> tree.plot_tree(clf)
[...]
rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rO   )rN   )r   _MPLTreeExporterexport)rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   exporters                 r+   	plot_treerW   G   sK    n M"#H ??=?00r-   c                   L    \ rS rSr           S	S jrS rS rS rS rSr	g)
_BaseTreeExporter   Nc                     Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        g NrS   )r3   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rO   s               r+   __init___BaseTreeExporter.__init__   s=     #*&
  $" r-   c           
         U R                   S   c`  [        U R                   S   [        R                  " U5         5      n[	        USS9n[        U5      S:X  a  SnOjUS   US   -
  SUS   -
  -  nOU[        U R                   S   S   5      nXR                   S   S   -
  U R                   S   S   U R                   S   S   -
  -  nU Vs/ s H#  n[        [        XE-  SU-
  S-  -   S5      5      PM%     nnS	[        U5      -  $ s  snf )
Nboundsr'   T)reverser   g        r   r   z
#%2x%2x%2x)	colorslistr   argmaxsortedlenr   roundtuple)r3   valuecolorsorted_valuesalphar"   s         r+   	get_color_BaseTreeExporter.get_color   s   ;;x (U+BIIe,<=>E"5$7M=!Q&&q)M!,<<]STEUAUV U+A./E[[2155H%a(4;;x+@+CCE HMMu!U59E	S'88!<=uMeEl** Ns   
*Dc                 h   SU R                   ;  Ga  [        UR                  S   5      U R                   S'   UR                  S:w  aP  [        R
                  " UR                  5      * [        R                  " UR                  5      * 4U R                   S'   OUR                  S   S:X  az  [        [        R                  " UR                  5      5      S:w  aM  [        R                  " UR                  5      [        R
                  " UR                  5      4U R                   S'   UR                  S:X  a_  UR                  U   SS S 24   nUR                  S   S:X  a5  [        U[        5      (       a   U R                   S   b  UR                  5       nOUR                  U   * nU R                  U5      $ )Nr'   r   r   r`   )rb   r,   	n_classes	n_outputsr   maxrI   minrf   uniqueri   
isinstancer   itemrm   )r3   treenode_idnode_vals       r+   get_fill_color _BaseTreeExporter.get_fill_color   sB   #!,T^^A->!?DKK~~" +-&&*?)?"&&BWAW(XH%"a'C		$**0E,F!,K)+

);RVVDJJ=O(PH%>>Qzz'*1a40Hq!Q&x22KK)5 $==? g..H~~h''r-   c           	      
   UR                   S:X  a  UR                  U   SS S 24   nOUR                  U   nU R                  S:H  =(       a    US:H  =(       d    U R                  S:H  nU R                  nUS   nU R                  (       a%  U(       a  US-  nXvS   [        U5      -   US   -   -  nUR                  U   [        R                  :w  a  U R                  b.  U R                  UR                  U      nU R                  U5      nOSUS   < UR                  U   < US	   < 3nUU< S
US   < S
[        UR                  U   U R                  5      < US   < 3-  nU R                  (       a  [!        U["        R$                  5      (       a  SnO?[!        U["        R&                  5      (       d  US:X  a  SnO[!        U[
        5      (       d  SnU(       a  USU-  -  nU[        [        UR                  U   U R                  5      5      US   -   -  nU(       a  US-  nU R(                  (       aM  SUR*                  U   -  [-        UR*                  S   5      -  n	U[        [        U	S5      5      S-   US   -   -  nO!U[        UR*                  U   5      US   -   -  nU R(                  (       d$  UR.                  S   S:w  a  XAR0                  U   -  nU(       a  US-  nUR.                  S   S:X  a!  [2        R4                  " X@R                  5      n
OU R(                  (       a!  [2        R4                  " X@R                  5      n
O{[2        R6                  " [2        R8                  " [2        R:                  " US5      S5      5      (       a  UR=                  [>        5      n
O [2        R4                  " X@R                  5      n
[        U
R=                  S5      5      RA                  SS5      n
U
RA                  SS5      RA                  SS5      n
UR.                  S   S:X  a2  UR                   S:X  a"  U
RA                  SS5      RA                  SS5      n
U
RA                  SUS   5      n
XzUS   -   -  nU RB                  b  UR.                  S   S:w  a  UR                   S:X  az  U(       a  US-  nU RB                  SLa5  U RB                  [2        RD                  " U5         nU R                  U5      nO&SUS   < [2        RD                  " U5      < US	   < 3nX{-  nURG                  US   5      (       a  US [I        US   5      *  nXvS    -   $ )!Nr   r   rA   r?   znode    r&   r    rQ   friedman_msesquared_errorrI   z%s = z
samples = g      Y@%zvalue = S32zb''z' ',  []z
 zclass = Ty   )%rq   ri   rG   
charactersrJ   strchildren_leftr   	TREE_LEAFrE   feature
str_escaperg   	thresholdrM   rI   ru   r   FriedmanMSEMSErK   n_node_samplesfloatrp   weighted_n_node_samplesr   aroundr?   equalmodr   r   replacerF   rd   endswithrf   )r3   rw   rx   	criterionri   labelsr   node_stringr   percent
value_text
class_names               r+   node_to_str_BaseTreeExporter.node_to_str  s   >>QJJw'1-EJJw'E **&77a<ODJJ%<O__
 n ==w&a=3w<7*Q-GGK g&%//9!!-,,T\\'-BC//'2 .
 qMLL)qM
 1dnnW-t~~>1	 K ==)Z%;%;<<*	Iz~~66):V+		3//&	w22E$--0$..ABZPQ]RK
 <'K??++G44uT=P=PQR=S7TT  3uWa01C7*Q-GGK3t227;<z!}LLK 4>>!#4#988AAE:%K>>!!5..9J__5..9JVVBHHRVVE1-q122c*J 5..9J**512::4E
''t4<<S"E
>>!!dnn&9#++C4<<S"EJ''z!}=
JqM11 (q!Q&!# z)t+!--bii.>?
!__Z8
 ,
 qMIIe$qM

 %K 
1..%&;Z]);(;<K]**r-   c                     U$ r\   r2   r3   strings     r+   r   _BaseTreeExporter.str_escape  s    r-   )rF   rE   rH   rO   rI   rG   rD   rJ   rM   rK   rL   NNNr?   FTFFFrQ   N)
r6   r7   r8   r9   r]   rm   rz   r   r   r:   r2   r-   r+   rY   rY      s@     !4+*(>q+fr-   rY   c                   l   ^  \ rS rSr\SSSSSSSSSSSSSS4U 4S jjrS	 rS
 rS rSS jr	S r
SrU =r$ )_DOTTreeExporteri  Nr?   FTrQ   	helveticac                    > [         TU ]  UUUUUUU	U
UUS9
  Xpl        Xl        Xl        Xl        Xl        U(       a
  / SQU l        O	/ SQU l        S/ 0U l        SS 0U l	        g )N
rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   )z&#35;z<SUB>z</SUB>z&le;z<br/>><)#r   r   <=z\n"r   leavesr`   )
superr]   leaves_parallelout_filespecial_charactersfontnamerotater   ranksrb   )r3   r   rD   rE   rF   rG   rH   r   rI   rJ   rK   r   rL   r   rM   r   	__class__s                   r+   r]   _DOTTreeExporter.__init__  s~    $ 	'#! 	 	
  / "4  UDODDO ^
&r-   c                    U R                   bP  [        U R                   5      UR                  :w  a-  [        S[        U R                   5      UR                  4-  5      eU R	                  5         [        U[        R                  5      (       a  U R                  USSS9  O%U R                  UR                  SUR                  S9  U R                  5         g )NzALength of feature_names, %d does not match number of features, %dr   rI   r   )rE   rf   n_features_in_
ValueErrorheadru   r   r   recursetree_r   tail)r3   rC   s     r+   rU   _DOTTreeExporter.export  s     )4%%&-*F*FF W4--.0L0LMN 
 			mUZZ00LLZL@LL,,a=;R;RLS		r-   c           	         U R                   (       a`  [        U R                  5       HG  nU R                  R	                  SSR                  S U R                  U    5       5      -   S-   5        MI     U R                  R	                  S5        g )Nz{rank=same ; z; c              3   $   #    U  H  ov   M     g 7fr\   r2   ).0r(   s     r+   	<genexpr>(_DOTTreeExporter.tail.<locals>.<genexpr>  s     /L;Ka;Ks   z} ;
})r   re   r   r   writejoin)r3   ranks     r+   r   _DOTTreeExporter.tail  si    tzz*###dii/L4::d;K/L&LLwV + 	C r-   c                    U R                   R                  S5        U R                   R                  S5        / nU R                  (       a  UR                  S5        U R                  (       a  UR                  S5        [        U5      S:  a-  U R                   R                  SSR                  U5      -  5        U R                   R                  SU R                  -  5        U R                   R                  S	5        U R                  (       a  U R                   R                  S
5        U R                   R                  SU R                  -  5        U R                  (       a  U R                   R                  S5        g g )Nzdigraph Tree {
znode [shape=boxrH   rL   r   z, style="%s", color="black"r   z, fontname="%s"] ;
z,graph [ranksep=equally, splines=polyline] ;
zedge [fontname="%s"] ;
zrankdir=LR ;
)
r   r   rH   r   rL   rf   r   r   r   r   )r3   rounded_filleds     r+   r   _DOTTreeExporter.head  s   ./ 	-.;;!!(+<<!!),~"MM-		.0II 	-=>G$ MM OP6FG;;MM 01 r-   c           	         U[         R                  :X  a  [        S[         R                  -  5      eUR                  U   nUR                  U   nU R
                  b  XPR
                  ::  GaD  U[         R                  :X  a(  U R                  S   R                  [        U5      5        Ol[        U5      U R                  ;  a#  [        U5      /U R                  [        U5      '   O0U R                  [        U5         R                  [        U5      5        U R                  R                  SX R                  XU5      4-  5        U R                  (       a-  U R                  R                  SU R                  X5      -  5        U R                  R                  S5        Ub  U R                  R                  SXB4-  5        US:X  a  [        R                  " SS	/5      U R                   S
-
  S-  -  nU R                  R                  S5        US:X  a"  U R                  R                  SUS   -  5        O!U R                  R                  SUS   -  5        U R                  R                  S5        U[         R                  :w  a-  U R#                  UUUUUS-   S9  U R#                  UUUUUS-   S9  g g U R                  S   R                  [        U5      5        U R                  R                  SU-  5        U R                  (       a  U R                  R                  S5        U R                  R                  SU-  5        Ub   U R                  R                  SXB4-  5        g g )NzInvalid node_id %sr   z%d [label=%sz, fillcolor="%s"r   z%d -> %dr   -   i      ?z  [labeldistance=2.5, labelangle=r   z%d, headlabel="True"]z%d, headlabel="False"]z ;
)r   parentdepthz%d [label="(...)"z, fillcolor="#C0C0C0"z%d -> %d ;
)r   r   r   r   children_rightrD   r   r   r   r   r   r   rH   rz   r   arrayr   r   )	r3   rw   rx   r   r   r   
left_childright_childangless	            r+   r   _DOTTreeExporter.recurse  s   eoo%1EOOCDD''0
))'2 >>!Unn%<U__,

8$++CL9U4::-*-g,

3u:&

3u:&--c'l;MM'+;+;D9+U!VV {{##&)<)<T)KK MM(!##J&1B$BCQ;XXr3i0T[[35F"4LMFMM''(JK!|++,CfQi,OP++,Dvay,PQ##F+U__,'"!)   '"!)   -" JJx ''G5MM 3g =>{{##$;<MM' 12!##Nf5F$FG "r-   c                 &    UR                  SS5      $ )Nr   z\")r   r   s     r+   r   _DOTTreeExporter.str_escapeC  s    ~~c5))r-   )r   rb   r   r   r   r   r   r   )Nr   )r6   r7   r8   r9   SENTINELr]   rU   r   r   r   r   r:   __classcell__r   s   @r+   r   r     sY      !-'^(!26CHJ* *r-   r   c                   `   ^  \ rS rSr           SU 4S jjrSS jrS	S jrSS jrSrU =r	$ )
rT   iH  c                    > [         TU ]  UUUUUUUUU	U
S9
  Xl        S/ 0U l        SS 0U l        / SQU l        [        5       U l        U R                  (       a  SU R                  S'   [        SS9U l	        g )	Nr   r   r`   )r   r   r   r   
r   r   rg   boxstylez<-)
arrowstyle)
r   r]   rO   r   rb   r   dict	bbox_argsrL   
arrow_args)r3   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rO   r   s               r+   r]   _MPLTreeExporter.__init__I  s     	'#! 	 	
 ! ^
&=<<)0DNN:&$/r-   c                 P   U R                  X!US9nUR                  U   [        R                  :w  a_  U R                  b  X@R                  ::  aC  U R                  UR                  U   X#US-   S9U R                  UR                  U   X#US-   S9/nO[        XQ5      $ [        XQ/UQ76 $ )Nr   r   r   )r   r   r   r   rD   
_make_treer   r   )r3   rx   etr   r   namechildrens          r+   r   _MPLTreeExporter._make_treeq  s     yAG$7NN"e~~&= $$W-rEAI    %%g.UQY   	H &&D-H--r-   c                 h   SS K Jn  SSKJn  Uc  UR	                  5       nUR                  5         UR                  5         U R                  SUR                  UR                  5      n[        U5      nUR                  5       S-   u  pxUR                  5       R                  n	UR                  5       R                  n
X-  nX-  nU R                  XaR                  X'U5        UR!                  5        Vs/ s H  n[#        X5      (       d  M  UPM     nnUR$                  R&                  R)                  5       nU H  nUR+                  U5        M     U R,                  c  U Vs/ s H(  nUR/                  5       =nc  M  UR                  5       PM*     nn[1        U Vs/ s H  nUR                  PM     sn5      n[1        U Vs/ s H  nUR                  PM     sn5      nUS   R3                  5       [5        UU-  UU-  5      -  nU H  nUR7                  U5        M     U$ s  snf s  snf s  snf s  snf )Nr   )
Annotationr   )matplotlib.pyplotpyplotmatplotlib.textr   gcaclearset_axis_offr   r   r   r   max_extentsget_window_extentwidthheightr   get_childrenru   figurecanvasget_rendererupdate_bbox_position_sizerO   get_bbox_patchrr   get_fontsizers   set_fontsize)r3   rC   rN   pltr   my_tree	draw_treemax_xmax_yax_width	ax_heightscale_xscale_yannannsrenderer
bbox_patchextentsextent	max_width
max_heightsizes                         r+   rU   _MPLTreeExporter.export  s   '.:B


//!]%8%8-:Q:QRW%	 !,,.2'')//((*11	"#Y 3 3RF!0P0Js4O0P 99##002C))(3  ==   C"%"4"4"66J /
,,.  
 @fV\\@AI'B'fmm'BCJ7'')C)#Wz%9- D   &  5 Q
 ABs$   2H 
H !H%<H%H*H/c           
      H   SS K Jn  [        SSU-  -
  SS9nU R                  b  U R                  US'   [        SSSU R                  R                  5       U R                  R                  5       S.UD6n	UR                  S	   U	S
   S'   UR                  S-   U-  XQR                  -
  S-
  U-  4n
U R                  b  X`R                  ::  Ga  U R                  (       a,  U R                  X!R                  R                  5      U	S   S'   OUR                  5       U	S   S'   UR                   c)  UR"                  " UR                  R$                  U
40 U	D6  OUR                   R                  S-   U-  XQR                   R                  -
  S-
  U-  4nUR"                  " UR                  R$                  X40 U	D6  UR                   R                   cX  US   U
S   -   S-  US   U
S   -   S-  4nUR                   R'                  5       U:X  a  Su  pOSu  pUR"                  " X4SU0UD6  UR(                   H  nU R+                  XX4XVS-   S9  M     g UR                   R                  S-   U-  XQR                   R                  -
  S-
  U-  4nSU	S   S'   UR"                  " SX40 U	D6  g )Nr   d   
   zaxes fraction)zorderxycoordsrO   center)havabbox
arrowpropsz
text.colorr%  	edgecolorr   r$  fcr   r   )zTrue  right)z  Falser;   r"  r   greyz
  (...)  
r2   )r   r   r   rO   r   copyr   rcParamsr&   r   rD   rH   rz   rw   rx   get_facecolorr   annotaterG   r;   r   r   )r3   noderw   rN   r  r  r   r	  common_kwargskwargsxy	xy_parenttext_pos
label_textlabel_hachilds                   r+   r   _MPLTreeExporter.recurse  s   ' e#$
 ==$(,M*%  
$$&++-	

 
 -0LL,F|[) vv|u$uvv~';u&DE>>!Unn%<{{'+':':4ARAR'Svt$')'7'7'9vt${{"DIIOOR:6: [[]]S(E1[[]]*S0E9	 DIIOOYEfE ;;%%- #11-2"11-2 H {{'')T1/B,
H/B,
KK
SS]SU"U!)L '
 $-&,5I $*F6N4 KKA&Ar-   )r   r   r   rb   rO   r   r   )r   r\   )
r6   r7   r8   r9   r]   r   rU   r   r:   r   r   s   @r+   rT   rT   H  sC     &0P.&1f?B ?Br-   rT   rC   r   r   rD   rE   rF   rG   rH   r   rI   rJ   rK   r   rL   r   rM   r   r   )rD   rE   rF   rG   rH   r   rI   rJ   rK   r   rL   r   rM   r   c                   Ub  [        USSSS9nUb!  [        U[        5      (       d  [        USSSS9n[        U 5        SnSn [        U[        5      (       a  [        USSS9nSnUc  Sn[        5       n[        UUUUUUUUU	U
UUUUUS	9nUR                  U 5        U(       a2  UR                  R                  5       U(       a  UR                  5         $ $  U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)
a  Export a decision tree in DOT format.

This function generates a GraphViz representation of the decision tree,
which is then written into `out_file`. Once exported, graphical renderings
can be generated using, for example::

    $ dot -Tps tree.dot -o tree.ps      (PostScript format)
    $ dot -Tpng tree.dot -o tree.png    (PNG format)

The sample counts that are shown are weighted with any sample_weights that
might be present.

Read more in the :ref:`User Guide <tree>`.

Parameters
----------
decision_tree : object
    The decision tree estimator to be exported to GraphViz.

out_file : object or str, default=None
    Handle or name of the output file. If ``None``, the result is
    returned as a string.

    .. versionchanged:: 0.20
        Default of out_file changed from "tree.dot" to None.

max_depth : int, default=None
    The maximum depth of the representation. If None, the tree is fully
    generated.

feature_names : array-like of shape (n_features,), default=None
    An array containing the feature names.
    If None, generic names will be used ("x[0]", "x[1]", ...).

class_names : array-like of shape (n_classes,) or bool, default=None
    Names of each of the target classes in ascending numerical order.
    Only relevant for classification and not supported for multi-output.
    If ``True``, shows a symbolic representation of the class name.

label : {'all', 'root', 'none'}, default='all'
    Whether to show informative labels for impurity, etc.
    Options include 'all' to show at every node, 'root' to show only at
    the top root node, or 'none' to not show at any node.

filled : bool, default=False
    When set to ``True``, paint nodes to indicate majority class for
    classification, extremity of values for regression, or purity of node
    for multi-output.

leaves_parallel : bool, default=False
    When set to ``True``, draw all leaf nodes at the bottom of the tree.

impurity : bool, default=True
    When set to ``True``, show the impurity at each node.

node_ids : bool, default=False
    When set to ``True``, show the ID number on each node.

proportion : bool, default=False
    When set to ``True``, change the display of 'values' and/or 'samples'
    to be proportions and percentages respectively.

rotate : bool, default=False
    When set to ``True``, orient tree left to right rather than top-down.

rounded : bool, default=False
    When set to ``True``, draw node boxes with rounded corners.

special_characters : bool, default=False
    When set to ``False``, ignore special characters for PostScript
    compatibility.

precision : int, default=3
    Number of digits of precision for floating point in the values of
    impurity, threshold and value attributes of each node.

fontname : str, default='helvetica'
    Name of font used to render text.

Returns
-------
dot_data : str
    String representation of the input tree in GraphViz dot format.
    Only returned if ``out_file`` is None.

    .. versionadded:: 0.18

Examples
--------
>>> from sklearn.datasets import load_iris
>>> from sklearn import tree

>>> clf = tree.DecisionTreeClassifier()
>>> iris = load_iris()

>>> clf = clf.fit(iris.data, iris.target)
>>> tree.export_graphviz(clf)
'digraph Tree {...
NFr   	ensure_2ddtypeensure_min_sampleswzutf-8)encodingT)r   rD   rE   rF   rG   rH   r   rI   rJ   rK   r   rL   r   rM   r   )r   ru   boolr   r   openr   r   rU   r   getvalueclose)rC   r   rD   rE   rF   rG   rH   r   rI   rJ   rK   r   rL   r   rM   r   own_filereturn_stringrV   s                      r+   export_graphvizrE    s*   V  #U$1
 z+t'D'D!5
 M"HM!h$$HcG<HH MzH#'#+!1
" 	&$$--/ NN 	  NN 8NN s   A9C0 0D
c                 j   ^ U4S jm/ nT" USU R                   U R                  U5        [        U5      $ )z2
Returns the depth of the subtree rooted in node.
c                 p   > XA/-  nX    nX0   nUS:w  a"  US:w  a  T" XQS-   X#U5        T" XaS-   X#U5        g g g )Nr}   r   r2   )current_nodecurrent_depthr   r   depthsr;   r(  compute_depth_s          r+   rK  &_compute_depth.<locals>.compute_depth_  s]     	/!*,2:%2+a' q(-	 &:r-   r   )r   r   rr   )rw   r.  rJ  rK  s      @r+   _compute_depthrM    s5    
 F4D..0C0CVLv;r-   )rC   rE   rF   rD   spacingdecimalsshow_weightsr  )rE   rF   rD   rN  rO  rP  c                  ^ ^^^^^^^	^
^^^^^ Ub  [        USSSS9nTb  [        TSSSS9m[        T 5        T R                  m[        T 5      (       a`  Tc  T R                  mOP[        T5      [        T R                  5      :w  a.  [        S[        T5       S[        T R                  5       S35      eSmS	m
S
mUb<  [        U5      TR                  :w  a#  [        STR                  [        U5      4-  5      e[        T [        5      (       a  SmT(       d  SmOSmUb6  TR                   Vs/ s H  nU[        R                  :w  a  X   OSPM     snm	O,TR                   Vs/ s H  nSR                  U5      PM     snm	S[        l        UU UU4S jmUUUU	U
UUUUUU4S jmT" SS5        [        R                  $ s  snf s  snf )ai  Build a text report showing the rules of a decision tree.

Note that backwards compatibility may not be supported.

Parameters
----------
decision_tree : object
    The decision tree estimator to be exported.
    It can be an instance of
    DecisionTreeClassifier or DecisionTreeRegressor.

feature_names : array-like of shape (n_features,), default=None
    An array containing the feature names.
    If None generic names will be used ("feature_0", "feature_1", ...).

class_names : array-like of shape (n_classes,), default=None
    Names of each of the target classes in ascending numerical order.
    Only relevant for classification and not supported for multi-output.

    - if `None`, the class names are delegated to `decision_tree.classes_`;
    - otherwise, `class_names` will be used as class names instead of
      `decision_tree.classes_`. The length of `class_names` must match
      the length of `decision_tree.classes_`.

    .. versionadded:: 1.3

max_depth : int, default=10
    Only the first max_depth levels of the tree are exported.
    Truncated branches will be marked with "...".

spacing : int, default=3
    Number of spaces between edges. The higher it is, the wider the result.

decimals : int, default=2
    Number of decimal digits to display.

show_weights : bool, default=False
    If true the classification weights will be exported on each leaf.
    The classification weights are the number of samples each class.

Returns
-------
report : str
    Text summary of all the rules in the decision tree.

Examples
--------

>>> from sklearn.datasets import load_iris
>>> from sklearn.tree import DecisionTreeClassifier
>>> from sklearn.tree import export_text
>>> iris = load_iris()
>>> X = iris['data']
>>> y = iris['target']
>>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
>>> decision_tree = decision_tree.fit(X, y)
>>> r = export_text(decision_tree, feature_names=iris['feature_names'])
>>> print(r)
|--- petal width (cm) <= 0.80
|   |--- class: 0
|--- petal width (cm) >  0.80
|   |--- petal width (cm) <= 1.75
|   |   |--- class: 1
|   |--- petal width (cm) >  1.75
|   |   |--- class: 2
NFr   r9  zaWhen `class_names` is an array, it should contain as many items as `decision_tree.classes_`. Got z  while the tree was fitted with z	 classes.z{} {} <= {}
z{} {} >  {}
z{} {}
z.feature_names must contain %d elements, got %dz{}{} weights: {}
z{}{}{}
z{}{} value: {}
z
feature_{}r   c                   > Sn[        T[        5      (       aY  T(       a@  U  Vs/ s H  nSR                  TXQ-  5      PM     nnSSR                  U5      S S -   S-   nU  US[	        U5      -   -  nO<U  Vs/ s H  nSR                  TU5      PM     nnSSR                  U5      S S -   S-   n[
        =R                  T	R                  USU5      -  sl        g s  snf s  snf )Nr   z{1:.{0}f}, r   r   r   z class: )ru   r   formatr   r   export_textreport)
ri   r   r   indentvalr!   rO  rC   rP  	value_fmts
         r+   	_add_leafexport_text.<locals>._add_leafT  s    m%;<< #" "((13NO"   BGGCL"--3':J//C>CDe=''!4eCDSb))C/Ci..vr3?? Es   C6Cc                   > SST-  -   U-  nUS T*  ST-  -   nS nTR                   S:X  a  TR                  U    S   nOTR                  U    R                  S   n[        R                  " U5      nTR
                  S   S:w  a  TR                   S:X  a  TU   nTR                  U    nUTS-   ::  Ga  SnUnUnTR                  U    [        R                  :w  a  TU    n	TR                  U    n
SR                  TU
5      n
[        =R                  TR                  X)U
5      -  sl        [        =R                  U-  sl        T" TR                  U    US-   5        [        =R                  TR                  X)U
5      -  sl        [        =R                  U-  sl        T" TR                  U    US-   5        g T" X5XB5        g [!        TU 5      nUS:X  a
  T" X5XB5        g SU-  n[        =R                  TR                  X,5      -  sl        g )	N|r   -r   r   r   z	{1:.{0}f}ztruncated branch of depth %d)rq   ri   Tr   rd   rp   r   r   r   TREE_UNDEFINEDr   rS  rT  rU  r   r   rM  )r.  r   rV  ri   r   r   info_fmtinfo_fmt_leftinfo_fmt_rightr   r   subtree_depthtrunc_reportrY  rF   rO  feature_names_left_child_fmtrD   print_tree_recurseright_child_fmtrN  r   truncation_fmts                r+   rg  'export_text.<locals>.print_tree_recursed  s   w'50	'"S7]2??aKK%a(EKK%''*EYYu%
??1"u!';$Z0J"'"?"?"EIM!H$M%N}}T"e&:&::%d+!OOD1	'..xC	""o&<&<V9&UU"""m3""5#6#6t#<eaiH""n&;&;F)&TT"""n4""5#7#7#=uqyI%*M*5$7M!%*M=M""n&;&;F&QQ"r-   r   )r   r   r   r   classes_rf   r   
n_featuresru   r   r   r   r_  rS  rT  rU  )rC   rE   rF   rD   rN  rO  rP  irY  re  rf  rg  rh  r   ri  rX  s   ` ````` @@@@@@@@r+   rT  rT    s   p  #U$1
 !5
 M"E]##'00K]%;%;!<<$% &../0	;  &O$NN S%75;K;K%K<]!345
 	

 -!788(	"I&	  ]]
" !"U%9%9 9MtC"

 ;@--H-Q,--a0-HK@ @ (R (RT q!I

 Is   -$F>#Gr\   )&__doc__collections.abcr   ior   numbersr   numpyr   baser   utils._param_validationr   r	   r
   r   utils.validationr   r   r   r   r   r   r   _reingold_tilfordr   r   r,   r/   r   rW   rY   r   rT   r   rE  rM  rT  r2   r-   r+   <module>rw     s1   %      W W ; N N -'T 
 : 02GHxD@$G&-6456+KK k;xD@$Gh4?F #'!* 
t1%$t1nC CLo*( o*dnB( nBb S$
7 34 	hxD@$G 	,-	
 	6 	*456 	9+ 	I; 	YK 	YK 	yk 	9+ 	I; 	yk 	hxD@$G  	SE!$ #''. c 
#c+*cL0 02GH&-$d+xD@$GXq$v>Eh4?F" #' wwr-   