
    ;i?5                    N   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$  SSK%r&SSK'r(SSK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:  \(       a  SSKJ;r;   SSKJ<r<  / SQr?\R                  rA\R                  rB\$S   rC\$S   rD\$S   rE\$S   rF\#\G\H\I4   rJ\\G\\G\H4   4   rK\#\G\G\H\I4   rL\#\G\G\H\I\H4   rM\$\ \G   \ \N   S4   rO\$\ \G   S4   rP\$\ \H   \ \N   \&R                  \:\3\54   rR\$\&R                  \:4   rS\$\ \H   \ \ \H      \&R                  \:\9\7\3\54   rT\$\G\\&R                  \9\2\(R                  R                  S\ S   \ \&R                     \74
   rW\$\ \H   \ \N   \&R                  \:\9\3\54   rX\$\G\\&R                  \9\2\(R                  R                  \74   rY\$\ \H   \ \N   \&R                  \:\3\54   rZ\$\ \ \H      \ \ \N      \ \H   \ \N   \&R                  \:\9\7\3\54
   r[Sr\1 Skr] " S S\^5      r_S\HS\I4S jr`S\NS \GS\N4S! jraS"\&R                  S\#\&R                  \N4   4S# jrb " S$ S%\5      rc " S& S'5      rd\d" 5       qe\\fS('   S)qgS*qhS+\S,\GS\I4S- jri  SS+\S.\GS/\GSS4S0 jjrjS1\\G/S4   S\\G/S4   4S2 jrkS3\GSS4S4 jrlS3\GSS4S5 jrm\kS3\GSS4S6 j5       rnS3\oSS4S7 jrp\R                  " S8S95      (       d  \R                  \R                  lt        \R                  " S\R                  5      rv\v" \p5      \lv        \R                  " \R                  5      S:w  a&  \_" \R                  " 5       R                  S:5      5      e\N\H\I4ryS;\NSS4S< jrzS=\S\I4S> jr{S?\S\I4S@ jr|S?\S\I4SA jr}SB\&R                  SCSDS\&R                  4SE jr~S?\S\I4SF jrS?\SSG4SH jrS?\SSI4SJ jrS?\S\I4SK jrS?\SCSDSL\GS\&R                  4SM jrS?\S\I4SN jrS?\S\I4SO jrS?\S\I4SP jrS?\SSQ4SR jrS?\S\I4SS jr " ST SU5      rS?\7S\4SV jrS?\SCSDSL\GS\&R                  4SW jrSXSYSZ\NS\&R                  4S[ jrSXSYSZ\NS\&R                  4S\ jrSXSYSZ\NS\&R                  4S] jrSXSYSZ\NS\&R                  4S^ jrS_\GS\R                  4S` jrSa\Sb\ \   S\GR$                  4Sc jrS=\S\4Sd jrS\$\N\H\G\ 4   S\G4Se jrS?\!\\G\4      S\G4Sf jr " Sg Sh5      r " Si Sj\5      rSSk jr " Sl Sm5      rSn\GS \\G\4   So\S\\G\4   4Sp jrSqr SrSrSrrSsr SrSr SrSrSrrSsr SrSr SrSr \\\\\St.r \\Su.rS?\&R                  S\&R                  4Sv jrS?\&R                  S\#\E\N\&R                  4   4Sw jrS?\&R                  S\#\C\N\&R                  4   4Sx jrSC\S\I4Sy jrSz\:SS4S{ jrS?\9S|SDS\&R                  4S} jrS?\9S~\PS\OS\!\ \       S\#\&R                  \ \G   \$\ \G   \ \N   4   \ \    4   4
S jr SS\!\ \       S\!\$\G\4      S\G4S jjr  SS\!\$\G\4      S\!\G   S\!\ \       4S jjr " S S\GRn                  5      r " S S5      r " S S5      r\\&R                  \/\#\&R                  \&R                  4   4   r\$\\&R                  \/\J4   \\&R                  \/\ \J   4   4   r " S S5      rg! \= a
    SSK>J<r<   GNwf = f)zWrapper for C API of LightGBM.   )_LIB    N)OrderedDict)deepcopy)Enum)wraps)SEEK_ENDenviron)getsize)Path)NamedTemporaryFile)TYPE_CHECKINGAnyCallableDictIterableIteratorListOptionalSetTupleUnion)CFFI_INSTALLEDPANDAS_INSTALLEDPYARROW_INSTALLED
arrow_cffiarrow_is_booleanarrow_is_floatingarrow_is_integerconcatdt_DataTablepa_Arraypa_chunked_arraypa_ChunkedArray
pa_computepa_Tablepd_CategoricalDtypepd_DataFrame	pd_Series)Literal)	TypeGuard)BoosterDatasetLGBMDeprecationWarningLightGBMErrorregister_loggerSequence)zctypes._Pointer[ctypes.c_int32]zctypes._Pointer[ctypes.c_int64])z-ctypes.Array[ctypes._Pointer[ctypes.c_int32]]z-ctypes.Array[ctypes._Pointer[ctypes.c_int64]])zctypes._Pointer[ctypes.c_float]z ctypes._Pointer[ctypes.c_double])z-ctypes.Array[ctypes._Pointer[ctypes.c_float]]z.ctypes.Array[ctypes._Pointer[ctypes.c_double]]zLiteral['auto']r1   gz8>   ovaovrsoftmax
multiclassmulticlassovamulticlass_ovac                       \ rS rSrSrSrg)r/      zError thrown by LightGBM. N__name__
__module____qualname____firstlineno____doc____static_attributes__r:       aC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\lightgbm/basic.pyr/   r/      s    #rB   r/   xreturnc                 >    [         * U s=:*  =(       a	    [         :*  $ s  $ N)ZERO_THRESHOLDrD   s    rC   _is_zerorJ      s    ?a11>1111rB   
total_nrowparamsc           	          [         R                  " S5      n[        [        R                  " [         R
                  " U 5      [        U5      [         R                  " U5      5      5        UR                  $ )Nr   )	ctypesc_int
_safe_callr   LGBM_GetSampleCountc_int32_c_strbyrefvalue)rK   rL   
sample_cnts      rC   _get_sample_countrW      sR    aJ  NN:&6NLL$	
 rB   matc                 .   U R                   [        R                  [        R                  4;   a  U R                   nO[        R                  nU R                  S   (       a	  Sn[
        nOSn[        n[        R                  " XUS9nUR                  US9U4$ )NF_CONTIGUOUSFC)dtypeorderr^   )	r]   npfloat32float64flags_C_API_IS_COL_MAJOR_C_API_IS_ROW_MAJORasarrayravel)rX   r]   r^   layoutdatas        rC   _np2d_to_np1drj      ss    
yyRZZ,,		


yy $$::ce4D::E:"F**rB   c                        \ rS rSrSrSrSrSrg)_MissingType   NoneNaNZeror:   N)r<   r=   r>   r?   NONENANZEROrA   r:   rB   rC   rl   rl      s    D
CDrB   rl   c                   8    \ rS rSrS\SS4S jrS\SS4S jrSrg)_DummyLogger   msgrE   Nc                     [        U5        g rG   )printselfrw   s     rC   info_DummyLogger.info   s	    c
rB   c                 .    [         R                  " USS9  g )N   )
stacklevel)warningswarnrz   s     rC   warning_DummyLogger.warning   s    ca(rB   r:   )r<   r=   r>   r?   strr|   r   rA   r:   rB   rC   ru   ru      s(      )3 )4 )rB   ru   _LOGGERr|   r   loggermethod_namec                 ,    [        [        XS 5      5      $ rG   )callablegetattr)r   r   s     rC   _has_methodr      s    GF677rB   info_method_namewarning_method_namec                 t    [        X5      (       a  [        X5      (       d  [        SU SU S35      eU qUqUqg)a  Register custom logger.

Parameters
----------
logger : Any
    Custom logger.
info_method_name : str, optional (default="info")
    Method used to log info messages.
warning_method_name : str, optional (default="warning")
    Method used to log warning messages.
zLogger must provide 'z' and 'z' methodN)r   	TypeErrorr   _INFO_METHOD_NAME_WARNING_METHOD_NAME)r   r   r   s      rC   r0   r0      sL      v00F8`8`/0@/AI\H]]efgg G(.rB   funcc                 L   ^ ^ / m[        T 5      S[        SS4U U4S jj5       nU$ )z;Join log messages from native library which come by chunks.rw   rE   Nc                    > U R                  5       S:X  a  SR                  T5      n / mT" U 5      $ TR                  U 5        g )N )stripjoinappend)rw   r   msg_normalizeds    rC   wrapper)_normalize_native_string.<locals>.wrapper  s>     99;"''.)CN9!!#&rB   )r   r   )r   r   r   s   ` @rC   _normalize_native_stringr     s3     "N
4['S 'T ' ' NrB   rw   c                 8    [        [        [        5      " U 5        g rG   r   r   r   rw   s    rC   	_log_infor     s    G&',rB   c                 8    [        [        [        5      " U 5        g rG   )r   r   r   r   s    rC   _log_warningr     s    G)*3/rB   c                 8    [        [        [        5      " U 5        g rG   r   r   s    rC   _log_nativer     s    G&',rB   c                 J    [        [        U R                  S5      5      5        g)z.Redirect logs from native library into Python.utf-8N)r   r   decoder   s    rC   _log_callbackr     s    CJJw'()rB   LIGHTGBM_BUILD_DOCFr   retc                 j    U S:w  a-  [        [        R                  " 5       R                  S5      5      eg)zpCheck the return value from C API call.

Parameters
----------
ret : int
    The return value from C API calls.
r   r   N)r/   r   LGBM_GetLastErrorr   )r   s    rC   rP   rP   0  s/     axD224;;GDEE rB   objc                 H     [        U 5        g! [        [        4 a     gf = f)zCCheck whether object is a number or not, include numpy number, etc.TF)floatr   
ValueErrorr   s    rC   _is_numericr   <  s*    c
z"  s    !!ri   c                 t    [        U [        R                  5      =(       a    [        U R                  5      S:H  $ )z(Check whether data is a numpy 1-D array.r   
isinstancer`   ndarraylenshaperi   s    rC   _is_numpy_1d_arrayr   G  s%    dBJJ'@C

Oq,@@rB   c                     [        U [        R                  5      (       d  gU R                  n[	        U5      S:H  =(       a    US   S:H  $ )z+Check whether data is a column numpy array.F   r   )r   r`   r   r   r   )ri   r   s     rC   _is_numpy_column_arrayr   L  s:    dBJJ''JJEu:?,uQx1},rB   arrayr]   znp.typing.DTypeLikec                 F    U R                   U:X  a  U $ U R                  USS9$ )z Cast numpy array to given dtype.Fr]   copy)r]   astype)r   r]   s     rC   _cast_numpy_array_to_dtyper   T  s&    {{e<<e%<00rB   c                 h    [        U [        5      =(       a    U (       + =(       d    [        U S   5      $ )z!Check whether data is a 1-D list.r   )r   listr   r   s    rC   _is_1d_listr   [  s$    dD!H4x'G;tAw3GHrB   zTypeGuard[List[np.ndarray]]c                 T    [        U [        5      =(       a    [        S U  5       5      $ )Nc              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frG   )r   r`   r   .0rD   s     rC   	<genexpr>+_is_list_of_numpy_arrays.<locals>.<genexpr>a  s     )RT*Q

*C*CTs   ')r   r   allr   s    rC   _is_list_of_numpy_arraysr   `  s    dD!Rc)RT)R&RRrB   zTypeGuard[List[Sequence]]c                 T    [        U [        5      =(       a    [        S U  5       5      $ )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frG   )r   r1   r   s     rC   r   (_is_list_of_sequences.<locals>.<genexpr>e  s     )P4a*Q*A*A4s   r   r   s    rC   _is_list_of_sequencesr   d  s    dD!Pc)P4)P&PPrB   c                     [        U 5      =(       d4    [        U 5      =(       d"    [        U 5      =(       d    [        U [        5      $ )z'Check whether data is a 1-D collection.)r   r   r   r   r)   r   s    rC   _is_1d_collectionr   h  s2    d#w'=d'Cw{SWGXw\fgkmv\wwrB   namec                    [        U 5      (       a  [        X5      $ [        U 5      (       a&  [        S5        U R	                  5       n[        X15      $ [        U 5      (       a  [        R                  " XS9$ [        U [        5      (       a7  [        U R                  5       R                  5        [        R                  " XS9$ [        S[        U 5      R                   SU S35      e)z Convert data to numpy 1-D array.z$Converting column-vector to 1d arrayr]   Wrong type() for z5.
It should be list, numpy 1-D array or pandas Series)r   r   r   r   rg   r   r`   rf   r   r)   _check_for_bad_pandas_dtypesto_framedtypesr   typer<   )ri   r]   r   r   s       rC   _list_to_1d_numpyr   m  s     $)$66		%	%;<

)%77	T		zz$,,	D)	$	$$T]]_%;%;<zz$,,$t*--.fTF:pq
 	
rB   c                     [        U [        R                  5      =(       a1    [        U R                  5      S:H  =(       a    U R                  S   S:  $ )z(Check whether data is a numpy 2-D array.r   r   r   r   s    rC   _is_numpy_2d_arrayr     s9    dBJJ'VC

Oq,@VTZZPQ]UVEVVrB   c                 v    [        U [        5      =(       a#    [        U 5      S:  =(       a    [        U S   5      $ )z!Check whether data is a 2-D list.r   )r   r   r   r   r   s    rC   _is_2d_listr     s*    dD!Lc$i!mLDG8LLrB   c                 j    [        U 5      =(       d"    [        U 5      =(       d    [        U [        5      $ )z'Check whether data is a 2-D collection.)r   r   r   r(   r   s    rC   _is_2d_collectionr     s#    d#Z{4'8ZJt\<ZZrB   z+TypeGuard[Union[pa_Array, pa_ChunkedArray]]c                 .    [        U [        [        45      $ )z&Check whether data is a PyArrow array.)r   r"   r$   r   s    rC   _is_pyarrow_arrayr     s    dX788rB   c                 "    [        U [        5      $ )z&Check whether data is a PyArrow table.)r   r&   r   s    rC   _is_pyarrow_tabler     s    dH%%rB   c                       \ rS rSr% Sr\\S'   \R                  \S'   \R                  \S'   S\S\R                  S\R                  4S jr	\
S\4S j5       r\
S\4S	 j5       rS
rg)_ArrowCArrayi  z<Simple wrapper around the C representation of an Arrow type.n_chunkschunksschemac                 (    Xl         X l        X0l        g rG   )r   r   r   )r{   r   r   r   s       rC   __init___ArrowCArray.__init__  s     rB   rE   c           	          [        [        R                  " S[        R                  " U R                  S   5      5      5      $ )zMReturns the address of the pointer to the list of chunks making up the array.	uintptr_tr   )intr   cast	addressofr   r{   s    rC   
chunks_ptr_ArrowCArray.chunks_ptr  s.     :??;
0D0DT[[QR^0TUVVrB   c                 V    [        [        R                  " SU R                  5      5      $ )z>Returns the address of the pointer to the schema of the array.r   )r   r   r   r   r   s    rC   
schema_ptr_ArrowCArray.schema_ptr  s     :??;<==rB   )r   r   r   N)r<   r=   r>   r?   r@   r   __annotations__r   CDatar   propertyr   r   rA   r:   rB   rC   r   r     s    FM j.>.> 
HXHX 
 WC W W >C > >rB   r   c           
         [        U [        5      (       a  U /nO`[        U [        5      (       a  U R                  nO>[        U [        5      (       a  U R                  5       nO[        S[        U 5       S35      e[        R                  " S[        U5      5      n[        R                  " S5      n[        U5       H  u  pE[        [        R                  " S[        R                  " X$   5      5      5      nUS:X  a3  [        [        R                  " SU5      5      nUR                  Xg5        Mt  UR                  U5        M     [!        [        U5      X#5      $ )z-Export an Arrow type to its C representation.zdata of type 'z' cannot be exported to Arrowzstruct ArrowArray[]zstruct ArrowSchema*r   r   )r   r"   r$   r   r&   
to_batchesr   r   r   newr   	enumerater   r   r   _export_to_cr   )ri   export_objectsr   r   ir   	chunk_ptrr   s           rC   _export_arrow_to_cr	    s    $!!	D/	*	*	D(	#	#*>$t*5RSTT ^^13~3FGF^^12F N+
Z5I5I&)5TUV	6Z__[&ABJY3Y' , FV44rB   c                 J   [        U 5      (       a  [        X5      $ [        U 5      (       a  [        R                  " XS9$ [        U [        5      (       a+  [        U R                  5        [        U R                  U5      $ [        S[        U 5      R                   SU S35      e)z Convert data to numpy 2-D array.r   r   r   zA.
It should be list of lists, numpy 2-D array or pandas DataFrame)r   r   r   r`   r   r   r(   r   r   valuesr   r   r<   )ri   r]   r   s      rC   _data_to_2d_numpyr    s     $)$664xx**$%%$T[[1)$++u==

d4j))*& 7J 	J rB   cptrctypes._Pointerlengthc                     [        U [        R                  " [        R                  5      5      (       a,  [        R
                  R                  X4S9R                  5       $ [        S5      e)z6Convert a ctypes float pointer array to a numpy array.r   zExpected float pointer)	r   rN   POINTERc_floatr`   	ctypeslibas_arrayr   RuntimeErrorr  r  s     rC   _cfloat32_array_to_numpyr    K    $v~~677||$$T$;@@BB344rB   c                     [        U [        R                  " [        R                  5      5      (       a,  [        R
                  R                  X4S9R                  5       $ [        S5      e)z7Convert a ctypes double pointer array to a numpy array.r  zExpected double pointer)	r   rN   r  c_doubler`   r  r  r   r  r  s     rC   _cfloat64_array_to_numpyr    sK    $v788||$$T$;@@BB455rB   c                     [        U [        R                  " [        R                  5      5      (       a,  [        R
                  R                  X4S9R                  5       $ [        S5      e)4Convert a ctypes int pointer array to a numpy array.r  zExpected int32 pointer)	r   rN   r  rR   r`   r  r  r   r  r  s     rC   _cint32_array_to_numpyr    r  rB   c                     [        U [        R                  " [        R                  5      5      (       a,  [        R
                  R                  X4S9R                  5       $ [        S5      e)r  r  zExpected int64 pointer)	r   rN   r  c_int64r`   r  r  r   r  r  s     rC   _cint64_array_to_numpyr"    r  rB   stringc                 L    [         R                  " U R                  S5      5      $ )z$Convert a Python string to C string.r   )rN   c_char_pencode)r#  s    rC   rS   rS     s    ??6==122rB   ctyper  c                 $    U [        U5      -  " U6 $ )z"Convert a Python array to C array.r   )r'  r  s     rC   _c_arrayr*    s    CK&))rB   c                     [        U [        R                  [        R                  [        R                  45      (       a  U R                  5       $ [        U [        R                  5      (       a  U R                  5       $ U $ )z3Convert numpy classes to JSON serializable objects.)r   r`   integerfloatingbool_itemr   tolistr   s    rC   _json_default_with_numpyr1    sP    #

BKK:;;xxz	C	$	$zz|
rB   c                 ~    [        U [        5      (       a  SR                  S U  5       5      nSU S3$ [        U 5      $ )N,c              3   8   #    U  H  n[        U5      v   M     g 7frG   )r   )r   vals     rC   r   _to_string.<locals>.<genexpr>  s     2CHH   [])r   r   r   r   )rD   val_lists     rC   
_to_stringr;    s:    !T882228*A1vrB   c                    U b  U (       d  g/ nU R                  5        H  u  p#[        U[        [        [        45      (       d  [        U5      (       a5  UR                  U SSR                  [        [        U5      5       35        Mj  [        U[        [        [        45      (       d  [        U5      (       a  UR                  U SU 35        M  Uc  M  [        SU S[        U5      R                    35      e   SR                  U5      $ )z>Convert Python dictionary to string, which is passed to C API.r   =r3  zUnknown type of parameter:z, got: )itemsr   r   tuplesetr   r   r   mapr;  r   r   _NUMERIC_TYPESr   r   r   r<   )ri   pairskeyr5  s       rC   _param_dict_to_strrF    s    |4EJJLcD%-..2DS2I2ILLC5#((3z3+?"@!ABCc4899[=M=MLLC5#(_8VDIDVDVCWXYY ! 88E?rB   c                   <    \ rS rSrSrSS jrS\S\S\SS4S	 jrS
rg)	_TempFilei.  z,Proxy class to workaround errors on Windows.rE   c                     [        SSS9 nUR                  U l        [        U R                  5      U l        S S S 5        U $ ! , (       d  f       U $ = f)Nlightgbm_tmp_T)prefixdelete)r   r   r   path)r{   fs     rC   	__enter___TempFile.__enter__1  sF    tDDITYYDI E  ED s   ,A
Aexc_typeexc_valexc_tbNc                 x    U R                   R                  5       (       a  U R                   R                  5         g g rG   )rM  is_fileunlink)r{   rQ  rR  rS  s       rC   __exit___TempFile.__exit__7  s*    99II rB   )r   rM  )rE   rH  )	r<   r=   r>   r?   r@   rO  r   rW  rA   r:   rB   rC   rH  rH  .  s+    6 s C D rB   rH  c                       \ rS rSrSrSrg)r.   i>  zCustom deprecation warning.r:   Nr;   r:   rB   rC   r.   r.   >  s    %rB   r.   c                  <    Sn [         R                  " U [        SS9  g )NzSupport for 'datatable' in LightGBM is deprecated, and will be removed in a future release. To avoid this warning, convert 'datatable' inputs to a supported format (for example, use the 'to_numpy()' method).r   )categoryr   )r   r   r.   r   s    rC   #_emit_datatable_deprecation_warningr\  D  s    	6 
 MM# 61ErB   c                       \ rS rSrSr\S\\\\   4   4S j5       r	\
S\S\\   4S j5       r\
S\S\\   4S j5       r\
S\S\\   4S	 j5       rS
rg)_ConfigAliasesiM  NrE   c                     Sn [         R                  " S5      n[         R                  " U 5      n[         R                  " [         R                  " U5      5      n[        [        R                  " [         R                  " U 5      [         R                  " U5      U5      5        UR                  nX@:  a  [         R                  " U5      n[         R                  " [         R                  " U5      5      n[        [        R                  " [         R                  " U5      [         R                  " U5      U5      5        [        R                  " UR                  R                  S5      S S9$ )N   r   r   c                 `    U R                  5        VVs0 s H  u  pX/U-   _M     snn$ s  snnf rG   r?  )r   kvs      rC   <lambda>7_ConfigAliases._get_all_param_aliases.<locals>.<lambda>k  s/    adajajalImalY]YZ!SSTW*alImIms   *object_hook)rN   r!  create_string_bufferr%  r   rP   r   LGBM_DumpParamAliasesrT   rU   jsonloadsr   )
buffer_lentmp_out_lenstring_bufferptr_string_buffer
actual_lens        rC   _get_all_param_aliases%_ConfigAliases._get_all_param_aliasesQ  s   
nnQ'33J?"OOF,<,<],KL&&z*[)!	
 !&&
""77
CM &0@0@0O P**NN:.LL-% zz&&w/=m
 	
rB   argsc                     U R                   c  U R                  5       U l         [        5       nU H#  nUR                  U R	                  U5      5        M%     U$ rG   )aliasesrr  rA  update
get_sorted)clsrt  r   r  s       rC   get_ConfigAliases.getn  sG    ;;446CKeAJJs~~a() 
rB   r   c                 ~    U R                   c  U R                  5       U l         U R                   R                  X/5      $ rG   )rv  rr  rz  )ry  r   s     rC   rx  _ConfigAliases.get_sortedw  s1    ;;446CK{{tV,,rB   c                     U R                   c  U R                  5       U l         [        U5      nU H=  nU R                   R                  5        H  nX4;   d  M
  UR	                  U5          M;     M?     U$ rG   )rv  rr  rA  r  rw  )ry  rt  r   argrv  s        rC   get_by_alias_ConfigAliases.get_by_alias}  sa    ;;446CK$iC;;--/>JJw' 0 
 
rB   r:   )r<   r=   r>   r?   rv  staticmethodr   r   r   rr  classmethodr   rz  rx  r  rA   r:   rB   rC   r^  r^  M  s    G
Dd3i$8 
 
8  C   -c -d3i - -
 	 	S 	 	rB   r^  main_param_namedefault_valuec                    [        U5      n[        R                  U 5      nU Vs/ s H  oDU :w  d  M
  UPM     nnXR                  5       ;   a  U H  nUR	                  US5        M     U$ U H  nXQR                  5       ;   d  M  X   X'     O   XR                  5       ;   a  U H  nUR	                  US5        M     U$ X!U '   U$ s  snf )ab  Get a single parameter value, accounting for aliases.

Parameters
----------
main_param_name : str
    Name of the main parameter to get a value for. One of the keys of ``_ConfigAliases``.
params : dict
    Dictionary of LightGBM parameters.
default_value : Any
    Default value to use for the parameter, if none is found in ``params``.

Returns
-------
params : dict
    A ``params`` dict with exactly one value for ``main_param_name``, and all aliases ``main_param_name`` removed.
    If both ``main_param_name`` and one or more aliases for it are found, the value of ``main_param_name`` will be preferred.
N)r   r^  rx  keyspop)r  rL   r  rv  aparams         rC   _choose_param_valuer    s    & fF''8G!:'Q/%9q'G: ++-'EJJud#  KKM!&,mF# 
 ++-'EJJud#  ,?M- ;s
   	CCir   r   )labelweight
init_scoregroupposition)splitgainc                    [        U [        R                  5      (       ae  [        U R                  [        R                  5      (       a<  U R                  R
                  (       d!  [        S5        [        R                  " U 5      $ U $ )z2Fix the memory of multi-dimensional sliced object.zsUsage of np.ndarray subset (sliced data) is not recommended due to it will double the peak memory cost in LightGBM.)r   r`   r   baserc   c_contiguousr   r   r   s    rC   _convert_from_sliced_objectr    sW    $

##
499bjj(I(Izz&&J 774= KrB   c                    [        U 5      (       a  [        R                  " U 5      n [        U 5      (       Ga  [	        U 5      n U R
                  R                  (       d   eU R                  [        R                  :X  aD  U R                  R                  [        R                  " [        R                  5      5      n[        nOU R                  [        R                  :X  aD  U R                  R                  [        R                  " [        R                  5      5      n[         nO;[#        SU R                   S35      e[#        S[%        U 5      R&                   S35      eXU 4$ )z(Get pointer of float numpy array / list.z,Expected np.float32 or np.float64, met type()Unknown type()r   r`   rf   r   r  rc   r  r]   ra   rN   data_asr  r  _C_API_DTYPE_FLOAT32rb   r  _C_API_DTYPE_FLOAT64r   r   r<   ri   ptr_data	type_datas      rC   _c_float_arrayr    s    4zz$$*40zz&&&&::#{{**6>>&..+IJH,IZZ2::%{{**6>>&//+JKH,IJ4::,VWXYY-T
(;(;'<A>??&&rB   c                    [        U 5      (       a  [        R                  " U 5      n [        U 5      (       Ga  [	        U 5      n U R
                  R                  (       d   eU R                  [        R                  :X  aD  U R                  R                  [        R                  " [        R                  5      5      n[        nOU R                  [        R                  :X  aD  U R                  R                  [        R                  " [        R                  5      5      n[         nO;[#        SU R                   S35      e[#        S[%        U 5      R&                   S35      eXU 4$ )z&Get pointer of int numpy array / list.z(Expected np.int32 or np.int64, met type(r  r  )r   r`   rf   r   r  rc   r  r]   int32rN   r  r  rR   _C_API_DTYPE_INT32int64r!  _C_API_DTYPE_INT64r   r   r<   r  s      rC   _c_int_arrayr    s    4zz$$*40zz&&&&::!{{**6>>&..+IJH*IZZ288#{{**6>>&..+IJH*IFtzzlRSTUU-T
(;(;'<A>??&&rB   c                     [        [        S[        S 5      5      n[        U [        R                  [        R
                  [        R                  45      =(       a!    [        U [        R                  U45      (       + $ )Nfloat128)r   r`   r   
issubclassr,  r-  r.  timedelta64)r]   r  s     rC   _is_allowed_numpy_dtyper    sQ    r:tDz2Hebjj"++rxx@Aw*UZ]_]k]kmu\vJwFwwrB   pandas_dtypes_seriesc                     U R                  5        VVs/ s H(  u  p[        UR                  5      (       a  M!  U SU 3PM*     nnnU(       a  [        SSR	                  U5       35      eg s  snnf )Nz: zIpandas dtypes must be int, float or bool.
Fields with bad pandas dtypes: z, )r?  r  r   r   r   )r  column_namepandas_dtypebad_pandas_dtypess       rC   r   r     s     *>)C)C)E)E%K&|'8'89 	);-r,()E  
 XY]YbYbctYuXvw
 	
 s
    A+A+target_dtypec                     [        U R                  5         U R                  USS9$ ! [         a    U R	                  USS9R
                  s $ [         a!    U R                  U[        R                  S9s $ f = f)NFr   r   )r]   na_value)	r   r   to_numpyr   r   r  r   r`   nan)ri   r  s     rC   _pandas_to_numpyr  *  st     !-	B}}<e}<< < {{<e{4;;; B}}<"&&}AABs   ' $A7'A76A7feature_namecategorical_featurepandas_categoricalc                    [        U R                  5      S:w  d  U R                  S   S:  a  [        S5      eU R                  SS9n US:X  a%  U R                   Vs/ s H  n[        U5      PM     nn[        U R                  U R                  5       VVs/ s H  u  pE[        U[        5      (       d  M  UPM      nnnU Vs/ s H$  o@U   R                  R                  (       a  M"  UPM&     nnUc2  U Vs/ s H$  n[        X   R                  R                  5      PM&     nnO[        U5      [        U5      :w  a  [        S5      e[        Xc5       HT  u  pH[        X   R                  R                  5      [        U5      :w  d  M5  X   R                  R                  U5      X'   MV     [        U5      (       a5  X   R                  S	 5      R!                  S
["        R$                  05      X'   US:X  a  UnU R                   Vs/ s H  oUR&                  PM     n	nU	R)                  ["        R*                  5        ["        R,                  " U	6 n
[/        X
S9UUU4$ s  snf s  snnf s  snf s  snf s  snf )Nr   r   r   z/Input data must be 2 dimensional and non empty.F)deepautoz9train and valid dataset categorical_feature do not match.c                 .    U R                   R                  $ rG   )catcodesrI   s    rC   re  #_data_from_pandas.<locals>.<lambda>X  s    rB   r  )r   r   r   r   columnsr   zipr   r   r'   r  orderedr   
categoriesset_categoriesapplyreplacer`   r  r   r   ra   result_typer  )ri   r  r  r  colr]   cat_colscat_cols_not_orderedr[  	df_dtypesr  s              rC   _data_from_pandasr  ;  s    4::!tzz!}q0JKK 99%9 D v,0LL9LSCL9 '*$,,&Do&D

SXZmHn&DHo6>&\hs3immF[F[sh&\!HPQd49==#;#;<Qx=C 233XYY >MCDIMM,,-h? IMM88B	 ? 8}}--.CDLLbRTRXRX\Z f$2)-5I5RZZ >>9-L 	9	 3 : p&\Q 6s*   II4I!I%&I%5+I*I/	file_namec                     [         R                  " U [        S9nSU S3nUb(  [        US5       nUR	                  U5        S S S 5        U$ U$ ! , (       d  f       U$ = f)Ndefaultz
pandas_categorical:
r  )rk  dumpsr1  openwrite)r  r  categorical_json
pandas_strrN  s        rC   _dump_pandas_categoricalr  k  sd     zz"4>VW()9(:"=J)S!QGGJ ": "!s   A
A	model_strc                    Sn[        U5      * nU b  [        U 5      * n[        U S5       n [        X45      nUR	                  U[
        5        UR                  5       n[        U5      S:  a  OUS-  nMH  S S S 5        WS   R                  S5      R                  5       nUR                  U5      (       d"  US   R                  S5      R                  5       nO(Ub%  UR                  SSU5      nXS  R                  5       nWR                  U5      (       a"  [        R                  " U[        U5      S  5      $ g ! , (       d  f       N= f)	Nzpandas_categorical:rbr   r  r   r  r   )r   r   r  maxseekr	   	readlinesr   r   
startswithrfindrk  rl  )	r  r  
pandas_keyoffset
max_offsetrN  lines	last_lineidxs	            rC   _load_pandas_categoricalr  w  s+    'J*oFi((
)T"aV0vx(u:?!  # "I$$W-335	##J//b	((1779I		oodAv.dO))+	J''zz)C
O$5677# #"s   A
D88
Ec                       \ rS rSrSrSr\R                  S\\	\
\\	   4   S\R                  4S j5       r\R                  S\	4S j5       rSrg	)
r1   i  a  
Generic data access interface.

Object should support the following operations:

.. code-block::

    # Get total row number.
    >>> len(seq)
    # Random access by row index. Used for data sampling.
    >>> seq[10]
    # Range data access. Used to read data in batch when constructing Dataset.
    >>> seq[0:100]
    # Optionally specify batch_size to control range data read size.
    >>> seq.batch_size

- With random access, **data sampling does not need to go through all data**.
- With range data access, there's **no need to read all data into memory thus reduce memory usage**.

.. versionadded:: 3.3.0

Attributes
----------
batch_size : int
    Default size of a batch.
i   r  rE   c                     [        S5      e)a  Return data for given row index.

A basic implementation should look like this:

.. code-block:: python

    if isinstance(idx, numbers.Integral):
        return self._get_one_line(idx)
    elif isinstance(idx, slice):
        return np.stack([self._get_one_line(i) for i in range(idx.start, idx.stop)])
    elif isinstance(idx, list):
        # Only required if using ``Dataset.subset()``.
        return np.array([self._get_one_line(i) for i in idx])
    else:
        raise TypeError(f"Sequence index must be integer, slice or list, got {type(idx).__name__}")

Parameters
----------
idx : int, slice[int], list[int]
    Item index.

Returns
-------
result : numpy 1-D array or numpy 2-D array
    1-D array if idx is int, 2-D array if idx is slice or list.
z=Sub-classes of lightgbm.Sequence must implement __getitem__()NotImplementedError)r{   r  s     rC   __getitem__Sequence.__getitem__  s    8 ""abbrB   c                     [        S5      e)z"Return row count of this sequence.z9Sub-classes of lightgbm.Sequence must implement __len__()r  r   s    rC   __len__Sequence.__len__  s     ""]^^rB   r:   N)r<   r=   r>   r?   r@   
batch_sizeabcabstractmethodr   r   slicer   r`   r   r  r  rA   r:   rB   rC   r1   r1     sp    6 JcuS%c%:; c

 c c: 	_ _ _rB   c                   \   \ rS rSrSrS\S\\\      S\\	\
4   S\4S jr\SS	S\\	\
4   S
S 4S j5       r\S\\	\4   S\\	\
4   S
S 4S j5       rS6S jrS
\\	\
4   4S jr       S7S\S\S\S\S\S\S\S\S
\\R.                  \R2                  R4                  \\R2                  R4                     4   4S jjrS\S\S\S\S
\4
S jrS\R.                  S\S\S\S\\R.                     S
\\R.                  \4   4S jrS\R.                  S\S\S\S
\\R.                  \4   4
S  jrS!\\R2                  R@                  \R2                  RB                  4   S"\R.                  S#S$S%S$S&S$S'\S(\S)\S
\\\R2                  R@                     \\R2                  RB                     4   4S* jr"S+\R2                  RB                  S\S\S\S\\R.                     S
\\R.                  \4   4S, jr#S+\R2                  RB                  S\S\S\S
\\\\R2                  R@                     \\R2                  RB                     4   \4   4
S- jr$S+\R2                  RB                  S\S\S\S
\\R.                  \4   4
S. jr%S/\R2                  R@                  S\S\S\S
\\\\R2                  R@                     \\R2                  RB                     4   \4   4
S0 jr&S/\R2                  R@                  S\S\S\S
\\R.                  \4   4
S1 jr'S2\(S\S\S\S
\\R.                  \4   4
S3 jr)S
\4S4 jr*S5r+g)8_InnerPredictori  z_InnerPredictor of LightGBM.

Not exposed to user.
Used only for prediction, usually used for continued training.

.. note::

    Can be converted from Booster, but cannot be converted to Booster.
booster_handler  pred_parametermanage_handlec                    Xl         X@l        X l        [        U5      U l        [
        R                  " S5      n[        [        R                  " U R                   [
        R                  " U5      5      5        UR                  U l        g)a  Initialize the _InnerPredictor.

Parameters
----------
booster_handle : object
    Handle of Booster.
pandas_categorical : list of list, or None
    If provided, list of categories for ``pandas`` categorical columns.
    Where the ``i``th element of the list contains the categories for the ``i``th categorical feature.
pred_parameter : dict
    Other parameters for the prediction.
manage_handle : bool
    If ``True``, free the corresponding Booster on the C++ side when this Python object is deleted.
r   N)_handle!_InnerPredictor__is_manage_handler  rF  r  rN   rO   rP   r   LGBM_BoosterGetNumClassesrT   rU   	num_class)r{   r  r  r  r  out_num_classs         rC   r   _InnerPredictor.__init__  sg    * &"/"40@Q**]+	
 ',,rB   boosterr,   rE   c                     [         R                  " S5      n[        [        R                  " UR
                  [         R                  " U5      5      5        U " UR
                  UR                  USS9$ )zInitialize an ``_InnerPredictor`` from a ``Booster``.

Parameters
----------
booster : Booster
    Booster.
pred_parameter : dict
    Other parameters for the prediction.
r   Fr  r  r  r  )rN   rO   rP   r   LGBM_BoosterGetCurrentIterationr  rT   r  )ry  r  r  out_cur_iters       rC   from_booster_InnerPredictor.from_booster  s_     ||A00\*	
 "??&99)	
 	
rB   
model_filec           	      .   [         R                  " 5       n[         R                  " S5      n[        [        R
                  " [        [        U5      5      [         R                  " U5      [         R                  " U5      5      5        U " U[        US9USS9$ )zInitialize an ``_InnerPredictor`` from a text file containing a LightGBM model.

Parameters
----------
model_file : str or pathlib.Path
    Path to the model file.
pred_parameter : dict
    Other parameters for the prediction.
r   r  Tr  )
rN   c_void_prO   rP   r   LGBM_BoosterCreateFromModelfilerS   r   rT   r  )ry  r  r  r  out_num_iterationss        rC   from_model_file_InnerPredictor.from_model_file   sy      *#\\!_00s:'/0^,	
 )7*M)	
 	
rB   Nc                      U R                   (       a*  [        [        R                  " U R                  5      5        g g ! [
         a     g f = frG   )r   rP   r   LGBM_BoosterFreer  AttributeErrorr   s    rC   __del___InnerPredictor.__del__?  s>    	&&400>? ' 		s   :> 
A
Ac                     U R                   R                  5       nUR                  SS 5        UR                  SS 5        U$ )Nhandler  )__dict__r   r  )r{   thiss     rC   __getstate___InnerPredictor.__getstate__F  s5    }}!!#4 D!rB   ri   start_iterationnum_iteration	raw_score	pred_leafpred_contribdata_has_headervalidate_featuresc	                 ^
   [        U[        5      (       a  [        S5      e[        U[        5      (       a  U(       a  UR                   V	s/ s H  n	[        U	5      PM     n
n	[        R                  [        U
5      -  " 5       nU
 V	s/ s H  oR                  S5      PM     sn	USS& [        [        R                  " U R                  U[        R                  " [        U
5      5      5      5        [        U[        5      (       a  [        USSU R                   S9S   n["        nU(       a  [$        nU(       a  [&        nU(       a  [(        n[        U[
        [*        45      (       Ga	  [-        5        n[        [        R.                  " U R                  [1        [        U5      5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [1        U R2                  5      [1        UR4                  5      5      5        [6        R8                  " UR4                  [6        R:                  S9nUR<                  S   nSSS5        GO[        U[>        R@                  RB                  5      (       a  U RE                  UUUUS9u  pGOZ[        U[>        R@                  RF                  5      (       a  U RI                  UUUUS	9u  pGO[        U[6        RJ                  5      (       a  U RM                  UUUUS
9u  pO[O        U5      (       a  U RQ                  UUUUS9u  pO[        U[R        5      (       a,   [6        RT                  " U5      nU RM                  UUUUS
9u  pO[        U[Z        5      (       a-  []        5         U RM                  UR_                  5       UUUS
9u  pO? [a        S5        [>        R@                  RC                  U5      nU RE                  UUUUS9u  pU(       a  WRg                  [6        Rh                  5      n[        W[R        [>        R@                  Rj                  45      nU(       da  URl                  W:w  d  U(       d  U(       aC  URl                  U-  S:X  a  URo                  US5      nU$ [Y        SURl                   SU S35      eU$ s  sn	f s  sn	f ! , (       d  f       N= f! [V         a  n[Y        S5      UeSnAff = f! [V         a'  n[        S[c        U5      Rd                   35      UeSnAff = f)a  Predict logic.

Parameters
----------
data : str, pathlib.Path, numpy array, pandas DataFrame, pyarrow Table, H2O DataTable's Frame (deprecated) or scipy.sparse
    Data source for prediction.
    If str or pathlib.Path, it represents the path to a text file (CSV, TSV, or LibSVM).
start_iteration : int, optional (default=0)
    Start index of the iteration to predict.
num_iteration : int, optional (default=-1)
    Iteration used for prediction.
raw_score : bool, optional (default=False)
    Whether to predict raw scores.
pred_leaf : bool, optional (default=False)
    Whether to predict leaf index.
pred_contrib : bool, optional (default=False)
    Whether to predict feature contributions.
data_has_header : bool, optional (default=False)
    Whether data has header.
    Used only for txt data.
validate_features : bool, optional (default=False)
    If True, ensure that the features used to predict match the ones used to train.
    Used only if data is pandas DataFrame.

    .. versionadded:: 4.0.0

Returns
-------
result : numpy array, scipy.sparse or list of scipy.sparse
    Prediction result.
    Can be sparse or a list of sparse objects (each element represents predictions for one class) for feature contributions (when ``pred_contrib=True``).
zGCannot use Dataset instance for prediction, please use raw data insteadr   Nr  ri   r  r  r  r   r   csrr  r   predict_typecscr  r   r*  )rX   r  r   r*  )tabler  r   r*  z(Cannot convert data list to numpy array.z'Converting data to scipy sparse matrix.zCannot predict data for type r  zLength of predict result (z) cannot be divide nrow (r  )8r   r-   r   r(   r  r   rN   r%  r   r&  rP   r    LGBM_BoosterValidateFeatureNamesr  rO   r  r  _C_API_PREDICT_NORMAL_C_API_PREDICT_RAW_SCORE_C_API_PREDICT_LEAF_INDEX_C_API_PREDICT_CONTRIBr   rH  LGBM_BoosterPredictForFilerS   r  r   r`   loadtxtrb   r   scipysparse
csr_matrix_InnerPredictor__pred_for_csr
csc_matrix_InnerPredictor__pred_for_cscr   _InnerPredictor__pred_for_np2dr   '_InnerPredictor__pred_for_pyarrow_tabler   r   BaseExceptionr   r!   r\  r  r   r   r<   r   r  spmatrixsizereshape)r{   ri   r  r   r!  r"  r#  r$  r%  rD   
data_names	ptr_namesr*  rN  predsnrowerrr)  	is_sparses                      rC   predict_InnerPredictor.predictL  so   V dG$$effl++0A*.,,7,Q#a&,J73z?:=I7ABz!HHW-zBIaL55LLLLZ1 dL))$#$*#'#:#:	
 D -3L4L1LdS$K((33s4y)_5\2_5]3t223qvv	 

166<{{1~  ell5566-- /+)	 . KE4 ell5566-- /+)	 . KE4 bjj)).. /+)	 / KE4 t$$77 /+)	 8 KE4 d##Vxx~ .. /+)	 / KE4 l++/1..MMO /+)	 / KE4`FGll--d3 -- /+)	 . KE LL*EutU\\-B-B&CD	ejjD0IzzD A%dB/  !#=ejj\Ibcgbhhi!jkk] 8B4 \ ! V !KLRUUV( ! `"?T
@S@S?T UV\__`sI   SS0C5SS 
*S; 
S
S8'S33S8;
T,"T''T,rD  r*  c                    U[         :  a  [        S[          S35      e[        R                  " S5      n[	        [
        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      5      5        UR                  $ )zGet size of prediction result.zXLightGBM cannot perform prediction for data with number of rows greater than MAX_INT32 (zP).
You can split your data into chunks and then concatenate predictions for themr   )
_MAX_INT32r/   rN   r!  rP   r   LGBM_BoosterCalcNumPredictr  rO   rT   rU   )r{   r  r   rD  r*  n_predss         rC   __get_num_preds_InnerPredictor.__get_num_preds  s     *??Il K<<  ..#++T"\*_-]+W%		
 }}rB   rX   rC  c                 "   [        U5      u  pg[        U5      u  pn
U R                  UUUR                  S   US9nUc$  [        R
                  " U[        R                  S9nO3[        UR                  5      S:w  d  [        U5      U:w  a  [        S5      e[        R                  " S5      n[        [        R                  " U R                  U[        R                  " U	5      [        R                   " UR                  S   5      [        R                   " UR                  S   5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [#        U R$                  5      [        R&                  " U5      UR                  R)                  [        R*                  " [        R,                  5      5      5      5        XR.                  :w  a  [        S5      eXQR                  S   4$ )Nr   r  r   rD  r*  r   r   +Wrong length of pre-allocated predict array Wrong length for predict results)rj   r  _InnerPredictor__get_num_predsr   r`   emptyrb   r   r   rN   r!  rP   r   LGBM_BoosterPredictForMatr  rO   rR   rS   r  rT   r  r  r  rU   )r{   rX   r  r   r*  rC  ri   rh   r  type_ptr_data_rL  out_num_predss                rC   __inner_predict_np2d$_InnerPredictor.__inner_predict_np2d  s    %S)%3D%9"&&+'1%	 ' 
 =HHWBJJ7E"c%jG&;JKKq)**]+syy|,syy|,V$\*_-]+t**+]+$$V^^FOO%DE	
  )))?@@iil""rB   c           
         [        UR                  5      S:w  a  [        S5      eUR                  S   nU[        :  Ga  [        R
                  " [        U[        S9n[        R                  " S/[        U5      -   U/-   5       Vs/ s H  nU R                  X#Xt5      PM     nn[        R                  " S/U-   [        R                  S9R                  5       n	[        R                  " [        U5      [        R                  S9n
[        [        R                   " X5      [        XSS 5      5       H  u  nu  pU R#                  UUUUXU S9  M     X4$ U R#                  UUUUSS9$ s  snf )	zPredict for a 2-D numpy matrix.r   z1Input numpy.ndarray or list must be 2 dimensionalr   startstopstepr   r   N)rX   r  r   r*  rC  )r   r   r   rJ  r`   arangediffr   rS  r   intpcumsumrT  sumrb   r  array_split#_InnerPredictor__inner_predict_np2d)r{   rX   r  r   r*  rD  sectionsr  rL  n_preds_sectionsrC  chunkstart_idx_predend_idx_preds                 rC   __pred_for_np2d_InnerPredictor.__pred_for_np2d/  sb    syy>QPQQyy|*yyz:NH !tH~!5!>??A $$_QU?    "xxgRWWELLNHHS\<E9<s-s3CVWVXEY/Z:55 ))$3"/!-|< * 	: ;,, /+) -  's   E(cs	out_shapeout_ptr_indptrr  out_ptr_indicesout_ptr_dataindptr_type	data_typeis_csrc	                    US   n	US   n
U[         :X  a
  [        X:S9nOU[        :X  a
  [        X:S9nO[	        S5      eU[
        :X  a
  [        XYS9nOU[        :X  a
  [        XYS9nO[	        S5      e[        XIS9nUR                  R                  S   nU(       d  US-  n[        R                  " XR                  S   U-  5      n/ nSnU H  nUUR                  S   S-
     nUUUS   -   UU-    nUUUS   -   UU-    nUU-  nUR                  S   UR                  S   S-   /nU(       a4  UR                  [        R                  R!                  UUU4U5      5        M  UR                  [        R                  R#                  UUU4U5      5        M     [%        [&        R(                  " UUU[*        R,                  " U5      [*        R,                  " U5      5      5        [/        U5      S:X  a  US   $ U$ )Nr   r   r  z'Expected int32 or int64 type for indptrz)Expected float32 or float64 type for data)r  r  r  r"  r   r  r  r  r  indptrr   r`   r  r   r5  r6  r7  r9  rP   r   LGBM_BoosterFreePredictSparserN   rO   r   )r{   rn  ro  rp  rq  rr  rs  rt  ru  data_indices_len
indptr_len
out_indptrout_dataout_indicesper_class_indptr_shapeout_indptr_arrayscs_output_matricesr  	cs_indptrmatrix_indptr_len
cs_indicescs_datacs_shapes                          rC   __create_sparse_native&_InnerPredictor.__create_sparse_nativeY  s     %Q<q\
,,/^WJ../^WJEFF,,/\[H../\[HGHH,/[!#!3"a'"HHZ1A1A!1DG]1]^*I ))//!*<q*@ A$Vil%:VFW=WXJv	!4v@Q7QRG''FRXXa[1_5H"))%,,*A*A7JXaBbdl*mn"))%,,*A*A7JXaBbdl*mn + 	..[)Y'	
 !"a'%a((!!rB   r)  c                    [        UR                  5      S-
  nU R                  UUUUS9nUc$  [        R                  " U[        R
                  S9nO3[        UR                  5      S:w  d  [        U5      U:w  a  [        S5      e[        R                  " S5      n[        UR                  5      u  pn[        UR                  5      u  pnUR                  S   [        ::  d   eUR                  R                  [        R                   SS9n[#        [$        R&                  " U R(                  U	[        R*                  " U
5      UR                  R-                  [        R.                  " [        R0                  5      5      U[        R*                  " U5      [        R                  " [        UR                  5      5      [        R                  " [        UR                  5      5      [        R                  " UR                  S   5      [        R*                  " U5      [        R*                  " U5      [        R*                  " U5      [3        U R4                  5      [        R6                  " U5      UR                  R-                  [        R.                  " [        R8                  5      5      5      5        XxR:                  :w  a  [        S5      eXV4$ )	Nr   rP  r   rQ  r   Fr  rR  )r   rw  rS  r`   rT  rb   r   r   rN   r!  r  r  ri   rJ  indicesr   r  rP   r   LGBM_BoosterPredictForCSRr  rO   r  r  rR   rS   r  rT   r  rU   )r{   r)  r  r   r*  rC  rD  rL  rX  
ptr_indptrtype_ptr_indptrrW  r  rV  csr_indicess                  rC   __inner_predict_csr#_InnerPredictor.__inner_predict_csr  s    3::"&&+'%	 ' 
 =HHWBJJ7E"c%jG&;JKKq))5cjj)A&
Q%3CHH%="yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+]+$$V^^FOO%DE	
& )))?@@{rB   c                    [        UR                  5      u  pVn[        UR                  5      u  pn
UR                  R                  [        R                  SS9n[        nU[        :X  a*  [        R                  " [        R                  5      " 5       nO)[        R                  " [        R                  5      " 5       n[        R                  " [        R                  5      " 5       nU	[        :X  a*  [        R                  " [        R                  5      " 5       nO)[        R                  " [        R                   5      " 5       n[        R"                  " S[        R$                  S9n['        [(        R*                  " U R,                  U[        R.                  " U5      UR                  R1                  [        R                  " [        R                  5      5      U[        R.                  " U	5      [        R                  " [3        UR                  5      5      [        R                  " [3        UR                  5      5      [        R                  " UR4                  S   5      [        R.                  " U5      [        R.                  " U5      [        R.                  " U5      [7        U R8                  5      [        R.                  " U5      UR                  R1                  [        R                  " [        R                  5      5      [        R:                  " U5      [        R:                  " U5      [        R:                  " U5      5      5        U R=                  UUUUUUU	SS9n[3        UR                  5      S-
  nUU4$ )NFr  r   r   r   Trn  ro  rp  rq  rr  rs  rt  ru  )r  rw  r  ri   r  r   r`   r  _C_API_MATRIX_TYPE_CSRr  rN   r  rR   r!  r  r  r  rT  r  rP   r   LGBM_BoosterPredictSparseOutputr  rO   r  r   r   rS   r  rT   %_InnerPredictor__create_sparse_native)r{   r)  r  r   r*  r  r  __r  rV  rW  r  matrix_typerp  rq  rr  ro  matricesrD  s                      rC   __inner_predict_csr_sparse*_InnerPredictor.__inner_predict_csr_sparse  sC    +7szz*B'
R%3CHH%="kk(((>,00#^^FNN;=N#^^FNN;=N ..8:00!>>&..9;L!>>&//:<LHHQbhh/	00_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+[)  (()GH^,_-\*%	
, ..)+%'# / 	
 3::"~rB   c           
         U[         :X  a  U R                  UUUUS9$ [        UR                  5      S-
  nU[        :  Ga  S/[        [        R                  " [        U[        S95      -   U/-   n[        R                  " U5       Vs/ s H  opR                  X#Xt5      PM     nn[        R                  " S/U-   [        R                  S9R                  5       n	[        R                  " [        U5      [        R                  S9n
[!        [!        XfSS 5      [!        XSS 5      5       H!  u  u  pu  pU R#                  XU UUUXU S9  M#     X4$ U R#                  UUUUSS9$ s  snf )zPredict for a CSR data.r(  r   r   r\  r   N)r)  r  r   r*  rC  )r2  )_InnerPredictor__inner_predict_csr_sparser   rw  rJ  r   r`   r`  ra  rS  r   rb  rc  rT  rd  rb   r  "_InnerPredictor__inner_predict_csr)r{   r)  r  r   r*  rD  rg  r  rL  rh  rC  	start_idxend_idxrj  rk  s                  rC   __pred_for_csr_InnerPredictor.__pred_for_csr  s~    1122 /+)	 3   3::"*sT"))*4j"YZZ^b]ccHfhfmfmnvfwxfwab++OA\fwGx!xxgRWWELLNHHS\<EHKHqrl+S1ATUTVCW-XID$&D~ ((g.$3"/!-|< ) 	I ;++ /+) ,  ! ys   E$r,  c                    [        UR                  5      u  pVn[        UR                  5      u  pn
UR                  R                  [        R                  SS9n[        nU[        :X  a*  [        R                  " [        R                  5      " 5       nO)[        R                  " [        R                  5      " 5       n[        R                  " [        R                  5      " 5       nU	[        :X  a*  [        R                  " [        R                  5      " 5       nO)[        R                  " [        R                   5      " 5       n[        R"                  " S[        R$                  S9n['        [(        R*                  " U R,                  U[        R.                  " U5      UR                  R1                  [        R                  " [        R                  5      5      U[        R.                  " U	5      [        R                  " [3        UR                  5      5      [        R                  " [3        UR                  5      5      [        R                  " UR4                  S   5      [        R.                  " U5      [        R.                  " U5      [        R.                  " U5      [7        U R8                  5      [        R.                  " U5      UR                  R1                  [        R                  " [        R                  5      5      [        R:                  " U5      [        R:                  " U5      [        R:                  " U5      5      5        U R=                  UUUUUUU	SS9nUR4                  S   nUU4$ )NFr  r   r   r   r  )r  rw  r  ri   r  r   r`   r  _C_API_MATRIX_TYPE_CSCr  rN   r  rR   r!  r  r  r  rT  r  rP   r   r  r  rO   r  r   r   rS   r  rT   r  )r{   r,  r  r   r*  r  r  r  r  rV  rW  csc_indicesr  rp  rq  rr  ro  r  rD  s                      rC   __inner_predict_sparse_csc*_InnerPredictor.__inner_predict_sparse_csc.  s>    +7szz*B'
R%3CHH%="kk(((>,00#^^FNN;=N#^^FNN;=N ..8:00!>>&..9;L!>>&//:<LHHQbhh/	00_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+[)  (()GH^,_-\*%	
, ..)+%'# / 	
 yy|~rB   c                    UR                   S   nU[        :  a   U R                  UR                  5       UUUS9$ U[        :X  a  U R                  UUUUS9$ U R                  UUUUS9n[        R                  " U[        R                  S9n[        R                  " S5      n[        UR                  5      u  pn[        UR                  5      u  pnUR                   S   [        ::  d   eUR                   R#                  [        R$                  SS9n['        [(        R*                  " U R,                  U	[        R.                  " U
5      UR                  R1                  [        R2                  " [        R4                  5      5      U[        R.                  " U5      [        R                  " [7        UR                  5      5      [        R                  " [7        UR                  5      5      [        R                  " UR                   S   5      [        R.                  " U5      [        R.                  " U5      [        R.                  " U5      [9        U R:                  5      [        R<                  " U5      UR                  R1                  [        R2                  " [        R>                  5      5      5      5        XhR@                  :w  a  [C        S5      eXu4$ )	zPredict for a CSC data.r   r(  r+  rP  r   Fr  rR  )"r   rJ  r8  tocsrr2  )_InnerPredictor__inner_predict_sparse_cscrS  r`   rT  rb   rN   r!  r  rw  r  ri   r  r   r  rP   r   LGBM_BoosterPredictForCSCr  rO   r  r  rR   r   rS   r  rT   r  rU   r   )r{   r,  r  r   r*  rD  rL  rC  rX  r  r  r  r  rV  rW  r  s                   rC   __pred_for_csc_InnerPredictor.__pred_for_csch  s)    yy|*&&IIK /+)	 '   1122 /+)	 3   &&+'%	 ' 
 

3q)*6szz*B'
R%3CHH%="yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+]+$$V^^FOO%DE	
& )))?@@{rB   r-  c                    [         (       a  [        (       d  [        S5      e[        S UR                  R
                   5       5      (       d  [        S5      eU R                  UUUR                  US9n[        R                  " U[        R                  S9n[        R                  " S5      n[        U5      n[        [         R"                  " U R$                  [        R                  " UR&                  5      [        R(                  " UR*                  5      [        R(                  " UR,                  5      [        R.                  " U5      [        R.                  " U5      [        R.                  " U5      [1        U R2                  5      [        R4                  " U5      UR                  R7                  [        R8                  " [        R:                  5      5      5
      5        XWR<                  :w  a  [        S5      eXaR                  4$ )zPredict for a PyArrow table.zACannot predict from Arrow without 'pyarrow' and 'cffi' installed.c              3      #    U  H4  n[        U5      =(       d    [        U5      =(       d    [        U5      v   M6     g 7frG   r   r   r   r   ts     rC   r   ;_InnerPredictor.__pred_for_pyarrow_table.<locals>.<genexpr>  3     r_qZ[#A&U*;A*>UBRSTBUU_q   <>=Arrow table may only have integer or floating point datatypesrP  r   r   rR  )r   r   r/   r   r   typesr   rS  num_rowsr`   rT  rb   rN   r!  r	  rP   r   LGBM_BoosterPredictForArrowr  r   r  r   r   rO   rS   r  rT   r  r  r  rU   )	r{   r-  r  r   r*  rL  rC  rX  c_arrays	            rC   __pred_for_pyarrow_table(_InnerPredictor.__pred_for_pyarrow_table  st    "!nn cdd r_d_k_k_q_qrrr\]] &&+'%	 ' 
 

3q) %U+,,w//0 2 23 2 23\*_-]+t**+]+$$V^^FOO%DE	
 )))?@@nn$$rB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ zpGet the index of the current iteration.

Returns
-------
cur_iter : int
    The index of the current iteration.
r   rN   rO   rP   r   r  r  rT   rU   r{   r	  s     rC   current_iteration!_InnerPredictor.current_iteration  H     ||A00\*	
 !!!rB   )__is_manage_handler  r  r  r  rE   N)r   r  FFFFF),r<   r=   r>   r?   r@   _BoosterHandler   r   r   r   r   boolr   r  r
  r   r   r  r  r  _LGBM_PredictDataTyper   r`   r   r5  r6  r>  rG  rS  r   rf  r;  r9  r7  r  r  r  r8  r  r:  r&   r<  r  rA   r:   rB   rC   r  r    s+   !-&!- %T$Z0!- S#X	!-
 !-F 

 S#X
 
	
 
8 
#t)$
 S#X
 
	
 
<d38n   !" %"'\#\ \ 	\
 \ \ \ \  \ 
rzz5<<00$u||7L7L2MM	N\|  	
  
8'#ZZ'# '# 	'#
 '# 

#'# 
rzz3	'#R(ZZ( ( 	(
 ( 
rzz3	(T<"%,,))5<<+B+BBC<" ::<" *	<"
 +<" (<" <" <" <" 
tELL++,d5<<3J3J.KK	L<"|0\\$$0 0 	0
 0 

#0 
rzz3	0d8\\$$8 8 	8
 8 
uT%,,112D9P9P4QQRTWW	X8t)\\$$) ) 	)
 ) 
rzz3	)V8\\$$8 8 	8
 8 
uT%,,112D9P9P4QQRTWW	X8t;\\$$; ; 	;
 ; 
rzz3	;z+%+% +% 	+%
 +% 
rzz3	+%Z"3 "rB   r  c                   T   \ rS rSrSr          SWS\S\\   S\S    S\\   S\\	   S	\\
   S
\S\S\\\\4      S\S\\   4S jjrSXS jrS\S\R,                  4S jrS\S\SS 4S jrS\\R,                     S\\R,                     S\S\SS 4
S jrS\R,                  SS 4S jrS\\\4   4S jrSYS jrS\\   S\S\\ \\   \R,                  4      SS 4S jr!S\\   S\\   S\S    S\\   S\\	   S	\\
   S\\   S
\S\S\\\\4      S\\   SS 4S  jr"\#S!\\$   S"\%\   S\&\R,                     4S# j5       r'S!\\$   S\S\(\\R,                     \\R,                     4   4S$ jr)S!\\$   S\\   SS 4S% jr*S&\R,                  S'\S\\   SS 4S( jr+S)\\R,                     S'\S\\   SS 4S* jr,S+\-R\                  R^                  S'\S\\   SS 4S, jr0S-\-R\                  Rb                  S'\S\\   SS 4S. jr2S/\3S'\S\\   SS 4S0 jr4\#S\\\4   S1\\\4   S2\5\   S\4S3 j5       r6SYS4 jr7      SZS\S\\   S\\   S\\	   S	\\
   S\\\\4      S\\   SS 4S5 jjr8 S[S\\   S\\\\4      SS 4S6 jjr9S7\ \\:4   SS 4S8 jr;S\\\\4      SS 4S9 jr<SYS: jr=S;\S\\>   SS 4S< jr?S;\S\\R,                     4S= jr@S\SS 4S> jrAS\\   SS 4S? jrBS\S@ jrCS
\SS 4SA jrDS\\   SS 4SB jrES\\   SS 4SC jrFS	\\
   SS 4SD jrGS\\	   SS 4SE jrHS\\   SS 4SF jrIS\\   4SG jrJS\\   4SH jrKS\\   4SI jrLS\\
   4SJ jrMS\\   4SK jrNS\\	   4SL jrOS\\   4SM jrPS\4SN jrQS\4SO jrRSP\ \\4   S\4SQ jrSS]SR\S\5S    4SS jjrTS^ST jrUS7\ \\:4   SS 4SU jrVSVrWg)_r-   i  a7  
Dataset in LightGBM.

LightGBM does not train on raw data.
It discretizes continuous features into histogram bins, tries to combine categorical features,
and automatically handles missing and infinite values.

This class handles that preprocessing, and holds that alternative representation of the input data.
Nri   r  	referencer  r  r  r  r  rL   free_raw_datar  c                    SU l         Xl        X l        X0l        X@l        XPl        Xl        X`l        Xpl        Xl	        [        U	5      U l        Xl        SU l        SU l        SU l        SU l        SU l        SU l        SU l        g)aD  Initialize Dataset.

Parameters
----------
data : str, pathlib.Path, numpy array, pandas DataFrame, H2O DataTable's Frame (deprecated), scipy.sparse, Sequence, list of Sequence, list of numpy array or pyarrow Table
    Data source of Dataset.
    If str or pathlib.Path, it represents the path to a text file (CSV, TSV, or LibSVM) or a LightGBM Dataset binary file.
label : list, numpy 1-D array, pandas Series / one-column DataFrame, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Label of the data.
reference : Dataset or None, optional (default=None)
    If this is Dataset for validation, training data should be used as reference.
weight : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Weight for each instance. Weights should be non-negative.
group : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Group/query data.
    Only used in the learning-to-rank task.
    sum(group) = n_samples.
    For example, if you have a 100-document dataset with ``group = [10, 20, 40, 10, 10, 10]``, that means that you have 6 groups,
    where the first 10 records are in the first group, records 11-30 are in the second group, records 31-70 are in the third group, etc.
init_score : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), pyarrow Array, pyarrow ChunkedArray, pyarrow Table (for multi-class task) or None, optional (default=None)
    Init score for Dataset.
feature_name : list of str, or 'auto', optional (default="auto")
    Feature names.
    If 'auto' and data is pandas DataFrame or pyarrow Table, data columns names are used.
categorical_feature : list of str or int, or 'auto', optional (default="auto")
    Categorical features.
    If list of int, interpreted as indices.
    If list of str, interpreted as feature names (need to specify ``feature_name`` as well).
    If 'auto' and data is pandas DataFrame, pandas unordered categorical columns are used.
    All values in categorical features will be cast to int32 and thus should be less than int32 max value (2147483647).
    Large values could be memory consuming. Consider using consecutive integers starting from zero.
    All negative values in categorical features will be treated as missing values.
    The output cannot be monotonically constrained with respect to a categorical feature.
    Floating point numbers in categorical features will be rounded towards 0.
params : dict or None, optional (default=None)
    Other parameters for Dataset.
free_raw_data : bool, optional (default=True)
    If True, raw data is freed after constructing inner Dataset.
position : numpy 1-D array, pandas Series or None, optional (default=None)
    Position of items used in unbiased learning-to-rank task.
NTr   )r  ri   r  r  r  r  r  r  r  r  r   rL   r  used_indices_need_slice
_predictorr  _params_back_upversion
_start_row)r{   ri   r  r  r  r  r  r  r  rL   r  r  s               rC   r   Dataset.__init__  s    n 26	
"
 $<HJ] v&*15598<9=rB   rE   c                 F     U R                  5         g ! [         a     g f = frG   )_free_handler  r   s    rC   r  Dataset.__del__:  s%    	 		s    
  rK   c           
         [        U R                  5       5      n[        X5      n[        R                  " U[        R
                  S9n[        U5      u  n  n[        R                  " S5      n[        [        R                  " [        R                  " U5      [        U5      U[        R                  " U5      5      5        X7R                  :X  d   eU$ )a  Get an array of randomly chosen indices from this ``Dataset``.

Indices are sampled without replacement.

Parameters
----------
total_nrow : int
    Total number of rows to sample from.
    If this value is greater than the value of parameter ``bin_construct_sample_cnt``, only ``bin_construct_sample_cnt`` indices will be used.
    If Dataset has multiple input data, this should be the sum of rows of every file.

Returns
-------
indices : numpy array
    Indices for sampled data.
r   r   )rF  
get_paramsrW   r`   rT  r  r  rN   rR   rP   r   LGBM_SampleIndicesrS   rT   rU   )r{   rK   	param_strrV   r  r  rW  actual_sample_cnts           rC   _create_sample_indicesDataset._create_sample_indices@  s    " 't'89	&z=
((:RXX6%g.!Q"NN1-##z*y!./		
 44444rB   ref_datasetc           	          [         R                  " 5       U l        [        [        R
                  " U[         R                  " U5      [         R                  " U R                  5      5      5        U $ )a  Create dataset from a reference dataset.

Parameters
----------
total_nrow : int
    Number of rows expected to add to dataset.
ref_dataset : object
    Handle of reference dataset to extract metadata from.

Returns
-------
self : Dataset
    Constructed Dataset object.
)rN   r  r  rP   r   LGBM_DatasetCreateByReferencer!  rT   )r{   rK   r  s      rC   _init_from_ref_datasetDataset._init_from_ref_datasetb  sN    & (..z*T\\*	
 rB   sample_datasample_indicesrV   c                    [        U5      n[        U5      U:X  d   S5       e[        U5       H  nX   R                  [        R                  :w  a  [        SU SX   R                   S35      eX&   R                  [        R                  :w  d  Mc  [        SU SX&   R                   S35      e   [        R                  " [        R                  5      U-  " 5       n[        R                  " [        R                  5      U-  " 5       n[        U5       H'  n[        X   5      S   Xv'   [        X&   5      S   X'   M)     [        R                  " U V	s/ s H  n	[        U	5      PM     sn	[        R                  S9n
[        U
5      u  n  n[        R                  " 5       U l        [!        U R#                  5       5      n[%        [&        R(                  " [        R*                  " U[        R                  " [        R                  " [        R                  5      5      5      [        R*                  " U[        R                  " [        R                  " [        R                  5      5      5      [        R                  " U5      U[        R                  " U5      [        R                  " U5      [        R,                  " U5      [/        U5      [        R0                  " U R                  5      5	      5        U $ s  sn	f )	a~  Create Dataset from sampled data structures.

Parameters
----------
sample_data : list of numpy array
    Sample data for each column.
sample_indices : list of numpy array
    Sample data row index for each column.
sample_cnt : int
    Number of samples.
total_nrow : int
    Total number of rows for all input files.

Returns
-------
self : Dataset
    Constructed Dataset object.
z&#sample data column != #column indiceszsample_data[z] type z is not doublezsample_indices[z is not int32r   r   )r   ranger]   r`   doubler   r  rN   r  r  rR   r  r  r   r  r  rF  r  rP   r   #LGBM_DatasetCreateFromSampledColumnr   r!  rS   rT   )r{   r  r  rV   rK   ncolr  sample_col_ptrindices_col_ptrdnum_per_colnum_per_col_ptrrW  
params_strs                 rC   _init_from_sampleDataset._init_from_sample  s%   2 >";4'Q)QQ'tA~##ryy0 <s'+.:N:N9O~!^__ &&"((2 ?1#W^=N=T=T<UUb!cdd	  06~~foo/NQU/U.X /5nnV^^.Lt.S-VtA .{~ >q AN!-n.?!@!CO  hh?1A?rxxP ,[ 9A('(9:
44NFNN6>>&//;Z,[\OV^^FNN6>><Z-[\t$z*z*z*z"T\\*
	
 %  @s   K3c                    UR                   u  p#UR                  UR                  5      n[        U5      u  pEn[	        [
        R                  " U R                  UU[        R                  " U5      [        R                  " U5      [        R                  " U R                  5      5      5        U =R                  U-  sl
        U $ )zAdd rows to Dataset.

Parameters
----------
data : numpy 1-D array
    New data to add to the Dataset.

Returns
-------
self : Dataset
    Dataset object.
)r   r@  r?  r  rP   r   LGBM_DatasetPushRowsr  rN   rR   r  )r{   ri   rD  r  data_ptrrt  rW  s          rC   
_push_rowsDataset._push_rows  s     ZZ
||DII&!/!5Q%%t$t$t/		
 	4rB   c                     U R                   b_  [        R                  SSSSSSSSS	S
SSSSSSSSSSS5      nU R                   R                  5        VVs0 s H  u  p#X!;   d  M  X#_M     snn$ 0 $ s  snnf )zwGet the used parameters in the Dataset.

Returns
-------
params : dict
    The used parameters in this Dataset object.
bin_construct_sample_cntr  data_random_seedenable_bundlefeature_pre_filterforcedbins_filenamegroup_columnheaderignore_columnis_enable_sparselabel_columnlinear_treemax_binmax_bin_by_featuremin_data_in_binpre_partitionprecise_float_parser	two_rounduse_missingweight_columnzero_as_missing)rL   r^  rz  r?  )r{   dataset_paramsrc  rd  s       rC   r  Dataset.get_params  s     ;;"+//*%"$%"$!&!+N. &*[[%6%6%8P%8TQA<ODAD%8PPI Qs   A/#A/c                     U R                   b0  [        [        R                  " U R                   5      5        S U l         SU l        U R
                  b  S U l        U $ )NT)r  rP   r   LGBM_DatasetFreer  r  ri   r   s    rC   r  Dataset._free_handle  sJ    <<#t,,T\\:;DL(DIrB   	predictorr  c                 n  ^  Sn[        U[        [        45      (       a5  T R                  b(  [	        U 4S j[
        R                  S5       5       5      nT R                  5       nUGb~  UR                  USUS9nUR                  5       nUb  T R                  (       a   e[        U[        [        45      (       a  [        R                  " XQR                  -  [        R                  S9nU[        U5      :X  d   e[!        [        U5      5       HH  n[!        UR                  5       H,  n	UX8   UR                  -  U	-      XxUR                  -  U	-   '   M.     MJ     UnUR                  S:  ay  [        R                  " UR"                  [        R                  S9n
[!        U5       H;  n[!        UR                  5       H  n	XhUR                  -  U	-      XU-  U-   '   M!     M=     U
nO>T R$                  b/  [        R&                  " T R$                  S[        R                  S	9nOT $ T R)                  U5        T $ )
NFc              3   \   >#    U  H!  nTR                   R                  US 5      v   M#     g7f)FN)rL   rz  )r   aliasr{   s     rC   r   7Dataset._set_init_score_by_predictor.<locals>.<genexpr>  s%     !jMiE$++//%"?"?Mis   ),r  T)ri   r!  r$  r   r   g        )
fill_valuer]   )r   r   r   rL   anyr^  rz  num_datarG  rg   r  r`   rT  r  rb   r   r  r?  r  	full_likeset_init_score)r{   r  ri   r  r$  r  r  sub_init_scorer  jnew_init_scores   `          rC   _set_init_score_by_predictor$Dataset._set_init_score_by_predictor  s     dS$K((T[[-D!!j^M_M_`hMi!jjO==? CLCTCT / DU DJ
 $))+J'++++dS$K00%'XXh9L9L.LTVT^T^%_N#s<'8888"3|#45!&y':':!;AJT ,)2E2E E IKNy/B/B+BQ+FG "< 6
 "0J""Q&!#*//!LxA"9#6#67;E)J]J]F]`aFa;b8|a'78 8 ) ,
__(doo#RZZXJKJ'rB   c           
         Uc	  S U l         U $ Ub  UR                  U l        UR                  n	[        U[        5      (       a  [        UUU	U R                  S9u  pol        O"[        U5      (       a  US:X  a  UR                  nU
c  0 OU
n
[        R                  " U R                  R                  5      R                  R                  5       nU
R                  5        H  nX;   d  M
  [        U SU S35        M     [        U	[        5      (       GaJ  [!        5       n0 n[        U[        5      (       a!  [#        U5       VVs0 s H	  u  nnUU_M     nnnU	 H  n[        U[$        5      (       a  UU;   a  UR'                  UU   5        M4  [        U[(        5      (       a  UR'                  U5        M\  [+        S[-        U5      R.                   SU S35      e   U(       a|  [0        R3                  S5       HU  nUU
;   d  M  [        U
U   [        5      (       a  [!        U
U   5      U:X  d  [        U S	35        U
R5                  US 5        MW     [7        U5      U
S
'   [9        U
5      nXl        S n[        U[<        5      (       a  UR?                  5       R                   nOUb  [+        S5      e[        U[$        [@        45      (       aw  [B        RD                  " 5       U l         [G        [H        RJ                  " [M        [%        U5      5      [M        U5      U[B        RN                  " U R                   5      5      5        GO[        U[P        RR                  RT                  5      (       a  U RW                  UUU5        GO[        U[P        RR                  RX                  5      (       a  U R[                  UUU5        GOl[        U[\        R^                  5      (       a  U Ra                  UUU5        GO8[        U5      (       a  U Rc                  UUU5        GO[        U[        5      (       aa  [e        U5      S:  aR  [g        U5      (       a  U Ri                  UUU5        O[k        U5      (       a  U Rm                  UU5        O[+        S5      e[        U[n        5      (       a  U Rm                  U/U5        Ot[        U[p        5      (       a,  [s        5         U Ra                  URu                  5       UU5        O3 [P        RR                  RU                  U5      nU RW                  UUU5        Ub  U Ry                  U5        U R{                  5       c  [}        S5      eUb  U R                  U5        Ub  U R                  U5        Ub  U R                  U5        [        U[        5      (       a,  U R                  c  Ub  [        S5        U R                  XqS S9  O9Ub  U R                  U5        O$Ub!  [+        S[-        U5      R.                   35      eU R                  U5      $ s  snnf ! [v         a'  n[+        S[-        U5      R.                   35      UeS nAff = f)Nr'  r  zD keyword has been found in `params` and will be ignored.
Please use z< argument of the Dataset constructor to pass this parameter.r   z) or unknown name(z) in categorical_featurer  z in param dict is overridden.categorical_columnz4Reference dataset should be None or dataset instancer   z,Data list can only be of ndarray or SequencezCannot initialize Dataset from zLabel should not be NonezBThe init_score will be overridden by the prediction of init_model.r  ri   r  zWrong predictor type )Gr  r  r  r   r(   r  r   column_namesinspect	signature	__class__
_lazy_init
parametersr  r   r   rA  r  r   addr   r   r   r<   r^  rz  r  sortedrF  rL   r-   	constructr   rN   r  rP   r   LGBM_DatasetCreateFromFilerS   rT   r5  r6  r7  _Dataset__init_from_csrr9  _Dataset__init_from_cscr`   r   _Dataset__init_from_np2d!_Dataset__init_from_pyarrow_tabler   r   _Dataset__init_from_list_np2dr   _Dataset__init_from_seqsr1   r!   r\  r  r=  	set_label	get_labelr   
set_weight	set_groupset_positionr  r  r  r  set_feature_name)r{   ri   r  r  r  r  r  r  r  r  rL   r  
args_namesrE  categorical_indicesfeature_dictr  r   	cat_aliasr  r  r)  rE  s                          rC   r%  Dataset._lazy_init6  s[    <DLK &/&B&BD#"+"?"?dL))O`)$7#'#:#:	PLD 35L t$$)?,,L ~6&&t~~'@'@ALLQQS
;;=C e ""%&bd ! )400"%%L,--7@7NO7NGAta7NO+dC((T\-A'++L,>?c**'++D1#k$t*2E2E1FFXY]X^^v$wxx , #!/!3!34I!JI F* *6)+<d C CFS\L]H^buHu(I;6S)TU

9d3 "K 066I/J+,'/
i))#--/77K"RSSdS$K((!??,DL//3t9%:&LL.	 ell5566  z;?ell5566  z;?bjj))!!$
K@t$$**4[Id##D	A'--**4[I&t,,%%dK8 NOOh''!!4&+6l++/1!!$--/:{Kbll--d3$$S*kB NN5!>>#788OOF#NN5!h'i11&:+Aab--	[_-`#
+"3DO4L4L3MNOO$$\22c  Px ! b"A$t*BUBUAV WX^aabs    X42X# #
Y-"YYseqsr  c              #     #    SnSnX   nU Hz  nXR:  d   S5       eXR[        U5      -   :  a*  U[        U5      -  nUS-  nX   nXR[        U5      -   :  a  M*  XR-
  nXF   nUR                  S   (       a  UOUR                  5       v   M|     g 7f)Nr   z+sample indices are expected to be monotonicr   OWNDATA)r   rc   r   )r<  r  r  seq_idseqrow_id	id_in_seqrows           rC   _yield_row_from_seqlistDataset._yield_row_from_seqlist  s     lF#R%RR#SX--#c("!l SX-- I.C9-#388:= s   AB5Bc                    U R                  U5      n[        R                  " [        U R	                  X5      5      5      nUR
                  n/ n/ n[        R                  " [        U5      [        R                  S9nU Ha  n[        R                  " U5      [        :  [        R                  " U5      -  n	X   n
Xy   nUR                  U
5        UR                  U5        Mc     XV4$ )zSample data from seqs.

Mimics behavior in c_api.cpp:LGBM_DatasetCreateFromMats()

Returns
-------
    sampled_rows, sampled_row_indices
r   )r  r`   r   r   rD  Tr`  r   r  absrH   isnanr   )r{   r<  rK   r  sampledfilteredfiltered_idxsampled_row_ranger  col_predicatefiltered_colfiltered_row_idxs               rC   __sampleDataset.__sample  s     --j9 ((4 < <T KLM))IIc'l"((CCVVC[>9RXXc]JM-L0?OOL) 01  %%rB   c                    [        S U 5       5      nUb  U R                  X25        OI[        U R                  5       5      n[	        X45      nU R                  X5      u  pgU R                  XgXS5        U Hf  n[        U5      n	[        USS5      =(       d    [        R                  n
[        SX5       H$  n[        X-   U	5      nU R                  XU 5        M&     Mh     U $ )z
Initialize data from list of Sequence objects.

Sequence: Generic Data Access Object
    Supports random access and access by batch if properly defined by user

Data scheme uniformity are trusted, not checked
c              3   8   #    U  H  n[        U5      v   M     g 7frG   r)  )r   r@  s     rC   r   +Dataset.__init_from_seqs.<locals>.<genexpr>  s     2TcSTr7  Nr  r   )rd  r  rF  r  rW   _Dataset__sampler  r   r   r1   r  r  minr  )r{   r<  r  rK   r  rV   r  col_indicesr@  rD  r  r]  ends                rC   __init_from_seqsDataset.__init_from_seqs  s     2T22
 "''
@*4??+<=I*:AJ'+}}T'F$K"";ZTCs8D lD9PX=P=PJq$3%,d3#/ 4  rB   rX   r  c                 &   [        UR                  5      S:w  a  [        S5      e[        R                  " 5       U l        [        U5      u  pE[        U5      u  pgn[        [        R                  " U[        R                  " U5      [        R                  " UR                  S   5      [        R                  " UR                  S   5      [        R                  " U5      [        U5      U[        R                  " U R
                  5      5      5        U $ )z(Initialize data from a 2-D numpy matrix.r   )Input numpy.ndarray must be 2 dimensionalr   r   )r   r   r   rN   r  r  rj   r  rP   r   LGBM_DatasetCreateFromMatrO   rR   rS   rT   )	r{   rX   r  r  ri   rh   r  rV  rW  s	            rC   __init_from_np2dDataset.__init_from_np2d	  s     syy>QHII($S)%3D%9"**]+syy|,syy|,V$z"T\\*		
 rB   matsc                    US   R                   S   n[        R                  " [        U5      4[        R                  5      nUS   R
                  [        R                  :X  a6  [        R                  " [        R                  5      [        U5      -  " 5       nO5[        R                  " [        R                  5      [        U5      -  " 5       n[        R                  [        U5      -  " 5       n/ nSn	[        U5       H  u  p[        UR                   5      S:w  a  [        S5      eUR                   S   U:w  a  [        S5      eUR                   S   XZ'   [        U5      u  p[        U5      u  pnU	S:w  a  X:w  a  [        S5      eXU
'   XU
'   Un	UR!                  U5        M     [        R"                  " 5       U l        ['        [(        R*                  " [        R,                  " [        U5      5      [        R.                  " U[        R                  " [        R                  " [        R                  5      5      5      [        R                  " U	5      UR                  R1                  [        R                  " [        R,                  5      5      [        R,                  " U5      U[3        U5      U[        R4                  " U R$                  5      5	      5        U $ )z2Initialize data from a list of 2-D numpy matrices.r   r   r  r   r]  z-Input arrays must have same number of columnsz Input chunks must have same type)r   r`   rT  r   r  r]   rb   rN   r  r  r  rO   r  r   rj   r  r   r  r  rP   r   LGBM_DatasetCreateFromMatsrR   r   r  rS   rT   )r{   ra  r  r  r  rD  r  layoutsholdersrV  r  rX   rh   chunk_ptr_datachunk_type_ptr_dataholders                   rC   __init_from_list_np2dDataset.__init_from_list_np2d	  s     Aw}}QxxTbhh/7==BJJ&v7#d)CFHv~~6TBEH<<#d)+.oFA399~" !LMMyy|t# !PQQiilDG',KC:H:M7N"':'K !CDD(QKAJ/MNN6"# && (++s4y)HfnnV^^FOO5T&UV]+##FNN6>>$BCt$z"T\\*
	
 rB   r)  c                 &   [        UR                  5      [        UR                  5      :w  a7  [        S[        UR                  5       S[        UR                  5       35      e[        R
                  " 5       U l        [        UR                  5      u  pEn[        UR                  5      u  pxn	UR                  S   [        ::  d   eUR                  R                  [        R                  SS9n
[        [         R"                  " U[        R$                  " U5      U
R                  R'                  [        R(                  " [        R*                  5      5      U[        R$                  " U5      [        R,                  " [        UR                  5      5      [        R,                  " [        UR                  5      5      [        R,                  " UR                  S   5      [/        U5      U[        R0                  " U R                  5      5      5        U $ )z"Initialize data from a CSR matrix.Length mismatch:  vs r   Fr  )r   r  ri   r   rN   r  r  r  rw  r  r   rJ  r   r`   r  rP   r   LGBM_DatasetCreateFromCSRrO   r  r  rR   r!  rS   rT   )r{   r)  r  r  r  r  r  r  rV  rW  r  s              rC   __init_from_csrDataset.__init_from_csrR	  b    s{{s388},0S[[1A0B$s388}oVWW(*6szz*B'
R%3CHH%="yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,z"T\\*	
 rB   r,  c                 &   [        UR                  5      [        UR                  5      :w  a7  [        S[        UR                  5       S[        UR                  5       35      e[        R
                  " 5       U l        [        UR                  5      u  pEn[        UR                  5      u  pxn	UR                  S   [        ::  d   eUR                  R                  [        R                  SS9n
[        [         R"                  " U[        R$                  " U5      U
R                  R'                  [        R(                  " [        R*                  5      5      U[        R$                  " U5      [        R,                  " [        UR                  5      5      [        R,                  " [        UR                  5      5      [        R,                  " UR                  S   5      [/        U5      U[        R0                  " U R                  5      5      5        U $ )z"Initialize data from a CSC matrix.rl  rm  r   Fr  )r   r  ri   r   rN   r  r  r  rw  r  r   rJ  r   r`   r  rP   r   LGBM_DatasetCreateFromCSCrO   r  r  rR   r!  rS   rT   )r{   r,  r  r  r  r  r  r  rV  rW  r  s              rC   __init_from_cscDataset.__init_from_csct	  rq  rB   r-  c                 H   [         (       a  [        (       d  [        S5      e[        S UR                  R
                   5       5      (       d  [        S5      e[        U5      n[        R                  " 5       U l
        [        [        R                  " [        R                  " UR                  5      [        R                  " UR                   5      [        R                  " UR"                  5      [%        U5      U[        R&                  " U R                  5      5      5        U $ )z%Initialize data from a PyArrow table.zFCannot init Dataset from Arrow without 'pyarrow' and 'cffi' installed.c              3      #    U  H4  n[        U5      =(       d    [        U5      =(       d    [        U5      v   M6     g 7frG   r  r  s     rC   r   4Dataset.__init_from_pyarrow_table.<locals>.<genexpr>	  r  r  r  )r   r   r/   r   r   r  r   r	  rN   r  r  rP   r   LGBM_DatasetCreateFromArrowr!  r   r   r   rS   rT   )r{   r-  r  r  r  s        rC   __init_from_pyarrow_table!Dataset.__init_from_pyarrow_table	  s     "!nn hii r_d_k_k_q_qrrr\]] %U+(,,w//0 2 23 2 23z"T\\*		
 rB   other_paramsignore_keysc                     UR                  5        H  u  p4X2;  d  M  X0;  d
  X   U:w  d  M    g   U R                  5        H  u  p4X2;  d  M  X1;  d
  XAU   :w  d  M    g   g)a  Compare two dictionaries with params ignoring some keys.

It is only for the warning purpose.

Parameters
----------
params : dict
    One dictionary with parameters to compare.
other_params : dict
    Another dictionary with parameters to compare.
ignore_keys : set
    Keys that should be ignored during comparing two dictionaries.

Returns
-------
compare_result : bool
  Returns whether two dictionaries with params are equal.
FTrb  )rL   r|  r}  rc  rd  s        rC   _compare_params_for_warning#Dataset._compare_params_for_warning	  s`    0 !&&(DA#?fi1n  ) LLNDA#(Aa,@  # rB   c                 `	   U R                   Gc  U R                  Gb  U R                  R                  5       nU R                  5       nX!:w  aE  U R                  UU[        R                  S5      S9(       d  [        S5        U R                  U5        U R                  c  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  SU R$                  S9  GOd['        U R                  [(        R*                  SS9nUR,                  R.                  (       d   eU R                  R                  b  [(        R0                  " U R                  R                  5      R3                  [(        R*                  S	S
9n[(        R4                  " [(        R6                  " [9        [;        U5      5      US9U R                     SS9u  oPl        [<        R>                  " 5       U l         [A        U R$                  5      n[C        [D        RF                  " U R                  RI                  5       R                   UR<                  RK                  [<        RL                  " [<        RN                  5      5      [<        RN                  " URP                  S   5      [S        U5      [<        RT                  " U R                   5      5      5        U RV                  (       d  U RY                  5         U R                  b  U R[                  U R                  5        U R                  b  U R]                  U R                  5        U R_                  5       c  [a        S5      e[c        U R                   [d        5      (       aX  U R                   U R                  R                   La5  U RY                  5         U Rg                  U R                   U R                  US9  O}U R                  U R                  U R                  SU R                  U R                  U R                  U R                   U R"                  U Rh                  U R$                  U R                  S9  U RV                  (       a  SU l
        U Rk                  5       U l        U $ )zKLazy init.

Returns
-------
self : Dataset
    Constructed Dataset object.
Nr  )rL   r|  r}  z1Overriding the parameters from Reference Dataset.r  )ri   r  r  r  r  r  r  r  r  r  rL   r  r]   r   Fr  )repeatsT)return_countsr   zLabel should not be None.r   )ri   r  r  r  r  r  r  r  r  rL   r  )6r  r  r  r  r^  rz  r   _update_paramsr  r%  ri   r  r  r  r  r  r  r  rL   r   r`   r  rc   r  r   r   uniquerepeatr  r   rN   r  rF  rP   r   LGBM_DatasetGetSubsetr)  r  r  rR   r   rS   rT   r  get_datar4  r5  r2  r   r   r  r  r  get_feature_name)r{   reference_paramsrL   r  
group_inforW  r  s          rC   r)  Dataset.construct	  se    <<~~)#'>>#<#<#> *-;;%%5$2$6$67L$M < 
 %%XY''(89$$,OO!YY"jj"&..#{{"jj!%#'??"&//%)%6%6,2#{{ $  $5T5F5Fbhh]k#lL'--::::~~++7%'XXdnn.B.B%C%J%J288Z_%J%`
(*		IIeC
O&<jQRVRcRcdtx): $*??#4DL!3DKK!@J22 NN446>>(//77v~~8VW"NN<+=+=a+@A":."LL6  --zz-tzz2}}0))$--8~~'/()DEE"4??ODD OO4>>3L3LL99&*ooDIIT` : 
 **";;**#"oo!%!2!2(,(@(@;;!]]    !! 	 $ 5 5 7DrB   c                     [        UUU UUUUUU R                  S9	nU R                  Ul        U R                  Ul        U$ )a  Create validation data align with current Dataset.

Parameters
----------
data : str, pathlib.Path, numpy array, pandas DataFrame, H2O DataTable's Frame (deprecated), scipy.sparse, Sequence, list of Sequence or list of numpy array
    Data source of Dataset.
    If str or pathlib.Path, it represents the path to a text file (CSV, TSV, or LibSVM) or a LightGBM Dataset binary file.
label : list, numpy 1-D array, pandas Series / one-column DataFrame, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Label of the data.
weight : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Weight for each instance. Weights should be non-negative.
group : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Group/query data.
    Only used in the learning-to-rank task.
    sum(group) = n_samples.
    For example, if you have a 100-document dataset with ``group = [10, 20, 40, 10, 10, 10]``, that means that you have 6 groups,
    where the first 10 records are in the first group, records 11-30 are in the second group, records 31-70 are in the third group, etc.
init_score : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), pyarrow Array, pyarrow ChunkedArray, pyarrow Table (for multi-class task) or None, optional (default=None)
    Init score for Dataset.
params : dict or None, optional (default=None)
    Other parameters for validation Dataset.
position : numpy 1-D array, pandas Series or None, optional (default=None)
    Position of items used in unbiased learning-to-rank task.

Returns
-------
valid : Dataset
    Validation Dataset with reference to self.
)r  r  r  r  r  r  rL   r  )r-   r  r  r  )	r{   ri   r  r  r  r  rL   r  r   s	            rC   create_validDataset.create_valid0
  sP    N !,,

 !%!8!8
rB   c           	          Uc  U R                   n[        SU U R                  U R                  UU R                  S9nU R
                  Ul        U R                  Ul        [        U5      Ul        U$ )a(  Get subset of current Dataset.

Parameters
----------
used_indices : list of int
    Indices used to create the subset.
params : dict or None, optional (default=None)
    These parameters will be passed to Dataset constructor.

Returns
-------
subset : Dataset
    Subset of the current Dataset.
N)r  r  r  rL   r  )	rL   r-   r  r  r  r  r  r(  r  )r{   r  rL   r   s       rC   subsetDataset.subsetf
  sm    & >[[F** $ 8 8,,
 !%!8!8!,/
rB   filenamec           
          [        [        R                  " U R                  5       R                  [        [        U5      5      5      5        U $ )a.  Save Dataset to a binary file.

.. note::

    Please note that `init_score` is not saved in binary file.
    If you need it, please set it again after loading Dataset.

Parameters
----------
filename : str or pathlib.Path
    Name of the output file.

Returns
-------
self : Dataset
    Returns self.
)rP   r   LGBM_DatasetSaveBinaryr)  r  rS   r   r{   r  s     rC   save_binaryDataset.save_binary
  s=    $ 	'' ((s8}%	
 rB   c                   ^ ^ T(       d  T $ [        T5      mSUU 4S jjnT R                  c	  U" 5         T $ Tb  [        R                  " [	        [        T R                  5      5      [	        [        T5      5      5      nUS:w  aS  T R                  b  U" 5         T R                  5         T $ [        [        R                  " 5       R                  S5      5      eT $ )Nc                     > TR                   (       d  T Tl         g [        TR                   5      Tl        TR                   R                  T 5        g rG   )rL   r   r  rw  )rL   r{   s   rC   rw  &Dataset._update_params.<locals>.update
  s4    ;;$'/'<$""6*rB   r   r   r  )r   r  r   LGBM_DatasetUpdateParamCheckingrS   rF  rL   ri   r  r/   r   r   )r{   rL   rw  r   s   ``  rC   r  Dataset._update_params
  s    K&!	+ 	+ <<H  66)$++67)&12C ax99(H%%'  ((>(>(@(G(G(PQQrB   c                 b    U R                   c!  [        U R                  5      U l        S U l        U $ rG   )r  r   r  rL   r   s    rC   _reverse_update_paramsDataset._reverse_update_params
  s+    <<"4#7#78DK#'D rB   
field_namec                    U R                   c  [        SU S35      eUcg  [        [        R                  " U R                   [        U5      S[        R                  " S5      [        R                  " [        U   5      5      5        U $ [        U5      (       d  [        U5      (       Ga  [        U5      (       aQ  US:w  a  [        SU S35      e[        UR                   VVs/ s H  nUR                    H  nUPM     M     snn5      n[        U5      n[        [        R                   " U R                   [        U5      [        R"                  " UR$                  5      [        R&                  " UR(                  5      [        R&                  " UR*                  5      5      5        U =R,                  S-  sl        U $ US:X  a`  [.        R0                  n[3        U5      (       a  [5        X&US	9nOf[7        U5      (       a  [9        X&US	9nUR;                  S
S9nO<[=        S5      eUS;   a  [.        R>                  nO[.        R@                  n[5        X&US	9nURB                  [.        R@                  :X  d  URB                  [.        R0                  :X  a  [E        U5      u  pxn	OFURB                  [.        R>                  :X  a  [G        U5      u  pxn	O[=        SURB                   S35      eU[        U   :w  a  [=        S5      e[        [        R                  " U R                   [        U5      U[        R                  " [I        U5      5      [        R                  " U5      5      5        U =R,                  S-  sl        U $ s  snnf )ai  Set property into the Dataset.

Parameters
----------
field_name : str
    The field name of the information.
data : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), pyarrow Array, pyarrow ChunkedArray or None
    The data to be set.

Returns
-------
self : Dataset
    Dataset with set property.
NzCannot set z before construct datasetr   r  z,pyarrow tables are not supported for field ''r   r  r[   r_   zinit_score must be list, numpy 1-D array or pandas Series.
In multiclass classification init_score can also be a list of lists, numpy 2-D array or pandas DataFrame.>   r  r  z-Expected np.float32/64 or np.int32, met type(r  zInput type error for set_field)%r  	ExceptionrP   r   LGBM_DatasetSetFieldrS   rN   rO   _FIELD_TYPE_MAPPERr   r   r   r#   r  r   r	  LGBM_DatasetSetFieldFromArrowr!  r   r  r   r   r  r`   rb   r   r   r   r  rg   r   r  ra   r]   r  r  r   )
r{   r  ri   r   ri  r  r]   r  r  rW  s
             rC   	set_fieldDataset.set_field
  s   & <<k*5NOPP<))LL:&LLOLL!3J!?@ K T""&7&=&= !&&-$'ST^S__`%abb' &*\\%1E%*\\E %1 %1 ).G22LL:&NN7#3#34OOG$6$67OOG$6$67 LLALK %JJE &&(L"4(((Lzzz,@ 
 22

$TZHD ::#tzzRZZ'?%3D%9"HZZ288#%1$%7"HKDJJ<WXYZZ*:66<==%%z"SY'Y'	
 	ws   ! M9
c                     U R                   c  [        SU S35      e[        R                  " S5      n[        R                  " S5      n[        R                  " [        R
                  5      " 5       n[        [        R                  " U R                   [        U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      5      5        UR                  [        U   :w  a  [        S5      eUR                  S:X  a  gUR                  [        :X  aL  [        [        R                   " U[        R                  " [        R"                  5      5      UR                  S9nOUR                  [$        :X  aL  ['        [        R                   " U[        R                  " [        R(                  5      5      UR                  S9nOkUR                  [*        :X  aL  [-        [        R                   " U[        R                  " [        R.                  5      5      UR                  S9nO[        S5      eUS:X  a6  U R1                  5       nUR2                  U-  nUS	:  a  UR5                  Xg4S
S9nU$ )a  Get property from the Dataset.

Can only be run on a constructed Dataset.

Unlike ``get_group()``, ``get_init_score()``, ``get_label()``, ``get_position()``, and ``get_weight()``,
this method ignores any raw data passed into ``lgb.Dataset()`` on the Python side, and will only read
data from the constructed C++ ``Dataset`` object.

Parameters
----------
field_name : str
    The field name of the information.

Returns
-------
info : numpy array or None
    A numpy array with information from the Dataset.
NzCannot get z before construct Datasetr   zReturn type error for get_fieldr  zUnknown typer  r   r[   r_   )r  r  rN   rO   r  r  rP   r   LGBM_DatasetGetFieldrS   rT   rU   r  r   r  r  r   rR   r  r  r  r  r  r  r  r?  r@  )r{   r  rn  out_typer   arrr  num_classess           rC   	get_fieldDataset.get_field+  s   & <<k*5NOPPll1o<<?nnV__-/%%z"[)S!X&	
 >>/
;;=>>!>>//([[fnnV^^&DE"((C ^^33*[[fnnV^^&DE"((C ^^33*[[fnnV__&EF"((C
 N++%}}H((h.KQkk8"9kE
rB   c                 &   U R                   U:X  a  U $ U R                  bh  U R                   c  Xl         U R                  5       $ US:X  a  U $ U R                   S:w  a  [        S[	        U5       35        Xl         U R                  5       $ [        S5      e)zSet categorical features.

Parameters
----------
categorical_feature : list of str or int, or 'auto'
    Names or indices of categorical features.

Returns
-------
self : Dataset
    Dataset with set categorical features.
r  zIcategorical_feature in Dataset is overridden.
New categorical_feature is zrCannot set categorical feature after freed raw data, set free_raw_data=False when construct Dataset to avoid this.)r  ri   r  r   r   r/   )r{   r  s     rC   set_categorical_featureDataset.set_categorical_featureh  s      ##'::K99 ''/+>(((**$.++v5 66:;N6O5PR ,?(((**P rB   c                    Uc  U R                   c  U $ [        U[        5      (       a\  [        U R                   [        5      (       a=  XR                   :X  a.  UR                  5       U R                   R                  5       :X  a  U $ U R                  c  Xl         U $ U R
                  b-  Xl         U R                  U R                   U R
                  SS9  U $ U R                  be  U R                  bX  U R                  R
                  bA  Xl         U R                  U R                   U R                  R
                  U R                  S9  U $ [        S5      e)zSet predictor for continued training.

It is not recommended for user to call this function.
Please use init_model argument in engine.train() or engine.cv() instead.
Nr   zhCannot set predictor after freed raw data, set free_raw_data=False when construct Dataset to avoid this.)
r  r   r  r  r  ri   r  r  r  r/   )r{   r  s     rC   _set_predictorDataset._set_predictor  s,    !8K	?33
4??Tc8d8d__,++-1R1R1TT<<'O( ' YY"'O--//YY! . "  *t~~/IdnnNaNaNm'O--//^^((!.. .  	  P rB   c                 `   U R                  UR                  5      R                  UR                  5      R	                  UR
                  5        U R                  5       R                  UR                  5       5      (       a  U $ U R                  b  Xl	        U R                  5       $ [        S5      e)zSet reference Dataset.

Parameters
----------
reference : Dataset
    Reference that is used as a template to construct the current Dataset.

Returns
-------
self : Dataset
    Dataset with set reference.
zhCannot set reference after freed raw data, set free_raw_data=False when construct Dataset to avoid this.)r  r  r6  r  r  r  get_ref_chainintersectionri   r  r  r/   )r{   r  s     rC   set_referenceDataset.set_reference  s     	$$Y%B%BCTT""	

.--
.,,Y-D-D-FGGK99 &N$$&&P rB   c                    US:w  a  Xl         U R                  b  Ub  US:w  a  [        U5      U R                  5       :w  a)  [	        S[        U5       SU R                  5        S35      eU Vs/ s H  n[        U5      PM     nn[        [        R                  " U R                  [        [        R                  U5      [        R                  " [        U5      5      5      5        U $ s  snf )zSet feature name.

Parameters
----------
feature_name : list of str
    Feature names.

Returns
-------
self : Dataset
    Dataset with set feature name.
r  zLength of feature_name(z) and num_feature() don't match)r  r  r   num_featurer   rS   rP   r   LGBM_DatasetSetFeatureNamesr*  rN   r%  rO   )r{   r  r   c_feature_names       rC   r6  Dataset.set_feature_name  s     6! ,<<#(@\U[E[< D$4$4$66 -c,.?-@@RSWScScSeRffst  8DD|tfTl|ND00LLV__n=LL\!23  Es   -C&c                    Xl         U R                  b  [        U[        5      (       aQ  [	        UR
                  5      S:  a  [        S5      e[        R                  " [        U[        R                  S95      nO,[        U5      (       a  UnO[        U[        R                  SS9nU R                  SU5        U R                  S5      U l         U $ )a  Set label of Dataset.

Parameters
----------
label : list, numpy 1-D array, pandas Series / one-column DataFrame, pyarrow Array, pyarrow ChunkedArray or None
    The label information to be set into Dataset.

Returns
-------
self : Dataset
    Dataset with set label.
r   z0DataFrame for label cannot have multiple columnsr  r  r  )r  r  r   r(   r   r  r   r`   rg   r  ra   r   r   r  r  )r{   r  label_arrays      rC   r1  Dataset.set_label  s     
<<#%..u}}%)$%WXX hh'7BJJ'WX"5))#/RZZgVNN7K00DJrB   c                    Ubq  [        U5      (       aA  [        R                  " [        R                  " US5      5      R	                  5       (       a  SnO [
        R                  " US:H  5      (       a  SnXl        U R                  bT  UbQ  [        U5      (       d  [        U[
        R                  SS9nU R                  SU5        U R                  S5      U l        U $ )a  Set weight of each instance.

Parameters
----------
weight : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None
    Weight to be set for each data point. Weights should be non-negative.

Returns
-------
self : Dataset
    Dataset with set weight.
Nr   r  r  )r   r%   r   equalas_pyr`   r  r  r   ra   r  r  )r{   r  s     rC   r3  Dataset.set_weight
  s    "  ((>>*"2"261"=>DDFF!F!$$ <<#(:$V,,*6(SNN8V,..2DKrB   c                     Xl         U R                  b+  Ub(  U R                  SU5        U R                  S5      U l         U $ )am  Set init score of Booster to start from.

Parameters
----------
init_score : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), pyarrow Array, pyarrow ChunkedArray, pyarrow Table (for multi-class task) or None
    Init score for Booster.

Returns
-------
self : Dataset
    Dataset with set init score.
r  )r  r  r  r  )r{   r  s     rC   r  Dataset.set_init_score+  s;      %<<#
(>NN<4"nn\:DOrB   c                    Xl         U R                  bm  Ubj  [        U5      (       d  [        U[        R
                  SS9nU R                  SU5        U R                  S5      nUb  [        R                  " U5      U l         U $ )aD  Set group size of Dataset (used for ranking).

Parameters
----------
group : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None
    Group/query data.
    Only used in the learning-to-rank task.
    sum(group) = n_samples.
    For example, if you have a 100-document dataset with ``group = [10, 20, 40, 10, 10, 10]``, that means that you have 6 groups,
    where the first 10 records are in the first group, records 11-30 are in the second group, records 31-70 are in the third group, etc.

Returns
-------
self : Dataset
    Dataset with set group.
r  r  )	r  r  r   r   r`   r  r  r  ra  )r{   r  constructed_groups      rC   r4  Dataset.set_groupA  sn    ( 
<<#(9$U++)%rxxgNNN7E* $w 7 ,WW%67
rB   c                     Xl         U R                  b.  Ub+  [        U[        R                  SS9nU R                  SU5        U $ )a  Set position of Dataset (used for ranking).

Parameters
----------
position : numpy 1-D array, pandas Series or None, optional (default=None)
    Position of items used in unbiased learning-to-rank task.

Returns
-------
self : Dataset
    Dataset with set position.
r  r  )r  r  r   r`   r  r  )r{   r  s     rC   r5  Dataset.set_position`  s=      !<<#(<(
SHNN:x0rB   c                    U R                   c  [        S5      eU R                  5       n[        R                  " S5      nSn[        R
                  " S5      n[        U5       Vs/ s H  n[        R                  " U5      PM     nn[        R                  U-  " [        [        R                  U5      6 n[        [        R                  " U R                   [        R                  " U5      [        R                  " U5      [        R
                  " U5      [        R                  " U5      U5      5        XR                  :w  a  [!        S5      eUR                  nX8:  a  [        U5       Vs/ s H  n[        R                  " U5      PM     nn[        R                  U-  " [        [        R                  U5      6 n[        [        R                  " U R                   [        R                  " U5      [        R                  " U5      [        R
                  " U5      [        R                  " U5      U5      5        [        U5       V	s/ s H   oU	   R                  R#                  S5      PM"     sn	$ s  snf s  snf s  sn	f )zGet the names of columns (features) in the Dataset.

Returns
-------
feature_names : list of str
    The names of columns (features) in the Dataset.
z0Cannot get feature_name before construct datasetr      6Length of feature names doesn't equal with num_featurer   )r  r/   r  rN   rO   c_size_tr  ri  r%  rB  r   rP   r   LGBM_DatasetGetFeatureNamesrT   rU   r   r   
r{   r  rn  reserved_string_buffer_sizerequired_string_buffer_sizerW  string_buffersptr_string_buffersactual_string_buffer_sizer  s
             rC   r  Dataset.get_feature_namev  s    << RSS&&(ll1o&)#&,ooa&8#\abm\no\nWX&556QR\no$oo;c&BRBRTb>cd,,[)[) ;<89"		
 +++UVV$?$E$E!&B^cdo^pq^pYZf99:ST^pNq"(//K"?#fFVFVXfBg!h00LLLL-LL-OO$=>LL!<=&	 BG{ASTASAq!''..w7ASTT; p" r Us   $ I/* I4'I9c                 `    U R                   c  U R                  S5      U l         U R                   $ )zGet the label of the Dataset.

Returns
-------
label : list, numpy 1-D array, pandas Series / one-column DataFrame or None
    The label information from the Dataset.
    For a constructed ``Dataset``, this will only return a numpy array.
r  )r  r  r   s    rC   r2  Dataset.get_label  s(     ::0DJzzrB   c                 `    U R                   c  U R                  S5      U l         U R                   $ )a  Get the weight of the Dataset.

Returns
-------
weight : list, numpy 1-D array, pandas Series or None
    Weight for each data point from the Dataset. Weights should be non-negative.
    For a constructed ``Dataset``, this will only return ``None`` or a numpy array.
r  )r  r  r   s    rC   
get_weightDataset.get_weight  s(     ;;..2DK{{rB   c                 `    U R                   c  U R                  S5      U l         U R                   $ )a,  Get the initial score of the Dataset.

Returns
-------
init_score : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), or None
    Init score of Booster.
    For a constructed ``Dataset``, this will only return ``None`` or a numpy array.
r  )r  r  r   s    rC   get_init_scoreDataset.get_init_score  s(     ??""nn\:DOrB   c                    U R                   c  [        S5      eU R                  (       Ga<  U R                  Gb.  U R                  Gb   U R                  R
                  U l        U R
                  Gb  [        U R
                  [        R                  [        R                  R                  45      (       a$  U R
                  U R                  SS24   U l        GO[        U R
                  [        5      (       a8  U R
                  R                  U R                     R                  5       U l        GO2[        U R
                  [        5      (       a-  [!        5         U R
                  U R                  SS24   U l        O[        U R
                  ["        5      (       a  U R
                  U R                     U l        O[%        U R
                  5      (       ab  ['        U R
                  5      S:  aI  [        R(                  " [+        U R-                  U R
                  U R                  5      5      5      U l        O,[/        S[1        U R
                  5      R2                   S35        SU l        U R
                  c  [5        S5      eU R
                  $ )a  Get the raw data of the Dataset.

Returns
-------
data : str, pathlib.Path, numpy array, pandas DataFrame, H2O DataTable's Frame (deprecated), scipy.sparse, Sequence, list of Sequence or list of numpy array or None
    Raw data used in the Dataset construction.
Nz(Cannot get data before construct Datasetr   zCannot subset z. type of raw data.
Returning original raw dataFzjCannot call `get_data` after freed raw data, set free_raw_data=False when construct Dataset to avoid this.)r  r  r  r  r  ri   r   r`   r   r5  r6  r>  r(   ilocr   r!   r\  r1   r   r   r   r   rD  r   r   r<   r/   r   s    rC   r  Dataset.get_data  s    <<FGG 1 1 =$..B\++DIyy$dii"**ell6K6K)LMM $		$*;*;Q*> ?DI		<88 $		t/@/@ A F F HDI		<8879 $		$*;*;Q*> ?DI		844 $		$*;*; <DI*49955#dii.1:L "d.J.J499VZVgVg.h)i jDI (dii)A)A(BBqr  %D99P  yyrB   c                     U R                   cH  U R                  S5      U l         U R                   b%  [        R                  " U R                   5      U l         U R                   $ )a!  Get the group of the Dataset.

Returns
-------
group : list, numpy 1-D array, pandas Series or None
    Group/query data.
    Only used in the learning-to-rank task.
    sum(group) = n_samples.
    For example, if you have a 100-document dataset with ``group = [10, 20, 40, 10, 10, 10]``, that means that you have 6 groups,
    where the first 10 records are in the first group, records 11-30 are in the second group, records 31-70 are in the third group, etc.
    For a constructed ``Dataset``, this will only return ``None`` or a numpy array.
r  )r  r  r`   ra  r   s    rC   	get_groupDataset.get_group  sF     ::0DJzz%WWTZZ0
zzrB   c                 `    U R                   c  U R                  S5      U l         U R                   $ )zGet the position of the Dataset.

Returns
-------
position : numpy 1-D array, pandas Series or None
    Position of items used in unbiased learning-to-rank task.
    For a constructed ``Dataset``, this will only return ``None`` or a numpy array.
r  )r  r  r   s    rC   get_positionDataset.get_position  s(     ==  NN:6DM}}rB   c                     U R                   b`  [        R                  " S5      n[        [        R
                  " U R                   [        R                  " U5      5      5        UR                  $ [        S5      e)ztGet the number of rows in the Dataset.

Returns
-------
number_of_rows : int
    The number of rows in the Dataset.
r   z,Cannot get num_data before construct dataset)	r  rN   rO   rP   r   LGBM_DatasetGetNumDatarT   rU   r/   r{   r   s     rC   r  Dataset.num_data  s\     <<#,,q/C++LLLL% 99 NOOrB   c                     U R                   b`  [        R                  " S5      n[        [        R
                  " U R                   [        R                  " U5      5      5        UR                  $ [        S5      e)zGet the number of columns (features) in the Dataset.

Returns
-------
number_of_columns : int
    The number of columns (features) in the Dataset.
r   z/Cannot get num_feature before construct dataset)	r  rN   rO   rP   r   LGBM_DatasetGetNumFeaturerT   rU   r/   r  s     rC   r  Dataset.num_feature#  s\     <<#,,q/C..LLLL% 99 QRRrB   featurec           	         U R                   b  [        U[        5      (       a  U R                  R	                  U5      nOUn[
        R                  " S5      n[        [        R                  " U R                   [
        R                  " U5      [
        R                  " U5      5      5        UR                  $ [        S5      e)zGet the number of bins for a feature.

.. versionadded:: 4.0.0

Parameters
----------
feature : int or str
    Index or name of the feature.

Returns
-------
number_of_bins : int
    The number of constructed bins for the feature in the Dataset.
r   z3Cannot get feature_num_bin before construct dataset)r  r   r   r  indexrN   rO   rP   r   LGBM_DatasetGetFeatureNumBinrT   rU   r/   )r{   r  feature_indexr   s       rC   feature_num_binDataset.feature_num_bin7  s     <<#'3'' $ 1 1 7 7 @ ',,q/C11LLLL/LL% 99 UVVrB   	ref_limitc                 
   U n[        5       n[        U5      U:  ag  [        U[        5      (       a>  UR	                  U5        UR
                  b  UR
                  U;  a  UR
                  nO U$  U$ [        U5      U:  a  Mg  U$ )ab  Get a chain of Dataset objects.

Starts with r, then goes to r.reference (if exists),
then to r.reference.reference, etc.
until we hit ``ref_limit`` or a reference loop.

Parameters
----------
ref_limit : int, optional (default=100)
    The limit number of references.

Returns
-------
ref_chain : set of Dataset
    Chain of references of the Datasets.
)rA  r   r   r-   r'  r  )r{   r  head	ref_chains       rC   r  Dataset.get_ref_chainW  s    " "%%	)ny($((d#NN.T^^95T>>D   )ny( rB   c                    U R                   b  UR                   c  [        S5      e[        [        R                  " U R                   UR                   5      5        U R
                  SL n[        U R
                  5      R                  nUR
                  c	  SU l        GOZU R
                  GbL  [        U R
                  [        R                  5      (       Ga  [        UR
                  [        R                  5      (       a3  [        R                  " U R
                  UR
                  45      U l        GO[        UR
                  [        R                  R                  5      (       aA  [        R                  " U R
                  UR
                  R                  5       45      U l        GOR[        UR
                  [         5      (       a=  [        R                  " U R
                  UR
                  R"                  45      U l        GO[        UR
                  [$        5      (       aK  ['        5         [        R                  " U R
                  UR
                  R)                  5       45      U l        GOSU l        GO[        U R
                  [        R                  R                  5      (       Gaw  U R
                  R+                  5       n[        UR
                  [        R                  [        R                  R                  45      (       a;  [        R                  R                  U R
                  UR
                  4US9U l        GO[        UR
                  [         5      (       aE  [        R                  R                  U R
                  UR
                  R"                  4US9U l        GOS[        UR
                  [$        5      (       aS  ['        5         [        R                  R                  U R
                  UR
                  R)                  5       4US9U l        GOSU l        GO[        U R
                  [         5      (       Ga  [,        (       d  [/        S5      e[        UR
                  [        R                  5      (       a1  [1        U R
                  [!        UR
                  5      4SSS9U l        GOH[        UR
                  [        R                  R                  5      (       a?  [1        U R
                  [!        UR
                  R                  5       5      4SSS9U l        GO[        UR
                  [         5      (       a(  [1        U R
                  UR
                  4SSS9U l        GO[        UR
                  [$        5      (       aI  ['        5         [1        U R
                  [!        UR
                  R)                  5       5      4SSS9U l        GO'SU l        GO[        U R
                  [$        5      (       Ga  ['        5         [        UR
                  [        R                  5      (       aJ  [%        [        R                  " U R
                  R)                  5       UR
                  45      5      U l        GO[        UR
                  [        R                  R                  5      (       aW  [%        [        R                  " U R
                  R)                  5       UR
                  R                  5       45      5      U l        O[        UR
                  [         5      (       aS  [%        [        R                  " U R
                  R)                  5       UR
                  R"                  45      5      U l        O[        UR
                  [$        5      (       aW  [%        [        R                  " U R
                  R)                  5       UR
                  R)                  5       45      5      U l        OSU l        OSU l        U R
                  c?  S[        UR
                  5      R                   S	U S
3nUU(       a  SOS-  n[3        U5        U R5                  5       U l        [3        S5        SU l        SU l        U $ )a  Add features from other Dataset to the current Dataset.

Both Datasets must be constructed before calling this method.

Parameters
----------
other : Dataset
    The Dataset to take features from.

Returns
-------
self : Dataset
    Dataset with the new features added.
NzJBoth source and target Datasets must be constructed before adding features)formatztCannot add features to DataFrame type of raw data without pandas installed. Install pandas and restart your session.r   T)axisignore_indexzCannot add features from z type of raw data to z type of raw data.
z<Set free_raw_data=False when construct Dataset to avoid thiszFreeing raw datazkResetting categorical features.
You can set new categorical features via ``set_categorical_feature`` methodr  )r  r   rP   r   LGBM_DatasetAddFeaturesFromri   r   r<   r   r`   r   hstackr5  r6  r>  toarrayr(   r  r!   r\  r  	getformatr   r/   r    r   r  r  r  r  )r{   otherwas_noneold_self_data_typesparse_formaterr_msgs         rC   add_features_fromDataset.add_features_fromu  s~    <<5==#8ijj,,	
 99$!$))_55::DIYY"$))RZZ00ejj"**55 "		499ejj*A BDI

ELL,A,ABB "		499ejj6H6H6J*K LDI

L99 "		499ejj6G6G*H IDI

L9979 "		499ejj6I6I6K*L MDI $DIDIIu||'<'<== $		 3 3 5ejj2::u||7L7L*MNN % 3 3TYY

4KTa 3 bDI

L99 % 3 3TYY

@Q@Q4R[h 3 iDI

L9979 % 3 3TYY

@S@S@U4V_l 3 mDI $DIDII|44'''C 
 ejj"**55 &		<

3K'LSTcg hDI

ELL,A,ABB &		<

@R@R@T3U'V]^mq rDI

L99 &		5::'>QUY ZDI

L9979 &		<

@S@S@U3V'W^_nr sDI $DIDII|4435ejj"**55 ,RYY		8J8J8Lejj7Y-Z [DI

ELL,A,ABB ,RYY		8J8J8LejjN`N`Nb7c-d eDI

L99 ,RYY		8J8J8LejjN_N_7`-a bDI

L99 ,RYY		8J8J8LejjNaNaNc7d-e fDI $DI 	99+D,<,E,E+FF[%&&:<  RZN`rG ! 113Z	
 $* "&rB   c           
          [        [        R                  " U R                  5       R                  [        [        U5      5      5      5        U $ )zSave Dataset to a text file.

This format cannot be loaded back in by LightGBM, but is useful for debugging purposes.

Parameters
----------
filename : str or pathlib.Path
    Name of the output file.

Returns
-------
self : Dataset
    Returns self.
)rP   r   LGBM_DatasetDumpTextr)  r  rS   r   r  s     rC   
_dump_textDataset._dump_text  s=     	%% ((s8}%	
 rB   )r  r  r  r  r  r  ri   r  r  r  r  r  r  rL   r  r  r  r  r  )
NNNNNr  r  NTNr  )rE   r-   )NNNNNNrG   )r  r-   rE   r-   )d   )r	  r-   rE   r-   )Xr<   r=   r>   r?   r@   _LGBM_TrainDataTyper   _LGBM_LabelType_LGBM_WeightType_LGBM_GroupType_LGBM_InitScoreType_LGBM_FeatureNameConfiguration%_LGBM_CategoricalFeatureConfigurationr   r   r   r  _LGBM_PositionTyper   r  r   r`   r   r  _DatasetHandler  r   r  r  r  r  r  r   r  r%  r  r1   r   r   rD  r   rV  r0  r-  r/  r5  r6  r7  r+  r9  r,  r&   r.  r   r  r)  r  r  r   r  r  r  _LGBM_SetFieldTyper  r  r  r  r  r6  r1  r3  r  r4  r5  r  r2  r  r  r  r  r  r  r  r  r  r  r  rA   r:   rB   rC   r-   r-     s    ,0)--1+/487=EK+/"15I!I (I I&	I
 )*I (I 01I 5I CI c3h(I I -.IV     D $ 
	:>"**%> RZZ(> 	>
 > 
>@rzz i <#DcN #J)O,) ") uT#Y

%:;<	)
 
)V}3*+}3 (}3 I&	}3
 )*}3 (}3 01}3 O,}3 5}3 C}3 c3h(}3 -.}3 
}3~ >d8n >x} >QYZ\ZdZdQe > >&T(^ & &tBJJGWY]^`^h^hYiGiAj &88n n- 
	BZZ  n-	
 
642::4 4 n-	4
 
4l \\$$    n-	 
 
 D \\$$    n-	 
 
 D  n-	
 
: S#X38n X 
	 BY| ,0-1+/48+/154!4 (4 )*	4
 (4 014 c3h(4 -.4 
4r ,0 3i  c3h(  
	 DE#t)$4  4Xd38n%= ) 8ee )*e 
	eN;C ;HRZZ,@ ;z$B$ 
$L%O,% 
%N8-K PY <x8 Y 6)* 
B01 
,( 
>-. 
,+U$s) +UZ8O4 H%56 )< = "(#67 "H8O4 (h'9: P# P(SS S(WuS#X W3 W@s S^ <cJ5d#3 	 rB   r-   c                      \ rS rSrSr    S_S\\\\4      S\\	   S\\
\\4      S\\   4S jjrS`S
 jrSaS jrS\S\S	S 4S jrS	\\\4   4S jrS\\\4   S	S4S jrS	\\\4   4S jrSaS jrSaS jr   SbS\
\\   \\   \4   S\S\S\S	S 4
S jjrSaS jrS	\4S jrS\S	S 4S jrS\	S\S	S 4S jrS\\\4   S	S 4S  jr  ScS\\	   S!\\   S	\ 4S" jjr!S#\"RF                  S$\"RF                  S	\ 4S% jr$SaS& jr%S	\4S' jr&S	\4S( jr'S	\4S) jr(S	\)4S* jr*S	\)4S+ jr+ SdS\	S\S,\\
\,\\,   4      S	\\-   4S- jjr. SdS,\\
\,\\,   4      S	\\-   4S. jjr/ SdS,\\
\,\\,   4      S	\\-   4S/ jjr0   SeS0\
\\4   S1\\   S2\S3\S	S 4
S4 jjr1  SfS2\S5\S	S 4S6 jjr2S\S	S 4S7 jr3   SeS1\\   S2\S3\S	\4S8 jjr4    SgS1\\   S2\S3\S9\\5\\\4   /\\\4   4      S	\\\4   4
S: jjr6       ShS\7S2\S1\\   S;\ S<\ S=\ S>\ S?\ S\S	\
\"RF                  \8Rr                  Rt                  \\8Rr                  Rt                     4   4S@ jjr;          SiS\<SA\=SB\)SC\\	   SD\\>   SE\\?   SF\\@   SG\ASH\BSI\\\\4      SJ\ S?\ S\S	S 4SK jjrCSL\SM\S	\)4SN jrDSL\SM\SO\)S	S 4SP jrES	\4SQ jrFS	\\   4SR jrG  SjS3\SS\\   S	\"RF                  4ST jjrH  SkSU\
\\4   SV\\
\\4      SW\ S	\
\I\"RF                  \"RF                  4   \"RF                  \4   4SX jjrJSY\SZ\S,\\
\,\\,   4      S	\\-   4S[ jrKSZ\S	\"RF                  4S\ jrLS`S] jrMS^rNg)lr,   i  zBooster in LightGBM.NrL   	train_setr  r  c           	         [         R                  " 5       U l        SU l        SU l        SU l        SU l        SU l        0 U l        Uc  0 O
[        U5      nUGb  [        U[        5      (       d!  [        S[        U5      R                   35      e[        SUSS9nUS   c  UR!                  SS5        OUS   n[        U["        5      (       a  [%        UR'                  S	5      5      nOC[        U[(        [*        45      (       a  [%        U5      nS	R-                  U5      nO[/        S
5      e[        SUUS9n[        SUSS9nU R1                  UUS   UR3                  SS5      US   S9  UR5                  5         UR7                  UR9                  5       5        [;        U5      n[=        [>        R@                  " UR                  [C        U5      [         RD                  " U R                  5      5      5        X l#        / U l$        / U l%        SU l&        URN                  U l(        U RP                  b>  [=        [>        RR                  " U R                  U RP                  R                  5      5        [         RT                  " S5      n[=        [>        RV                  " U R                  [         RD                  " U5      5      5        URX                  U l-        S/U l.        S/U l/        U Ra                  5         URb                  U l1        URd                  U l3        GO5UGb  [         RT                  " S5      n	[=        [>        Rh                  " [C        [#        U5      5      [         RD                  " U	5      [         RD                  " U R                  5      5      5        [         RT                  " S5      n[=        [>        RV                  " U R                  [         RD                  " U5      5      5        URX                  U l-        [k        US9U l1        U(       a  [m        S5        U Ro                  5       nO Ub  U Rq                  U5        O[        S5      eXl9        g)a}  Initialize the Booster.

Parameters
----------
params : dict or None, optional (default=None)
    Parameters for Booster.
train_set : Dataset or None, optional (default=None)
    Training dataset.
model_file : str, pathlib.Path or None, optional (default=None)
    Path to the model file.
model_str : str or None, optional (default=None)
    Model will be loaded from this string.
FTtrainingr  N.Training data should be Dataset instance, met machinesr  rL   r  r3  zInvalid machines in params.num_machineslocal_listen_portp0  time_outx   )r$  r'  listen_time_outr&  r   r   r  z;Ignoring params argument, using parameters from model file.z[Need at least one training dataset or model file or model string to create Booster instance):rN   r  r  _network_Booster__need_reload_eval_info_train_data_name_Booster__set_objective_to_nonebest_iteration
best_scorer   r   r-   r   r   r<   r  r  r   r   r  r   rA  r   r   set_networkrz  r)  rw  r  rF  rP   r   LGBM_BoosterCreaterS   rT   r   
valid_setsname_valid_sets_Booster__num_datasetr  _Booster__init_predictorLGBM_BoosterMergerO   r  rU   _Booster__num_class_Booster__inner_predict_buffer_Booster__is_predicted_cur_iter_Booster__get_eval_infor  r  train_set_versionr  r  r   _get_loaded_parammodel_from_stringrL   )
r{   rL   r   r  r  r$  num_machines_from_machine_listr  r  r  s
             rC   r   Booster.__init__  s   ( ('+$ *',$ 68~8F+; i11"PQUV_Q`QiQiPj kll( *"F j!)

:t,!*-h,,589L5M24+6658]2"xx1H$%BCC,$2!"@
 -$7!"'
   %&,-@&A$*JJz3$?!'!7	 !  !MM)..01+F3J''%%:&LL. 'N-/DO.0D !"D$-$8$8D!$$0**--55 #LLOM..LLLL/  -22DGKfD',17D(  "&/&B&BD#%.%6%6D"#!'a443z?+LL!34LL. #LLOM..LLLL/  -22D&>&TD#Z[++-F"""9-m  rB   rE   c                      U R                   (       a  U R                  5          U R                  b*  [	        [
        R                  " U R                  5      5        g g ! [         a     NEf = f! [         a     g f = frG   )r,  free_networkr  r  rP   r   r  r   s    rC   r  Booster.__del__  sl    	}}!!#	||'400>? (  		
  		s"   !A 6A, 
A)(A),
A98A9c                 $    U R                  S 5      $ rG   )__deepcopy__r   s    rC   __copy__Booster.__copy__  s      &&rB   rt  kwargsc                 2    U R                  SS9n[        US9$ )Nr  r   r  )model_to_stringr,   )r{   rt  rI  r  s       rC   rF  Booster.__deepcopy__  s     ((r(:	++rB   c                     U R                   R                  5       nUS   nUR                  SS 5        UR                  SS 5        Ub  U R                  SS9US'   U$ )Nr  r   r4  r  rK  )r  r   r  rM  )r{   r  r  s      rC   r  Booster.__getstate__  s[    }}!!#id#t$"222DDOrB   statec           	         UR                  SUR                  SS 5      5      nUb  [        R                  " 5       n[        R                  " S5      n[	        [
        R                  " [        U5      [        R                  " U5      [        R                  " U5      5      5        X1S'   U R                  R                  U5        g )Nr  r  r   )rz  rN   r  rO   rP   r   LGBM_BoosterLoadModelFromStringrS   rT   r  rw  )r{   rQ  r  r  r  s        rC   __setstate__Booster.__setstate__  s    IIi8T)BC	 __&F!'a449%LL!34LL(  &)U#rB   c           	         Sn[         R                  " S5      n[         R                  " U5      n[         R                  " [         R                  " U5      5      n[        [        R                  " U R                  [         R                  " U5      [         R                  " U5      U5      5        UR                  nXQ:  a  [         R                  " U5      n[         R                  " [         R                  " U5      5      n[        [        R                  " U R                  [         R                  " U5      [         R                  " U5      U5      5        [        R                  " UR                  R                  S5      5      $ )Nr`  r   r   )rN   r!  ri  r%  r   rP   r   LGBM_BoosterGetLoadedParamr  rT   rU   rk  rl  r   )r{   rm  rn  ro  rp  rq  s         rC   r>  Booster._get_loaded_param  s   
nnQ'33J?"OOF,<,<],KL++z*[)!		
 !&&
""77
CM &0@0@0O P//LLNN:.LL-%	 zz---44W=>>rB   c                     U R                   R                  SS5        U R                   R                  SS5        SU l        U $ )zWFree Booster's Datasets.

Returns
-------
self : Booster
    Booster without Datasets.
r   Nr4  r   )r  r  r6  r   s    rC   free_datasetBooster.free_dataset  s9     	+t,,-rB   c                 "    / U l         / U l        U $ rG   )r:  r;  r   s    rC   _free_bufferBooster._free_buffer  s    &(#')$rB   r$  r'  r+  r&  c           
      :   [        U[        [        45      (       a  SR                  U5      n[	        [
        R                  " [        U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      5      5        SU l
        U $ )a  Set the network configuration.

Parameters
----------
machines : list, set or str
    Names of machines.
local_listen_port : int, optional (default=12400)
    TCP listen port for local machines.
listen_time_out : int, optional (default=120)
    Socket time-out in minutes.
num_machines : int, optional (default=1)
    The number of machines for distributed learning application.

Returns
-------
self : Booster
    Booster with set network.
r3  T)r   r   rA  r   rP   r   LGBM_NetworkInitrS   rN   rO   r,  )r{   r$  r'  r+  r&  s        rC   r2  Booster.set_network  st    2 hs,,xx)H!!x ./_-\*		
 rB   c                 P    [        [        R                  " 5       5        SU l        U $ )zXFree Booster's network.

Returns
-------
self : Booster
    Booster with freed network.
F)rP   r   LGBM_NetworkFreer,  r   s    rC   rC  Booster.free_network  s!     	4((*+rB   c                   ^^^ [         (       d  [        S5      eU R                  5       S:X  a  [        S5      eS[        [        [
        4   S[        4S jm    SS[        [        [
        4   S[        S[        [           S	[        [        [              S
[        [           S[        [        [
        4   4U4S jjjm    SS[        [        [
        4   S[        S[        [           S	[        [        [              S
[        [           S[        [        [        [
        4      4UUU4S jjjmU R                  5       nUS	   n/ nUS    H   nUR                  T" US   US   US95        M"     [        X3S   R                  5       S9$ )a"  Parse the fitted model and return in an easy-to-read pandas DataFrame.

The returned DataFrame has the following columns.

    - ``tree_index`` : int64, which tree a node belongs to. 0-based, so a value of ``6``, for example, means "this node is in the 7th tree".
    - ``node_depth`` : int64, how far a node is from the root of the tree. The root node has a value of ``1``, its direct children are ``2``, etc.
    - ``node_index`` : str, unique identifier for a node.
    - ``left_child`` : str, ``node_index`` of the child node to the left of a split. ``None`` for leaf nodes.
    - ``right_child`` : str, ``node_index`` of the child node to the right of a split. ``None`` for leaf nodes.
    - ``parent_index`` : str, ``node_index`` of this node's parent. ``None`` for the root node.
    - ``split_feature`` : str, name of the feature used for splitting. ``None`` for leaf nodes.
    - ``split_gain`` : float64, gain from adding this split to the tree. ``NaN`` for leaf nodes.
    - ``threshold`` : float64, value of the feature used to decide which side of the split a record will go down. ``NaN`` for leaf nodes.
    - ``decision_type`` : str, logical operator describing how to compare a value to ``threshold``.
      For example, ``split_feature = "Column_10", threshold = 15, decision_type = "<="`` means that
      records where ``Column_10 <= 15`` follow the left side of the split, otherwise follows the right side of the split. ``None`` for leaf nodes.
    - ``missing_direction`` : str, split direction that missing values should go to. ``None`` for leaf nodes.
    - ``missing_type`` : str, describes what types of values are treated as missing.
    - ``value`` : float64, predicted value for this leaf node, multiplied by the learning rate.
    - ``weight`` : float64 or int64, sum of Hessian (second-order derivative of objective), summed over observations that fall in this node.
    - ``count`` : int64, number of records in the training data that fall into this node.

Returns
-------
result : pandas DataFrame
    Returns a pandas DataFrame of the parsed model.
zxThis method cannot be run without pandas installed. You must install pandas and restart your session to use this method.r   z<There are no trees in this Booster and thus nothing to parsetreerE   c                 (    SU R                  5       ;   $ )Nsplit_index)r  rf  s    rC   _is_split_node2Booster.trees_to_dataframe.<locals>._is_split_node<  s     DIIK//rB   
node_depth
tree_indexfeature_namesparent_nodec                 
  > S[         [        [        4   S[        [           S[        4U	4S jjnS[         [        [        4   S[        [
        [              S[        [           4U	4S jjnS[         [        [        4   S[        4S jn[        5       nX(S'   XS'   U" X5      US	'   S US
'   S US'   XHS'   U" X5      US'   S US'   S US'   S US'   S US'   S US'   S US'   S US'   S US'   T	" U 5      (       ai  U" U S
   U5      US
'   U" U S   U5      US'   U S   US'   U S   US'   U S   US'   U S   (       a  SOSUS'   U S   US'   U S   US'   U S   US'   U S   US'   U$ U S   US'   U" U 5      (       d  U S   US'   U S   US'   U$ )Nrf  rm  rE   c                    > Ub  U S3OSnT" U 5      nU(       a  SOSnU R                  U(       a  SOSS5      nU U U 3$ )N-r   SLrh  
leaf_indexr   )rz  )rf  rm  tree_numis_split	node_typenode_numrj  s         rC   _get_node_indexOBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._get_node_indexF  sS     0:/Ej\+2)$/#+C	88XM<QRS"I;xj99rB   rn  c                 N   > T" U 5      (       a  Ub	  XS      nU$ U S   n U$ S nU$ )Nsplit_featurer:   )rf  rn  r  rj  s      rC   _get_split_featureRBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._get_split_featureQ  sL     "$''$0'4/5J'K
 $# (,O'< $# $(L##rB   c                 >    [        U R                  5       5      SS1:H  $ )N
leaf_value
leaf_count)rA  r  ri  s    rC   _is_single_node_treeTBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._is_single_node_tree^  s    499;'L,+GGGrB   rl  
node_index
left_childright_childparent_indexr}  
split_gain	thresholddecision_typemissing_directionmissing_typerU   r  countdefault_leftleftrightinternal_valueinternal_weightinternal_countr  leaf_weightr  )r   r   r   r   r   r   r  r   )
rf  rl  rm  rn  ro  rz  r~  r  noderj  s
            rC   create_node_record6Booster.trees_to_dataframe.<locals>.create_node_record?  s   	:38n	:$SM	: 	:$38n$'S	2$ #$H4S> Hd H 6A]D!+!+!0!BD!%D"&D#. $6t$KD!!%D $D$(D!(,D$%#'D  DM!DN DM d##%4T,5G%T\"&5d=6I:&V]#%),%7\"$($5[!(,_(=_%6:>6JFPW()'+N';^$ $%5 6W!%&7!8X $%5 6W K !%\ 2W+D11%)-%8DN$($6DMKrB   c           	         > T" U UUUUS9nU/nT
" U 5      (       a0  SS/nU H&  nT" X   US-   UUUS   S9n	UR                  U	5        M(     U$ )N)rf  rl  rm  rn  ro  r  r  r   r  )extend)rf  rl  rm  rn  ro  r  reschildrenchildsubtree_listrj  r  tree_dict_to_node_lists             rC   r  :Booster.trees_to_dataframe.<locals>.tree_dict_to_node_list  s     &%%+'D &Cd##(-8%E#9![#->#-&3$($6$L JJ|, & JrB   	tree_infotree_structure)rf  rm  rn  r  )r   NNN)r   r/   	num_treesr   r   r   r  r   r   r   
dump_modelr  r(   r  )r{   
model_dictrn  
model_listrf  rj  r  r  s        @@@rC   trees_to_dataframeBooster.trees_to_dataframe  s   8  W 
 >>q  ^__	0c3h 	0D 	0
  (,15)-F	sCx.F	F	 !F	 $DI.	F	
 "#F	 #s(^F	 F	T  (,15)-	sCx.		 !	 $DI.		
 "#	 $sCx.!	 	B __&
"?3
{+D&./D<N^k , J10B0B0DEErB   r   c                     Xl         U $ )zSet the name to the training Dataset.

Parameters
----------
name : str
    Name for the training Dataset.

Returns
-------
self : Booster
    Booster with set training Dataset name.
)r.  )r{   r   s     rC   set_train_data_nameBooster.set_train_data_name  s     !%rB   ri   c                 @   [        U[        5      (       d!  [        S[        U5      R                   35      eUR
                  U R                  La  [        S5      e[        [        R                  " U R                  UR                  5       R                  5      5        U R                  R                  U5        U R                  R                  U5        U =R                   S-  sl        U R"                  R                  S5        U R$                  R                  S5        U $ )zAdd validation data.

Parameters
----------
data : Dataset
    Validation data.
name : str
    Name of validation data.

Returns
-------
self : Booster
    Booster with set validation data.
z0Validation data should be Dataset instance, met zHAdd validation data failed, you should use same predictor for these datar   NF)r   r-   r   r   r<   r  r7  r/   rP   r   LGBM_BoosterAddValidDatar  r)  r4  r   r5  r6  r:  r;  )r{   ri   r   s      rC   	add_validBooster.add_valid  s     $((NtTXzObObNcdee??$"7"77 jkk)) ((	
 	t$##D)a##**40$$++E2rB   c                     [        U5      nU(       a3  [        [        R                  " U R                  [        U5      5      5        U R                  R                  U5        U $ )zReset parameters of Booster.

Parameters
----------
params : dict
    New parameters for Booster.

Returns
-------
self : Booster
    Booster with new parameters.
)rF  rP   r   LGBM_BoosterResetParameterr  rS   rL   rw  )r{   rL   r  s      rC   reset_parameterBooster.reset_parameter  sO     (/
//LL:& 	6"rB   fobjc                    Uc3  U R                   U R                  R                  :w  a  U R                  nSnO-XR                  L =(       a    U R                   UR                  :H  nUb  U(       d  [        U[        5      (       d!  [        S[        U5      R                   35      eUR                  U R                  La  [        S5      eXl        [        [        R                  " U R                  U R                  R                  5       R                  5      5        SU R                   S'   U R                  R                  U l         ["        R$                  " S5      nUc  U R&                  (       a  [        S5      e[        [        R(                  " U R                  ["        R*                  " U5      5      5        [-        U R.                  5       Vs/ s H  nSPM     snU l        UR2                  S:H  $ U R&                  (       d  SU R5                  S	S
05      l        U" U R7                  S5      U R                  5      u  pgU R9                  Xg5      $ s  snf )aE  Update Booster for one iteration.

Parameters
----------
train_set : Dataset or None, optional (default=None)
    Training data.
    If None, last training data is used.
fobj : callable or None, optional (default=None)
    Customized objective function.
    Should accept two parameters: preds, train_data,
    and return (grad, hess).

        preds : numpy 1-D array or numpy 2-D array (for multi-class task)
            The predicted values.
            Predicted values are returned before any transformation,
            e.g. they are raw margin instead of probability of positive class for binary task.
        train_data : Dataset
            The training dataset.
        grad : numpy 1-D array or numpy 2-D array (for multi-class task)
            The value of the first order derivative (gradient) of the loss
            with respect to the elements of preds for each sample point.
        hess : numpy 1-D array or numpy 2-D array (for multi-class task)
            The value of the second order derivative (Hessian) of the loss
            with respect to the elements of preds for each sample point.

    For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes],
    and grad and hess should be returned in the same format.

Returns
-------
is_finished : bool
    Whether the update was successfully finished.
NFr#  zJReplace training data failed, you should use same predictor for these datar   z-Cannot update due to null objective function.r   T	objectivenone)r=  r   r  r   r-   r   r   r<   r  r7  r/   rP   r   LGBM_BoosterResetTrainingDatar  r)  r:  rN   rO   r/  LGBM_BoosterUpdateOneIterrT   r  r6  r;  rU   r  _Booster__inner_predict_Booster__boost)r{   r   r  is_the_same_train_setis_finishedrW  gradhesss           rC   rw  Booster.update  s   N !7!74>>;Q;Q!QI$)!$-$?$oDDZDZ^g^o^oDo! )>i11"PQUV_Q`QiQiPj kll##4+@+@@#$pqq&N22LLNN,,.66 .2D''*%)^^%;%;D"ll1o<++#$STT..LLLL- <AASAS;T+U;TaE;T+UD($$))//VZ$$k6%:;Sd2215t~~FJD<<++ ,Vs   Ir  r  c                    U R                   S:  a  UR                  SS9nUR                  SS9n[        U[        R                  SS9n[        U[        R                  SS9nUR
                  R                  (       d   eUR
                  R                  (       d   e[        U5      [        U5      :w  a$  [        S[        U5       S[        U5       S	35      eU R                  R                  5       n[        U5      X0R                   -  :w  a4  [        S[        U5       S[        U5       S
U SU R                    S3	5      e[        R                  " S5      n[        [        R                  " U R                   UR                  R#                  [        R$                  " [        R&                  5      5      UR                  R#                  [        R$                  " [        R&                  5      5      [        R(                  " U5      5      5        [+        U R,                  5       Vs/ s H  nSPM     snU l        UR0                  S:H  $ s  snf )a`  Boost Booster for one iteration with customized gradient statistics.

.. note::

    Score is returned before any transformation,
    e.g. it is raw margin instead of probability of positive class for binary task.
    For multi-class task, score are numpy 2-D array of shape = [n_samples, n_classes],
    and grad and hess should be returned in the same format.

Parameters
----------
grad : numpy 1-D array or numpy 2-D array (for multi-class task)
    The value of the first order derivative (gradient) of the loss
    with respect to the elements of score for each sample point.
hess : numpy 1-D array or numpy 2-D array (for multi-class task)
    The value of the second order derivative (Hessian) of the loss
    with respect to the elements of score for each sample point.

Returns
-------
is_finished : bool
    Whether the boost was successfully finished.
r   r[   r_   gradientr  hessianzLengths of gradient (z) and Hessian (r  z$) don't match training data length (z() * number of models per one iteration (r  r   F)r9  rg   r   r`   ra   rc   r  r   r   r   r  rN   rO   rP   r   LGBM_BoosterUpdateOneIterCustomr  r  r  r  rT   r  r6  r;  rU   )r{   r  r  num_train_datar  rW  s         rC   __boostBooster.__boostH  s   8 a::C:(D::C:(D RZZjI RZZiHzz&&&&zz&&&&t9D	!4SYKsSWykYfghh002t9)9)999'D	{/#d) M55C4D E77;7G7G6HK 
 ll1o00##FNN6>>$BC##FNN6>>$BC[)		
 8=T=O=O7P'Q7P!7P'Q$  A%% (Rs   #Ic                     [        [        R                  " U R                  5      5        [	        U R
                  5       Vs/ s H  nSPM     snU l        U $ s  snf )zdRollback one iteration.

Returns
-------
self : Booster
    Booster with rolled back one iteration.
F)rP   r   LGBM_BoosterRollbackOneIterr  r  r6  r;  )r{   rW  s     rC   rollback_one_iterBooster.rollback_one_iter  sJ     	433DLLAB7<T=O=O7P'Q7P!7P'Q$ (Rs   Ac                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ r  r  r  s     rC   r  Booster.current_iteration  r  rB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ )zrGet number of models per iteration.

Returns
-------
model_per_iter : int
    The number of models per iteration.
r   )rN   rO   rP   r    LGBM_BoosterNumModelPerIterationr  rT   rU   )r{   model_per_iters     rC   num_model_per_iterationBooster.num_model_per_iteration  sH      a11^,	
 ###rB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ )zcGet number of weak sub-models.

Returns
-------
num_trees : int
    The number of weak sub-models.
r   )rN   rO   rP   r   LGBM_BoosterNumberOfTotalModelr  rT   rU   )r{   r  s     rC   r  Booster.num_trees  sF     LLO	//Y'	
 rB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ )zkGet upper bound value of a model.

Returns
-------
upper_bound : float
    Upper bound value of the model.
r   )rN   r  rP   r   LGBM_BoosterGetUpperBoundValuer  rT   rU   r  s     rC   upper_boundBooster.upper_bound  G     ooa //S!	
 yyrB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ )zkGet lower bound value of a model.

Returns
-------
lower_bound : float
    Lower bound value of the model.
r   )rN   r  rP   r   LGBM_BoosterGetLowerBoundValuer  rT   rU   r  s     rC   lower_boundBooster.lower_bound  r  rB   fevalc                 R   [        U[        5      (       d  [        S5      eSnXR                  L a  SnO=[	        [        U R                  5      5       H  nXR                  U   L d  M  US-   n  O   US:X  a   U R                  X5        U R                  S-
  nU R                  X$U5      $ )a  Evaluate for data.

Parameters
----------
data : Dataset
    Data for the evaluating.
name : str
    Name of the data.
feval : callable, list of callable, or None, optional (default=None)
    Customized evaluation function.
    Each evaluation function should accept two parameters: preds, eval_data,
    and return (eval_name, eval_result, is_higher_better) or list of such tuples.

        preds : numpy 1-D array or numpy 2-D array (for multi-class task)
            The predicted values.
            For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes].
            If custom objective function is used, predicted values are returned before any transformation,
            e.g. they are raw margin instead of probability of positive class for binary task in this case.
        eval_data : Dataset
            A ``Dataset`` to evaluate.
        eval_name : str
            The name of evaluation function (without whitespace).
        eval_result : float
            The eval result.
        is_higher_better : bool
            Is eval result higher better, e.g. AUC is ``is_higher_better``.

Returns
-------
result : list
    List with (dataset_name, eval_name, eval_result, is_higher_better) tuples.
z"Can only eval for Dataset instancer  r   r   )
r   r-   r   r   r  r   r4  r  r6  _Booster__inner_eval)r{   ri   r   r  data_idxr  s         rC   evalBooster.eval  s    L $((@AA>>!H3t/0??1-- 1uH 1
 r>NN4&))A-H  77rB   c                 <    U R                  U R                  SU5      $ )a  Evaluate for training data.

Parameters
----------
feval : callable, list of callable, or None, optional (default=None)
    Customized evaluation function.
    Each evaluation function should accept two parameters: preds, eval_data,
    and return (eval_name, eval_result, is_higher_better) or list of such tuples.

        preds : numpy 1-D array or numpy 2-D array (for multi-class task)
            The predicted values.
            For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes].
            If custom objective function is used, predicted values are returned before any transformation,
            e.g. they are raw margin instead of probability of positive class for binary task in this case.
        eval_data : Dataset
            The training dataset.
        eval_name : str
            The name of evaluation function (without whitespace).
        eval_result : float
            The eval result.
        is_higher_better : bool
            Is eval result higher better, e.g. AUC is ``is_higher_better``.

Returns
-------
result : list
    List with (train_dataset_name, eval_name, eval_result, is_higher_better) tuples.
r   )r  r.  )r{   r  s     rC   
eval_trainBooster.eval_train  s     @   !6!65AArB   c           	          [        SU R                  5       VVs/ s H/  nU R                  U R                  US-
     X!5        H  nUPM     M1     snn$ s  snnf )a  Evaluate for validation data.

Parameters
----------
feval : callable, list of callable, or None, optional (default=None)
    Customized evaluation function.
    Each evaluation function should accept two parameters: preds, eval_data,
    and return (eval_name, eval_result, is_higher_better) or list of such tuples.

        preds : numpy 1-D array or numpy 2-D array (for multi-class task)
            The predicted values.
            For multi-class task, preds are numpy 2-D array of shape = [n_samples, n_classes].
            If custom objective function is used, predicted values are returned before any transformation,
            e.g. they are raw margin instead of probability of positive class for binary task in this case.
        eval_data : Dataset
            The validation dataset.
        eval_name : str
            The name of evaluation function (without whitespace).
        eval_result : float
            The eval result.
        is_higher_better : bool
            Is eval result higher better, e.g. AUC is ``is_higher_better``.

Returns
-------
result : list
    List with (validation_dataset_name, eval_name, eval_result, is_higher_better) tuples.
r   )r  r6  r  r5  )r{   r  r  r/  s       rC   
eval_validBooster.eval_valid:  s`    D 1d001
1))$*>*>q1u*EqP P 1
 	
 
s   6Ar  r   r  importance_typec                 X   Uc  U R                   n[        U   n[        [        R                  " U R
                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        [        U5      5      5      5        [        U R                  U5        U $ )a  Save Booster to file.

Parameters
----------
filename : str or pathlib.Path
    Filename to save Booster.
num_iteration : int or None, optional (default=None)
    Index of the iteration that should be saved.
    If None, if the best iteration exists, it is saved; otherwise, all iterations are saved.
    If <= 0, all iterations are saved.
start_iteration : int, optional (default=0)
    Start index of the iteration that should be saved.
importance_type : str, optional (default="split")
    What type of feature importance should be saved.
    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.

Returns
-------
self : Booster
    Returns self.
)r0  _FEATURE_IMPORTANCE_TYPE_MAPPERrP   r   LGBM_BoosterSaveModelr  rN   rO   rS   r   r  r  )r{   r  r   r  r  importance_type_ints         rC   
save_modelBooster.save_model`  s    :   //M=oN&&_-]+01s8}%	
 	!!8!8(CrB   end_iterationc           	          [        [        R                  " U R                  [        R
                  " U5      [        R
                  " U5      5      5        U $ )aN  Shuffle models.

Parameters
----------
start_iteration : int, optional (default=0)
    The first iteration that will be shuffled.
end_iteration : int, optional (default=-1)
    The last iteration that will be shuffled.
    If <= 0, means the last available iteration.

Returns
-------
self : Booster
    Booster with shuffled models.
)rP   r   LGBM_BoosterShuffleModelsr  rN   rO   )r{   r  r  s      rC   shuffle_modelsBooster.shuffle_models  s@    ( 	**_-]+	
 rB   c           	      v   [        [        R                  " U R                  5      5        U R	                  5         [
        R                  " 5       U l        [
        R                  " S5      n[        [        R                  " [        U5      [
        R                  " U5      [
        R                  " U R                  5      5      5        [
        R                  " S5      n[        [        R                  " U R                  [
        R                  " U5      5      5        UR                  U l        [        US9U l        U $ )zLoad Booster from a string.

Parameters
----------
model_str : str
    Model will be loaded from this string.

Returns
-------
self : Booster
    Loaded Booster object.
r   rL  )rP   r   r  r  r]  rN   r  rO   rS  rS   rT   r  rU   r9  r  r  )r{   r  r  r  s       rC   r?  Booster.model_from_string  s     	4((67(#\\!_00y!/0T\\*	
 Q**]+	
 )..":Y"OrB   c                 :   Uc  U R                   n[        U   nSn[        R                  " S5      n[        R                  " U5      n[        R
                  " [        R                  " U5      5      n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U5      5        UR                  n	X:  a  [        R                  " U	5      n[        R
                  " [        R                  " U5      5      n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U	5      [        R                  " U5      U5      5        UR                  R                  S5      n
U
[        U R                   5      -  n
U
$ )a  Save Booster to string.

Parameters
----------
num_iteration : int or None, optional (default=None)
    Index of the iteration that should be saved.
    If None, if the best iteration exists, it is saved; otherwise, all iterations are saved.
    If <= 0, all iterations are saved.
start_iteration : int, optional (default=0)
    Start index of the iteration that should be saved.
importance_type : str, optional (default="split")
    What type of feature importance should be saved.
    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.

Returns
-------
str_repr : str
    String representation of Booster.
r`  r   r   )r0  r  rN   r!  ri  r%  r   rP   r   LGBM_BoosterSaveModelToStringr  rO   rT   rU   r   r  r  )r{   r   r  r  r  rm  rn  ro  rp  rq  r   s              rC   rM  Booster.model_to_string  s   4   //M=oN
nnQ'33J?"OOF,<,<],KL.._-]+01z*[)!
	
 !&&
""77
CM &0@0@0O P22LLLL1LL/LL!45NN:.LL-%
 !!((1'(?(?@@
rB   rh  c                    Uc  U R                   n[        U   nSn[        R                  " S5      n[        R                  " U5      n[        R
                  " [        R                  " U5      5      n	[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U	5      5        UR                  n
X:  a  [        R                  " U
5      n[        R
                  " [        R                  " U5      5      n	[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U
5      [        R                  " U5      U	5      5        [        R                  " UR                  R!                  S5      US9n[        R                  " [        R"                  " U R$                  [&        S95      US'   U$ )a  Dump Booster to JSON format.

Parameters
----------
num_iteration : int or None, optional (default=None)
    Index of the iteration that should be dumped.
    If None, if the best iteration exists, it is dumped; otherwise, all iterations are dumped.
    If <= 0, all iterations are dumped.
start_iteration : int, optional (default=0)
    Start index of the iteration that should be dumped.
importance_type : str, optional (default="split")
    What type of feature importance should be dumped.
    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.
object_hook : callable or None, optional (default=None)
    If not None, ``object_hook`` is a function called while parsing the json
    string returned by the C API. It may be used to alter the json, to store
    specific values while building the json structure. It avoids
    walking through the structure again. It saves a significant amount
    of time if the number of trees is huge.
    Signature is ``def object_hook(node: dict) -> dict``.
    None is equivalent to ``lambda node: node``.
    See documentation of ``json.loads()`` for further details.

Returns
-------
json_repr : dict
    JSON format of Booster.
r`  r   r   rg  r  r  )r0  r  rN   r!  ri  r%  r   rP   r   LGBM_BoosterDumpModelr  rO   rT   rU   rk  rl  r   r  r  r1  )r{   r   r  r  rh  r  rm  rn  ro  rp  rq  r   s               rC   r  Booster.dump_model  s   H   //M=oN
nnQ'33J?"OOF,<,<],KL&&_-]+01z*[)!
	
 !&&
""77
CM &0@0@0O P**LLLL1LL/LL!45NN:.LL-%
 jj,,33G<+V$(JJJJ''0%
 ! 
rB   r!  r"  r#  r$  r%  c	                     [         R                  U [        U	5      S9n
Uc  US::  a  U R                  nOSnU
R	                  UUUUUUUUS9$ )a  Make a prediction.

Parameters
----------
data : str, pathlib.Path, numpy array, pandas DataFrame, pyarrow Table, H2O DataTable's Frame (deprecated) or scipy.sparse
    Data source for prediction.
    If str or pathlib.Path, it represents the path to a text file (CSV, TSV, or LibSVM).
start_iteration : int, optional (default=0)
    Start index of the iteration to predict.
    If <= 0, starts from the first iteration.
num_iteration : int or None, optional (default=None)
    Total number of iterations used in the prediction.
    If None, if the best iteration exists and start_iteration <= 0, the best iteration is used;
    otherwise, all iterations from ``start_iteration`` are used (no limits).
    If <= 0, all iterations from ``start_iteration`` are used (no limits).
raw_score : bool, optional (default=False)
    Whether to predict raw scores.
pred_leaf : bool, optional (default=False)
    Whether to predict leaf index.
pred_contrib : bool, optional (default=False)
    Whether to predict feature contributions.

    .. note::

        If you want to get more explanations for your model's predictions using SHAP values,
        like SHAP interaction values,
        you can install the shap package (https://github.com/slundberg/shap).
        Note that unlike the shap package, with ``pred_contrib`` we return a matrix with an extra
        column, where the last column is the expected value.

data_has_header : bool, optional (default=False)
    Whether the data has header.
    Used only if data is str.
validate_features : bool, optional (default=False)
    If True, ensure that the features used to predict match the ones used to train.
    Used only if data is pandas DataFrame.
**kwargs
    Other parameters for the prediction.

Returns
-------
result : numpy array, scipy.sparse or list of scipy.sparse
    Prediction result.
    Can be sparse or a list of sparse objects (each element represents predictions for one class) for feature contributions (when ``pred_contrib=True``).
r  r  r   r  )ri   r  r   r!  r"  r#  r$  r%  )r  r
  r   r0  rG  )r{   ri   r  r   r!  r"  r#  r$  r%  rI  r  s              rC   rG  Booster.predict]  su    r $00#F+ 1 
	  !# $ 3 3 "  +'%+/ ! 	
 		
rB   r  
decay_rater  r  r  r  r  r  r
  r  c                    U R                   (       a  [        S5      eU
c  0 n
[        R                  U [	        U5      S9nUR                  USSUS9nUR                  u  nn[        R                  " S5      n[        [        R                  " U R                  [        R                  " U5      5      5        [        SU R                  SS	9n[!        UR"                  5      US'   UR%                  U
5        ['        UUUUUUUU	UUS
9
nUUS'   [)        UU5      n[        [        R*                  " UR                  UR                  5      5        UR-                  S5      n[/        U5      u  n  n[        [        R0                  " UR                  U[        R2                  " U5      [        R2                  " U5      5      5        U R4                  Ul        U$ )a  Refit the existing Booster by new data.

Parameters
----------
data : str, pathlib.Path, numpy array, pandas DataFrame, H2O DataTable's Frame (deprecated), scipy.sparse, Sequence, list of Sequence or list of numpy array
    Data source for refit.
    If str or pathlib.Path, it represents the path to a text file (CSV, TSV, or LibSVM).
label : list, numpy 1-D array, pandas Series / one-column DataFrame, pyarrow Array or pyarrow ChunkedArray
    Label for refit.
decay_rate : float, optional (default=0.9)
    Decay rate of refit,
    will use ``leaf_output = decay_rate * old_leaf_output + (1.0 - decay_rate) * new_leaf_output`` to refit trees.
reference : Dataset or None, optional (default=None)
    Reference for ``data``.

    .. versionadded:: 4.0.0

weight : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Weight for each ``data`` instance. Weights should be non-negative.

    .. versionadded:: 4.0.0

group : list, numpy 1-D array, pandas Series, pyarrow Array, pyarrow ChunkedArray or None, optional (default=None)
    Group/query size for ``data``.
    Only used in the learning-to-rank task.
    sum(group) = n_samples.
    For example, if you have a 100-document dataset with ``group = [10, 20, 40, 10, 10, 10]``, that means that you have 6 groups,
    where the first 10 records are in the first group, records 11-30 are in the second group, records 31-70 are in the third group, etc.

    .. versionadded:: 4.0.0

init_score : list, list of lists (for multi-class task), numpy array, pandas Series, pandas DataFrame (for multi-class task), pyarrow Array, pyarrow ChunkedArray, pyarrow Table (for multi-class task) or None, optional (default=None)
    Init score for ``data``.

    .. versionadded:: 4.0.0

feature_name : list of str, or 'auto', optional (default="auto")
    Feature names for ``data``.
    If 'auto' and data is pandas DataFrame, data columns names are used.

    .. versionadded:: 4.0.0

categorical_feature : list of str or int, or 'auto', optional (default="auto")
    Categorical features for ``data``.
    If list of int, interpreted as indices.
    If list of str, interpreted as feature names (need to specify ``feature_name`` as well).
    If 'auto' and data is pandas DataFrame, pandas unordered categorical columns are used.
    All values in categorical features will be cast to int32 and thus should be less than int32 max value (2147483647).
    Large values could be memory consuming. Consider using consecutive integers starting from zero.
    All negative values in categorical features will be treated as missing values.
    The output cannot be monotonically constrained with respect to a categorical feature.
    Floating point numbers in categorical features will be rounded towards 0.

    .. versionadded:: 4.0.0

dataset_params : dict or None, optional (default=None)
    Other parameters for Dataset ``data``.

    .. versionadded:: 4.0.0

free_raw_data : bool, optional (default=True)
    If True, raw data is freed after constructing inner Dataset for ``data``.

    .. versionadded:: 4.0.0

validate_features : bool, optional (default=False)
    If True, ensure that the features used to refit the model match the original ones.
    Used only if data is pandas DataFrame.

    .. versionadded:: 4.0.0

**kwargs
    Other parameters for refit.
    These parameters will be passed to ``predict`` method.

Returns
-------
result : Booster
    Refitted Booster.
z,Cannot refit due to null objective function.Nr  r  T)ri   r  r"  r%  r   r   r%  )
ri   r  r  r  r  r  r  r  rL   r  refit_decay_rate)r/  r/   r  r
  r   rG  r   rN   rO   rP   r   LGBM_BoosterGetLinearr  rT   r  rL   r  rU   rw  r-   r,   r8  r@  r  LGBM_BoosterRefitrR   r,  )r{   ri   r  r  r  r  r  r  r  r  r
  r  r%  rI  r  
leaf_predsrD  r  out_is_linear
new_paramsr   new_boosterr  rW  s                           rC   refitBooster.refit  s   @ '' NOO!N#00hW]N^0_	!*!2!2/	 "3 "

  %%
dQ&&]+	
 ));;


 %))<)<$=
=!.)!% 3'
	 *4
%&j)4""##!!	
  ''+
%j1!Q""##t$t$		
  $}}rB   tree_idleaf_idc           
         [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      [         R                  " U5      [         R                  " U5      5      5        UR                  $ )zGet the output of a leaf.

Parameters
----------
tree_id : int
    The index of the tree.
leaf_id : int
    The index of the leaf in the tree.

Returns
-------
result : float
    The output of the leaf.
r   )	rN   r  rP   r   LGBM_BoosterGetLeafValuer  rO   rT   rU   )r{   r  r  r   s       rC   get_leaf_outputBooster.get_leaf_outputF  s_     ooa ))W%W%S!		
 yyrB   rU   c           
          [        [        R                  " U R                  [        R
                  " U5      [        R
                  " U5      [        R                  " U5      5      5        U $ )a(  Set the output of a leaf.

.. versionadded:: 4.0.0

Parameters
----------
tree_id : int
    The index of the tree.
leaf_id : int
    The index of the leaf in the tree.
value : float
    Value to set as the output of the leaf.

Returns
-------
self : Booster
    Booster with the leaf output set.
)rP   r   LGBM_BoosterSetLeafValuer  rN   rO   r  )r{   r  r  rU   s       rC   set_leaf_outputBooster.set_leaf_output`  sL    0 	))W%W%&		
 rB   c                     [         R                  " S5      n[        [        R                  " U R
                  [         R                  " U5      5      5        UR                  $ )zWGet number of features.

Returns
-------
num_feature : int
    The number of features.
r   )rN   rO   rP   r   LGBM_BoosterGetNumFeaturer  rT   rU   )r{   out_num_features     rC   r  Booster.num_feature  sH     !,,q/**_-	
 $$$rB   c                    U R                  5       n[        R                  " S5      nSn[        R                  " S5      n[	        U5       Vs/ s H  n[        R
                  " U5      PM     nn[        R                  U-  " [        [        R                  U5      6 n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U5      5        XR                  :w  a  [        S5      eUR                  nX8:  a  [	        U5       Vs/ s H  n[        R
                  " U5      PM     nn[        R                  U-  " [        [        R                  U5      6 n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U5      5        [	        U5       V	s/ s H   oU	   R                  R!                  S5      PM"     sn	$ s  snf s  snf s  sn	f )z^Get names of features.

Returns
-------
result : list of str
    List with names of features.
r   r  r  r   )r  rN   rO   r  r  ri  r%  rB  r   rP   r   LGBM_BoosterGetFeatureNamesr  rT   rU   r   r   r  s
             rC   r  Booster.feature_name  s    &&(ll1o&)#&,ooa&8#\abm\no\nWX&556QR\no$oo;c&BRBRTb>cd,,[)[) ;<89"		
 +++UVV$?$E$E!&B^cdo^pq^pYZf99:ST^pNq"(//K"?#fFVFVXfBg!h00LLLL-LL-OO$=>LL!<=&	 BG{ASTASAq!''..w7ASTT; p" r Us    I I-'I!	iterationc                    Uc  U R                   n[        U   n[        R                  " U R	                  5       [        R
                  S9n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      UR                  R                  [        R                  " [        R                  5      5      5      5        U[        :X  a  UR!                  [        R"                  5      $ U$ )ai  Get feature importances.

Parameters
----------
importance_type : str, optional (default="split")
    How the importance is calculated.
    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.
iteration : int or None, optional (default=None)
    Limit number of iterations in the feature importance calculation.
    If None, if the best iteration exists, it is used; otherwise, all trees are used.
    If <= 0, all trees are used (no limits).

Returns
-------
result : numpy array
    Array with feature importances.
r   )r0  r  r`   rT  r  rb   rP   r   LGBM_BoosterFeatureImportancer  rN   rO   r  r  r  _C_API_FEATURE_IMPORTANCE_SPLITr   r  )r{   r  r  r  results        rC   feature_importanceBooster.feature_importance  s    . ++I=oN$**,BJJ?..Y'01%%fnnV__&EF		
 "AA==**MrB   r  binsxgboost_stylec                 8  ^^^^ S[         [        [        4   SS4UUUU4S jjmU R                  5       nUR	                  S5      mUS   n/ mU H  nT" US   5        M     Ub  [        U[        5      (       a@  U(       a9  [        [        R                  " T5      5      n[        Ub  [        Xr5      OUS5      n[        R                  " TUS	9u  pU(       aB  [        R                  " U	SS U45      n
XSS2S4   S
:     n
[        (       a  [        U
SS/S9$ U
$ X4$ )a\  Get split value histogram for the specified feature.

Parameters
----------
feature : int or str
    The feature name or index the histogram is calculated for.
    If int, interpreted as index.
    If str, interpreted as name.

    .. warning::

        Categorical features are not supported.

bins : int, str or None, optional (default=None)
    The maximum number of bins.
    If None, or int and > number of unique split values and ``xgboost_style=True``,
    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.
xgboost_style : bool, optional (default=False)
    Whether the returned result should be in the same form as it is in XGBoost.
    If False, the returned value is tuple of 2 numpy arrays as it is in ``numpy.histogram()`` function.
    If True, the returned value is matrix, in which the first column is the right edges of non-empty bins
    and the second one is the histogram values.

Returns
-------
result_tuple : tuple of 2 numpy arrays
    If ``xgboost_style=False``, the values of the histogram of used splitting values for the specified feature
    and the bin edges.
result_array_like : numpy array or pandas DataFrame (if pandas is installed)
    If ``xgboost_style=True``, the histogram of used splitting values for the specified feature.
rootrE   Nc                   > SU ;   az  Tb  [        T[        5      (       a	  TU S      nOU S   nUT:X  a7  [        U S   [        5      (       a  [        S5      eTR                  U S   5        T" U S   5        T" U S   5        gg)zRecursively add thresholds.rh  Nr}  r  z@Cannot compute split value histogram for the categorical featurer  r  )r   r   r/   r   )r)  r}  r'  r  rn  r  s     rC   r'  .Booster.get_split_value_histogram.<locals>.add  s    $ ,GS1I1I$1$2G$HM$($9M G+!${"3S99+,nood;&78D&'D'( %rB   rn  r  r  r   )r&  r   
SplitValueCountr  )r   r   r   r  rz  r   r   r   r`   r  r  rW  	histogramcolumn_stackr   r(   )r{   r  r&  r'  model
tree_infosr  n_uniquehist	bin_edgesr   r'  rn  r  s    `         @@@rC   get_split_value_histogram!Booster.get_split_value_histogram  s   N	)d38n 	) 	) 	) !		/2;'
 #I	*+, $ <:dC00]299V,-Hd.>s8*HaPD,,vD9//9QR=$"78C!Q$i!m$C#C,1HII
?"rB   	data_namer  c                 d   X R                   :  a  [        S5      eU R                  5         / nU R                  S:  GaC  [        R
                  " U R                  [        R                  S9n[        R                  " S5      n[        [        R                  " U R                  [        R                  " U5      [        R                  " U5      UR                  R                  [        R                  " [        R                   5      5      5      5        UR"                  U R                  :w  a  [        S5      e[%        U R                  5       H3  nUR'                  XR(                  U   XW   U R*                  U   45        M5     [-        U5      (       a  U/nUb  US:X  a  U R.                  nOU R0                  US-
     nU Hn  n	U	c  M  U	" U R3                  U5      U5      n
[5        U
[6        5      (       a!  U
 H  u  pnUR'                  XX45        M     MV  U
u  pnUR'                  XX45        Mp     U$ )z%Evaluate training or validation data.1Data_idx should be smaller than number of datasetr   r   zWrong length of eval resultsr   )r6  r   r<  _Booster__num_inner_evalr`   rT  rb   rN   rO   rP   r   LGBM_BoosterGetEvalr  rT   r  r  r  rU   r  r   _Booster__name_inner_eval"_Booster__higher_better_inner_evalr   r   r4  r  r   r   )r{   r7  r  r  r   r#  rn  r  cur_dataeval_function	feval_ret	eval_namer5  is_higher_betters                 rC   __inner_evalBooster.__inner_eval2  s    )))PQQ  1$XXd332::FF ,,q/K((LLLL*LL-MM))&..*IJ	   D$9$99 !?@@4001

I'='=a'@&)TMlMlmnMopq 2E??GE1}>>??8a<8!& ()$*>*>x*H(S	i..<E8	(8

I##PQ =F 8A4I$4JJ	cLM "' 
rB   c           	      *   XR                   :  a  [        S5      eU R                  U   c  US:X  a(  U R                  R	                  5       U R
                  -  nO-U R                  US-
     R	                  5       U R
                  -  n[        R                  " U[        R                  S9U R                  U'   U R                  U   (       d  [        R                  " S5      nU R                  U   R                  R                  [        R                  " [        R                  5      5      n[!        ["        R$                  " U R&                  [        R(                  " U5      [        R*                  " U5      U5      5        UR,                  [/        U R                  U   5      :w  a  [        SU 35      eSU R                  U'   U R                  U   nU R
                  S:  a3  UR0                  U R
                  -  nUR3                  X`R
                  SS9nU$ )	z,Predict for training and validation dataset.r9  r   r   r   z)Wrong length of predict results for data Tr[   r_   )r6  r   r:  r   r  r9  r4  r`   rT  rb   r;  rN   r!  r  r  r  rP   r   LGBM_BoosterGetPredictr  rO   rT   rU   r   r?  r@  )r{   r  rL  rn  r  r#  r  s          rC   __inner_predictBooster.__inner_predict_  s   )))PQQ&&x081}..113d6F6FF//(Q,7@@BTEUEUU46HHWBJJ4WD''1++H5 ..+K228<CCKKFNN[a[j[jLklH++LLLL*LL-	   C(C(CH(M$NN #LXJ!WXX59D((2!88Ba{{d&6&66H^^H.>.>c^JFrB   c                    U R                   (       GaK  SU l         [        R                  " S5      n[        [        R
                  " U R                  [        R                  " U5      5      5        UR                  U l	        U R                  S:  Ga  [        R                  " S5      nSn[        R                  " S5      n[        U R                  5       Vs/ s H  n[        R                  " U5      PM     nn[        R                  U R                  -  " [        [        R                  U5      6 n[        [        R                   " U R                  [        R                  " U R                  5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U5      5        U R                  UR                  :w  a  [#        S5      eUR                  nX8:  a  [        U R                  5       Vs/ s H  n[        R                  " U5      PM     nn[        R                  U R                  -  " [        [        R                  U5      6 n[        [        R                   " U R                  [        R                  " U R                  5      [        R                  " U5      [        R                  " U5      [        R                  " U5      U5      5        [        U R                  5       V	s/ s H   oU	   R                  R%                  S5      PM"     sn	U l        U R&                   V
s/ s H  oR)                  S5      PM     sn
U l        gggs  snf s  snf s  sn	f s  sn
f )z%Get inner evaluation count and names.Fr   r  z1Length of eval names doesn't equal with num_evalsr   )auczndcg@zmap@average_precisionN)r-  rN   rO   rP   r   LGBM_BoosterGetEvalCountsr  rT   rU   r:  r  r  ri  r%  rB  r   LGBM_BoosterGetEvalNamesr   r   r<  r  r=  )r{   out_num_evalrn  r  r  rW  r  r  r  r  r   s              rC   __get_eval_infoBooster.__get_eval_info~  s   '''+0D(!<<?L..LLLL. %1$6$6D!$$q($ll1o.1+.4ooa.@+V[\`\q\qVr"VrQRF//0KLVr  " '-oo8M8M&MPSTZTdTdftPu%v"11T%:%:;[1(CD%@A*	 ((K,=,==$%XYY,G,M,M).JX]^b^s^sXt&XtST334MNXt # & +1//D<Q<Q*QV--~>*& 55 LL"LL)>)>?"LL5"OO,EF"LL)DE.	 \aaeavav[w)x[wVW*;*A*A*H*H*Q[w)x&_c_u_u3_uW[OO$QR_u3/S ) ( "&&  *y3s    M M$='M):M.)__higher_better_inner_eval__init_predictor__inner_predict_buffer__is_predicted_cur_iter__name_inner_eval__need_reload_eval_info__num_class__num_dataset__num_inner_eval__set_objective_to_noner  r,  r.  r0  r1  r5  r  rL   r   r=  r4  )NNNNr  )rE   r,   )r(  r*  r   NNrG   )Nr   r  )r   r  )Nr   r  N)r   NFFFFF)
g?NNNNr  r  NTF)r  N)NF)Or<   r=   r>   r?   r@   r   r   r   r   r-   r   r   r   r  rG  rF  r  rT  r>  rZ  r]  r   r   r   r2  rC  r(   r  r  r  r  _LGBM_CustomObjectiveFunctionr  rw  r`   r   r  r  r  r  r  r   r  r  _LGBM_CustomEvalFunction!_LGBM_BoosterEvalMethodResultTyper  r  r  r  r  r?  rM  r   r  r  r5  r6  r>  rG  r  r  r  r  r  r  r  r  r  r  r  r  r$  r   r5  r  r  r<  rA   r:   rB   rC   r,   r,     s<    ,0'+15#'Ec3h(E G$E U39-.	E
 C=EN
',# , , ,d38n $$sCx. $T $?4S> ?8 "'"$S	3s8S01$ $ 	$
 $ 
$L
[FL [Fz 	  g S Y @d38n  4 (,8<J,G$J, 45J, 
	J,X6&jj6& jj6& 
	6&p
"3 ""$ $"3 "U "U * \`	5858 58 6=U8VVWX	58
 
/	058r \` B6=U8VVWX B 
/	0 BH \`$
6=U8VVWX$
 
/	0$
R (, &*T	"*  }* 	*
 * 
*\  !  
	:#3 #9 #N (, &	>}> > 	>
 
>D (, &LPM}M M 	M
 hS#X'7c3h'GHIM 
c3hMd  !'+" %"'K
#K
 K
  }	K

 K
 K
 K
 K
  K
 K
 
rzz5<<00$u||7L7L2MM	NK
b  '+-1+/487=EK37""'Z!Z Z 	Z
 G$Z )*Z (Z 01Z 5Z CZ !c3h0Z Z  Z Z 
Zxs S U 4     	 
 
 D%S %"*Ud3i *U\  '#'&& C=& 
	&V +/#	I#sCxI# uS#X'I# 	I#
 
uRZZ+,bjj,F	GI#V++ + 6=U8VVWX	+
 
/	0+Z 

 >8rB   r,   )r|   r   r  rG   r[  )r@   libpathr   r  rN   r"  rk  r   collectionsr   r   r   enumr   	functoolsr   osr	   r
   os.pathr   pathlibr   tempfiler   typingr   r   r   r   r   r   r   r   r   r   r   numpyr`   scipy.sparser5  compatr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   ImportErrortyping_extensions__all__r  r  r  _ctypes_int_ptr_ctypes_int_array_ctypes_float_ptr_ctypes_float_arrayr   r   r  _LGBM_EvalFunctionResultType_LGBM_BoosterBestScoreTyper^  6_LGBM_BoosterEvalMethodResultWithStandardDeviationTyper   r  r  r   r  r  r  r6  r>  r  r  r  r  r  rH   _MULTICLASS_OBJECTIVESr  r/   rJ   rW   rj   rl   ru   r   r   r   r   r   r0   r   r   r   r   bytesr   rz  r%  r   restype	CFUNCTYPEcallbackLGBM_RegisterLogCallbackr   rC  rP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r  r"  rS   r   Arrayr*  r1  r;  rF  rH  FutureWarningr.   r\  r^  r  rJ  r  r  r  r  rd   re   r/  r0  r1  r2  r  r  r"  _C_API_FEATURE_IMPORTANCE_GAINr  r  r  r  r  r  r   r  r  r  r  ABCr1   r  r-   r\  r]  r,   r:   rB   rC   <module>r     s)   $  
     #        ' l l l l      ( 0$
 ' 5  (  6   %S%%56 !#tCJ'7"78 $)#sE4*?$@ !9>sCPTV[?[9\ 6(-d3icDU.U(V %!&tCy2C'C!D KIJJ JJ  KeJJ	  JJ	LL	  KIJJ JJ	LL  KIJJ  ecOKIJJ	  c 	I 	2 2$ 2	# 	s 	s 	+rzz +eBJJO&< +"4 ) ) ~    8 8# 8$ 8 #(/// / 
	/28SE4K#8 XseTk=R "-3 -4 -0c 0d 0 -S -T - -*u * * {{'//%+__D"foo6H]+DM$$T]]3q8D224;;GDEE ud#	FC 	FD 	FS T AS AT A
- - -1bjj 19N 1SUS]S] 1Ic Id I
S3 S+H SQ Q(C QxC xD x



 
 
 ZZ	
.WS WT W
Mc Md M
[C [D [
9C 9$Q 9
&C &D &
> >.5X 5, 58
   ZZ	&5&7 5 5 56&7 6 6 65$5 5s 5rzz 55$5 5s 5rzz 533 36?? 3
*D *$s) * *
# # %UC-. 3 Xd38n5 #   	] 	F: :z, ,d38n ,UX ,]abegjbj]k ,^ 
 8     .   >     ,   1"# !"  !"&"  8,*# 	bjj 	RZZ 	' '.?bjj.P(Q '*'rzz 'eOS"**,L&M '*x4 xD x
	
y 	
T 	
B
B'B ZZB"-
-0- ?- !d,	-
 2::tCy%S	49(<"=tDzIJ-d -1	 d,	c4i()	 		 -1#c4i()} d4j8?_sww ?_DL" L"^K K\8 !)ZZ	"**bjj
 !#!  !	W$	& 	W)*	,		 t tWn  0//0s   &\ \$#\$