
    sii`                        d Z ddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZ ddlZddlZddlmZ dej        deddfdZd	ed
eej                 dededdf
dZej        ddededej        deded
eej                 dej        fdZdS )z#Testing code shared by other tests.    N)AnyCallableDictType)	ArrayLikeleafnum_parallel_treereturnc           	      6   t          | j        d                   D ]}}t          | j        d                   D ]`}t          | j        d                   D ]C}| |||ddf         }|j        d         |k    sJ t          j        ||d         k              sJ Da~dS )z'Validate output for predict leaf tests.r         N)rangeshapenpall)r   r	   ijk
tree_groups         \/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/xgboost/testing/shared.pyvalidate_leaf_outputr      s    4:a=!! ; ;tz!}%% 	; 	;A4:a=)) ; ;!!Q111*-
!'*.?????vjJqM9::::::	;	;; ;    dmatrixmodelXyc                 p   | j         dgdt          dt          dt          ffd}|| _          |d                              ||||fg           d         dk    sJ dd<   |                                } |d                              ||||fg           d         d	k    sJ | _         d
S )z/Assert that we don't create duplicated DMatrix.r   selfkwargsr
   c                 6    dxx         dz  cc<    | fi |S )Nr   r    )r   r   countold_inits     r   new_initz.validate_data_initialization.<locals>.new_init$   s0    aAx'''''r   r   )n_estimators)eval_setr   N)__init__r   r   fitcopy)r   r   r   r   r$   y_copyr"   r#   s         @@r   validate_data_initializationr+      s    
 HCE(s (c (h ( ( ( ( ( ( (  G	Eqaq!fX6668q====E!HVVXXF	Eqaq&k];;;8q====Gr   )r   fwparser_pathtree_methodc                    t          j                    5 }d} ||||          }|                    | |           t          j                            |d          }	|                    |	           t          |	dd          5 }
t          j	        |
          }ddd           n# 1 swxY w Y   t          j                            d|          }|J t          j                            |          }|j        J |j                            |           |                    |          }i }d	}|j        D ]}t%          |j                  }||z  }t)          |          D ]}}|                    |          r|                    |                    |          d          d
||                    |          <   Z||                    |          xx         d
z  cc<   ~t1          j        t5          |                                                    }t9          |                                          }t9          t;          |           \  }}t=          j        ||d
          }|cddd           S # 1 swxY w Y   dS )z*Get feature weights using the demo parser.g      ?)r.   colsample_bynodefeature_weightsz
model.jsonrzutf-8)encodingN
JsonParserr   r   )deg) tempfileTemporaryDirectoryr(   ospathjoin
save_modelopenjsonload	importlibutilspec_from_file_locationmodule_from_specloaderexec_moduleModeltreeslennodesr   is_leafgetsplit_indexcollectionsOrderedDictsorteditemslistzipr   polyfit)r   r   r,   r-   r.   r   tmpdirr0   reg
model_pathfdspecjsonmsplitstotal_nodestreen_nodesnodtuplesr   vws                          r   get_feature_weightsrb   6   s    
	$	&	& %&e#-
 
 
 	1W\\&,77
z"""*cG444 	"IbMME	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" ~55lKPP//55{&&&&&&E""!#K 		5 		5D$*ooG7"K7^^ 5 5<<?? ::d..q11488@23F4++A..//4++A..///14////5 $VFLLNN%;%;<<bhhjj!!CL!!1Jq!###K% % % % % % % % % % % % % % % % % %s7   A.I/B#I/#B'	'I/*B'	+F7I//I36I3)__doc__rL   importlib.utilr?   r=   r8   r6   typingr   r   r   r   numpyr   xgboostxgbxgboost._typingr   ndarrayintr   XGBModelr+   XGBRegressorstrrb   r!   r   r   <module>ro      s|   ) )          				  , , , , , , , , , , , ,         % % % % % %;rz ;c ;d ; ; ; ;  s|, 1: ?H 	       B !$ 0/ / // / 	
	/
 / / / Z/ / / / / /r   