
    +^i                        U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%Z&ddl'Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: erddlm;Z; 	 ddlm<Z< g dZ?ej                  ZAej                  ZBe$d   ZCe$d   ZDe$d   ZEe$d   ZFe#eGeHeIf   ZJeeGeeGeHf   f   ZKe#eGeGeHeIf   ZLe#eGeGeHeIeHf   ZMe$e eG   e eN   df   ZOe$e eG   df   ZPe$e eH   e eN   e&j                  e:e3e5f   ZRe$e&j                  e:f   ZSe$e eH   e e eH      e&j                  e:e9e7e3e5f   ZTe$eGee&j                  e9e2e(j                  j                  de d   e e&j                     e7f
   ZWe$e eH   e eN   e&j                  e:e9e3e5f   ZXe$eGee&j                  e9e2e(j                  j                  e7f   ZYe$e eH   e eN   e&j                  e:e3e5f   ZZe$e e eH      e e eN      e eH   e eN   e&j                  e:e9e7e3e5f
   Z[dZ\h dZ] G d de^      Z_deHdeIfdZ`deNd eGdeNfd!Zad"e&j                  de#e&j                  eNf   fd#Zb G d$ d%e      Zc G d& d'      Zd ed       aeeefd(<   d)agd*ahd+ed,eGdeIfd-Zi	 	 dd+ed.eGd/eGddfd0Zjd1eeGgdf   deeGgdf   fd2Zkd3eGddfd4Zld3eGddfd5Zmekd3eGddfd6       Znd3eoddfd7Zp ej                  d8d9      sej                  ej                  _t         ej                  dej                        Zv evep      e_v         ej                  ej                        dk7  r& e_ ej                         j                  d:            eNeHeIfZyd;eNddfd<Zzd=edeIfd>Z{d?edeIfd@Z|d?edeIfdAZ}dBe&j                  dCdDde&j                  fdEZ~d?edeIfdFZd?eddGfdHZd?eddIfdJZd?edeIfdKZd?edCdDdLeGde&j                  fdMZd?edeIfdNZd?edeIfdOZd?edeIfdPZd?eddQfdRZd?edeIfdSZ G dT dU      Zd?e7defdVZd?edCdDdLeGde&j                  fdWZdXdYdZeNde&j                  fd[ZdXdYdZeNde&j                  fd\ZdXdYdZeNde&j                  fd]ZdXdYdZeNde&j                  fd^Zd_eGdej                  fd`Zdaedbe e   dej$                  fdcZd=edefddZde$eNeHeGe f   deGfdeZd?e!eeGef      deGfdfZ G dg dh      Z G di dje      ZddkZ G dl dm      ZdneGd eeGef   doedeeGef   fdpZdqZ	 dZdZdrZdsZ	 dZdZ	 dZdZdrZdsZ	 dZdZ	 dZdZ	 eeeeedtZ	 eeduZd?e&j                  de&j                  fdvZd?e&j                  de#eEeNe&j                  f   fdwZd?e&j                  de#eCeNe&j                  f   fdxZdCedeIfdyZdze:ddfd{Zd?e9d|dDde&j                  fd}Zd?e9d~ePdeOde!e e       de#e&j                  e eG   e$e eG   e eN   f   e e    f   f
dZ	 dde!e e       de!e$eGef      deGfdZ	 	 dde!e$eGef      de!eG   de!e e       fdZ G d dejn                        Z G d d      Z G d d      Zee&j                  ege#e&j                  e&j                  f   f   Ze$ee&j                  egeJf   ee&j                  ege eJ   f   f   Z G d d      Zy# e=$ r
 ddl>m<Z< Y >w xY w)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                       e Zd ZdZy)r/   zError thrown by LightGBM.N__name__
__module____qualname____doc__     O/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/lightgbm/basic.pyr/   r/      s    #r?   r/   xreturnc                 4    t          | cxk  xr	 t         k  S c S N)ZERO_THRESHOLDrA   s    r@   _is_zerorG      s    ?a1>1111r?   
total_nrowparamsc           	          t        j                  d      }t        t        j                  t        j
                  |       t        |      t        j                  |                   |j                  S )Nr   )	ctypesc_int
_safe_callr   LGBM_GetSampleCountc_int32_c_strbyrefvalue)rH   rI   
sample_cnts      r@   _get_sample_countrT      sR    aJ  NN:&6NLL$	
 r?   matc                 ,   | j                   t        j                  t        j                  fv r| j                   }nt        j                  }| j                  d   r	d}t
        }nd}t        }t        j                  | ||      }|j                  |      |fS )NF_CONTIGUOUSFC)dtypeorderr[   )	rZ   npfloat32float64flags_C_API_IS_COL_MAJOR_C_API_IS_ROW_MAJORasarrayravel)rU   rZ   r[   layoutdatas        r@   _np2d_to_np1drg      su    
yyRZZ,,		


yy $$::ce4D::E:"F**r?   c                       e Zd ZdZdZdZy)_MissingTypeNoneNaNZeroN)r:   r;   r<   NONENANZEROr>   r?   r@   ri   ri      s    D
CDr?   ri   c                   ,    e Zd ZdeddfdZdeddfdZy)_DummyLoggermsgrB   Nc                     t        |       y rD   )printselfrr   s     r@   infoz_DummyLogger.info   s	    c
r?   c                 2    t        j                  |d       y )N   )
stacklevel)warningswarnru   s     r@   warningz_DummyLogger.warning   s    ca(r?   )r:   r;   r<   strrw   r}   r>   r?   r@   rq   rq      s(      )3 )4 )r?   rq   _LOGGERrw   r}   loggermethod_namec                 .    t        t        | |d             S rD   )callablegetattr)r   r   s     r@   _has_methodr      s    GFK677r?   info_method_namewarning_method_namec                 d    t        | |      rt        | |      st        d| d| d      | a|a|ay)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      r@   r0   r0      sL      v/0FL_8`/0@/AI\H]]efgg G(.r?   funcc                 H     g t               dt        ddf fd       }|S )z;Join log messages from native library which come by chunks.rr   rB   Nc                     | j                         dk(  rdj                        } g  |       S j                  |        y )N )stripjoinappend)rr   r   msg_normalizeds    r@   wrapperz)_normalize_native_string.<locals>.wrapper  s>     99;"''.)CN9!!#&r?   )r   r~   )r   r   r   s   ` @r@   _normalize_native_stringr     s3     "N
4['S 'T ' ' Nr?   rr   c                 8     t        t        t              |        y rD   r   r   r   rr   s    r@   	_log_infor     s    'GG&',r?   c                 8     t        t        t              |        y rD   )r   r   r   r   s    r@   _log_warningr     s    *GG)*3/r?   c                 8     t        t        t              |        y rD   r   r   s    r@   _log_nativer     s    'GG&',r?   c                 J    t        t        | j                  d                   y)z.Redirect logs from native library into Python.utf-8N)r   r~   decoder   s    r@   _log_callbackr     s    CJJw'()r?   LIGHTGBM_BUILD_DOCFr   retc                 f    | dk7  r,t        t        j                         j                  d            y)zCheck 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    r@   rM   rM   0  s/     axD224;;GDEE r?   objc                 F    	 t        |        y# t        t        f$ r Y yw xY w)zCCheck whether object is a number or not, include numpy number, etc.TF)floatr   
ValueErrorr   s    r@   _is_numericr   <  s*    c
z"  s      rf   c                 j    t        | t        j                        xr t        | j                        dk(  S )z(Check whether data is a numpy 1-D array.r   
isinstancer]   ndarraylenshaperf   s    r@   _is_numpy_1d_arrayr   G  s%    dBJJ'@C

Oq,@@r?   c                     t        | t        j                        sy| j                  }t	        |      dk(  xr |d   dk(  S )z+Check whether data is a column numpy array.F   r   )r   r]   r   r   r   )rf   r   s     r@   _is_numpy_column_arrayr   L  s7    dBJJ'JJEu:?,uQx1},r?   arrayrZ   znp.typing.DTypeLikec                 J    | j                   |k(  r| S | j                  |d      S )z Cast numpy array to given dtype.FrZ   copy)rZ   astype)r   rZ   s     r@   _cast_numpy_array_to_dtyper   T  s&    {{e<<e%<00r?   c                 L    t        | t              xr |  xs t        | d         S )z!Check whether data is a 1-D list.r   )r   listr   r   s    r@   _is_1d_listr   [  s$    dD!H4x'G;tAw3GHr?   zTypeGuard[List[np.ndarray]]c                 J    t        | t              xr t        d | D              S )Nc              3   P   K   | ]  }t        |t        j                           y wrD   )r   r]   r   .0rA   s     r@   	<genexpr>z+_is_list_of_numpy_arrays.<locals>.<genexpr>a  s     )R*Q

*C)Rs   $&r   r   allr   s    r@   _is_list_of_numpy_arraysr   `  s    dD!Rc)RT)R&RRr?   zTypeGuard[List[Sequence]]c                 J    t        | t              xr t        d | D              S )Nc              3   <   K   | ]  }t        |t                y wrD   )r   r1   r   s     r@   r   z(_is_list_of_sequences.<locals>.<genexpr>e  s     )Pa*Q*A)Ps   r   r   s    r@   _is_list_of_sequencesr   d  s    dD!Pc)P4)P&PPr?   c                 p    t        |       xs* t        |       xs t        |       xs t        | t              S )z'Check whether data is a 1-D collection.)r   r   r   r   r)   r   s    r@   _is_1d_collectionr   h  s2    d#w'=d'Cw{SWGXw\fgkmv\wwr?   namec                    t        |       rt        | |      S t        |       r't        d       | j	                         }t        ||      S t        |       rt        j                  | |      S t        | t              r:t        | j                         j                         t        j                  | |      S t        dt        |       j                   d| d      )z Convert data to numpy 1-D array.z$Converting column-vector to 1d arrayrZ   Wrong type() for z5.
It should be list, numpy 1-D array or pandas Series)r   r   r   r   rd   r   r]   rc   r   r)   _check_for_bad_pandas_dtypesto_framedtypesr   typer:   )rf   rZ   r   r   s       r@   _list_to_1d_numpyr   m  s     $)$66		%;<

)%77	T	zz$e,,	D)	$$T]]_%;%;<zz$e,,$t*--.fTF:pq
 	
r?   c                     t        | t        j                        xr, t        | j                        dk(  xr | j                  d   dkD  S )z(Check whether data is a numpy 2-D array.r   r   r   r   s    r@   _is_numpy_2d_arrayr     s9    dBJJ'VC

Oq,@VTZZPQ]UVEVVr?   c                 b    t        | t              xr t        |       dkD  xr t        | d         S )z!Check whether data is a 2-D list.r   )r   r   r   r   r   s    r@   _is_2d_listr     s*    dD!Lc$i!mLDG8LLr?   c                 V    t        |       xs t        |       xs t        | t              S )z'Check whether data is a 2-D collection.)r   r   r   r(   r   s    r@   _is_2d_collectionr     s#    d#Z{4'8ZJt\<ZZr?   z+TypeGuard[Union[pa_Array, pa_ChunkedArray]]c                 .    t        | t        t        f      S )z&Check whether data is a PyArrow array.)r   r"   r$   r   s    r@   _is_pyarrow_arrayr     s    dX788r?   c                 "    t        | t              S )z&Check whether data is a PyArrow table.)r   r&   r   s    r@   _is_pyarrow_tabler     s    dH%%r?   c                       e Zd ZU dZeed<   ej                  ed<   ej                  ed<   dedej                  dej                  fdZe	defd       Z
e	defd       Zy	)
_ArrowCArrayz<Simple wrapper around the C representation of an Arrow type.n_chunkschunksschemac                 .    || _         || _        || _        y rD   )r   r   r   )rv   r   r   r   s       r@   __init__z_ArrowCArray.__init__  s     r?   rB   c           	          t        t        j                  dt        j                  | j                  d                     S )zMReturns the address of the pointer to the list of chunks making up the array.	uintptr_tr   )intr   cast	addressofr   rv   s    r@   
chunks_ptrz_ArrowCArray.chunks_ptr  s.     :??;
0D0DT[[QR^0TUVVr?   c                 T    t        t        j                  d| j                              S )z>Returns the address of the pointer to the schema of the array.r   )r   r   r   r   r   s    r@   
schema_ptrz_ArrowCArray.schema_ptr  s     :??;<==r?   N)r:   r;   r<   r=   r   __annotations__r   CDatar   propertyr   r   r>   r?   r@   r   r     s    FM j.>.> 
HXHX 
 WC W W >C > >r?   r   c           
         t        | t              r| g}nVt        | t              r| j                  }n9t        | t              r| j                         }nt        dt        |        d      t        j                  dt        |            }t        j                  d      }t        |      D ]  \  }}t        t        j                  dt        j                  ||                     }|dk(  r2t        t        j                  d|            }|j                  ||       r|j                  |        t!        t        |      ||      S )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   )rf   export_objectsr   r   ir   	chunk_ptrr   s           r@   _export_arrow_to_cr     s    $!	D/	*	D(	#*>$t*5RSTT ^^13~3FGF^^12F N+ (3
Z5I5I&QR)5TUV	6Z__[&ABJY
3Y'( FVV44r?   c                 4   t        |       rt        | |      S t        |       rt        j                  | |      S t        | t              r+t        | j                         t        | j                  |      S t        dt        |       j                   d| d      )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:   )rf   rZ   r   s      r@   _data_to_2d_numpyr     s     $)$664xxE**$%$T[[1)$++u==

d4j))*& 7J 	J r?   cptrctypes._Pointerlengthc                     t        | t        j                  t        j                              r0t        j
                  j                  | |f      j                         S t        d      )z6Convert a ctypes float pointer array to a numpy array.r   zExpected float pointer)	r   rK   POINTERc_floatr]   	ctypeslibas_arrayr   RuntimeErrorr   r  s     r@   _cfloat32_array_to_numpyr    J    $v~~67||$$T&$;@@BB344r?   c                     t        | t        j                  t        j                              r0t        j
                  j                  | |f      j                         S t        d      )z7Convert a ctypes double pointer array to a numpy array.r  zExpected double pointer)	r   rK   r  c_doubler]   r  r  r   r	  r
  s     r@   _cfloat64_array_to_numpyr    sJ    $v78||$$T&$;@@BB455r?   c                     t        | t        j                  t        j                              r0t        j
                  j                  | |f      j                         S t        d      )4Convert a ctypes int pointer array to a numpy array.r  zExpected int32 pointer)	r   rK   r  rO   r]   r  r  r   r	  r
  s     r@   _cint32_array_to_numpyr    r  r?   c                     t        | t        j                  t        j                              r0t        j
                  j                  | |f      j                         S t        d      )r  r  zExpected int64 pointer)	r   rK   r  c_int64r]   r  r  r   r	  r
  s     r@   _cint64_array_to_numpyr    r  r?   stringc                 J    t        j                  | j                  d            S )z$Convert a Python string to C string.r   )rK   c_char_pencode)r  s    r@   rP   rP     s    ??6==122r?   ctyper   c                 $     | t        |      z  | S )z"Convert a Python array to C array.r   )r  r   s     r@   _c_arrayr    s    ECK&))r?   c                     t        | t        j                  t        j                  t        j                  f      r| j                         S t        | t        j                        r| j                         S | S )z3Convert numpy classes to JSON serializable objects.)r   r]   integerfloatingbool_itemr   tolistr   s    r@   _json_default_with_numpyr$    sJ    #

BKK:;xxz	C	$zz|
r?   c                 t    t        | t              rdj                  d | D              }d| dS t        |       S )N,c              3   2   K   | ]  }t        |        y wrD   )r~   )r   vals     r@   r   z_to_string.<locals>.<genexpr>  s     2CH2   [])r   r   r   r~   )rA   val_lists     r@   
_to_stringr-    s7    !T882228*A1vr?   c                    | | syg }| j                         D ]  \  }}t        |t        t        t        f      st        |      r4|j                  | ddj                  t        t        |                    `t        |t        t        t        f      st        |      r|j                  | d|        |t        d| dt        |      j                           dj                  |      S )z>Convert Python dictionary to string, which is passed to C API.r   =r&  zUnknown type of parameter:z, got: )itemsr   r   tuplesetr   r   r   mapr-  r~   r   _NUMERIC_TYPESr   r   r   r:   )rf   pairskeyr(  s       r@   _param_dict_to_strr8    s    |4EJJL ZScD%-.2DS2ILLC5#((3z3+?"@!ABCc489[=MLLC5#(_8VDIDVDVCWXYYZ 88E?r?   c                   0    e Zd ZdZd	dZdedededdfdZy)
	_TempFilez,Proxy class to workaround errors on Windows.rB   c                     t        dd      5 }|j                  | _        t        | j                        | _        d d d        | S # 1 sw Y   | S xY w)Nlightgbm_tmp_T)prefixdelete)r   r   r   path)rv   fs     r@   	__enter__z_TempFile.__enter__1  sF    tD 	(DITYYDI	( 	( s   ,AAexc_typeexc_valexc_tbNc                 n    | j                   j                         r| j                   j                          y y rD   )r?  is_fileunlink)rv   rB  rC  rD  s       r@   __exit__z_TempFile.__exit__7  s'    99II r?   )rB   r:  )r:   r;   r<   r=   rA  r   rH  r>   r?   r@   r:  r:  .  s+    6 s C D r?   r:  c                       e Zd ZdZy)r.   zCustom deprecation warning.Nr9   r>   r?   r@   r.   r.   >  s    %r?   r.   c                  @    d} t        j                  | t        d       y )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   )categoryrz   )r{   r|   r.   r   s    r@   #_emit_datatable_deprecation_warningrL  D  s    	6 
 MM# 61Er?   c                       e Zd ZdZedeeee   f   fd       Ze	dede
e   fd       Ze	dedee   fd       Ze	dede
e   fd       Zy)	_ConfigAliasesNrB   c                     d} t        j                  d      }t        j                  |       }t        j                  t        j                  |            }t        t        j                  t        j                  |       t        j                  |      |             |j                  }|| kD  rt        j                  |      }t        j                  t        j                  |            }t        t        j                  t        j                  |      t        j                  |      |             t        j                  |j                  j                  d      d       S )N   r   r   c                 ^    | j                         D ci c]  \  }}||g|z    c}}S c c}}w rD   r1  )r   kvs      r@   <lambda>z7_ConfigAliases._get_all_param_aliases.<locals>.<lambda>k  s0    adajajalImY]YZ\]!aSSTW*Im Ims   )object_hook)rK   r  create_string_bufferr  r   rM   r   LGBM_DumpParamAliasesrQ   rR   jsonloadsr   )
buffer_lentmp_out_lenstring_bufferptr_string_buffer
actual_lens        r@   _get_all_param_aliasesz%_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
 	
r?   argsc                     | j                   | j                         | _         t               }|D ]"  }|j                  | j	                  |             $ |S rD   )aliasesra  r3  update
get_sorted)clsrb  r   r   s       r@   getz_ConfigAliases.getn  sL    ;;446CKe 	*AJJs~~a()	*
r?   r   c                 ~    | j                   | j                         | _         | j                   j                  ||g      S rD   )rd  ra  rh  )rg  r   s     r@   rf  z_ConfigAliases.get_sortedw  s3    ;;446CK{{tdV,,r?   c                     | j                   | j                         | _         t        |      }|D ]8  }| j                   j                         D ]  }||v s|j	                  |        8 : |S rD   )rd  ra  r3  r   re  )rg  rb  r   argrd  s        r@   get_by_aliasz_ConfigAliases.get_by_alias}  sm    ;;446CK$i 	C;;--/ '>JJw'	
 
r?   )r:   r;   r<   rd  staticmethodr   r~   r   ra  classmethodr   rh  rf  rl  r>   r?   r@   rN  rN  M  s    G
Dd3i$8 
 
8  C   -c -d3i - -
 	 	S 	 	r?   rN  main_param_namedefault_valuec                 ~   t        |      }t        j                  |       }|D cg c]
  }|| k7  s	| }}| |j                         v r|D ]  }|j	                  |d        |S |D ]  }||j                         v s||   || <    n | |j                         v r|D ]  }|j	                  |d        |S ||| <   |S c c}w )a  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   rN  rf  keyspop)ro  rI   rp  rd  aparams         r@   _choose_param_valuerv    s    & fF''8G!:QQ/%9q:G: &++-' 	$EJJud#	$  FKKM!&,UmF?#
 &++-' 	$EJJud#	$ ,F?M- ;s
   
B:B:ir   ry   )labelweight
init_scoregroupposition)splitgainc                     t        | t        j                        rZt        | j                  t        j                        r6| j                  j
                  s t        d       t        j                  |       S | S )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   baser`   c_contiguousr   r   r   s    r@   _convert_from_sliced_objectr    sQ    $

#
499bjj(Izz&&J 774= Kr?   c                    t        |       rt        j                  |       } t        |       rt	        |       } | j
                  j                  sJ | j                  t        j                  k(  rC| j                  j                  t        j                  t        j                              }t        }n| j                  t        j                  k(  rC| j                  j                  t        j                  t        j                              }t         }n;t#        d| j                   d      t#        dt%        |       j&                   d      ||| fS )z(Get pointer of float numpy array / list.z,Expected np.float32 or np.float64, met type()Unknown type()r   r]   rc   r   r  r`   r  rZ   r^   rK   data_asr  r  _C_API_DTYPE_FLOAT32r_   r  _C_API_DTYPE_FLOAT64r   r   r:   rf   ptr_data	type_datas      r@   _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>??i&&r?   c                    t        |       rt        j                  |       } t        |       rt	        |       } | j
                  j                  sJ | j                  t        j                  k(  rC| j                  j                  t        j                  t        j                              }t        }n| j                  t        j                  k(  rC| j                  j                  t        j                  t        j                              }t         }n;t#        d| j                   d      t#        dt%        |       j&                   d      ||| fS )z&Get pointer of int numpy array / list.z(Expected np.int32 or np.int64, met type(r  r  )r   r]   rc   r   r  r`   r  rZ   int32rK   r  r  rO   _C_API_DTYPE_INT32int64r  _C_API_DTYPE_INT64r   r   r:   r  s      r@   _c_int_arrayr    s    4zz$$*40zz&&&&::!{{**6>>&..+IJH*IZZ288#{{**6>>&..+IJH*IFtzzlRSTUU-T
(;(;'<A>??i&&r?   c                     t        t        dt        d             }t        | t        j                  t        j
                  t        j                  f      xr t        | t        j                  |f       S )Nfloat128)r   r]   r   
issubclassr  r   r!  timedelta64)rZ   r  s     r@   _is_allowed_numpy_dtyper    sQ    r:tDz2Hebjj"++rxx@Aw*UZ]_]k]kmu\vJwFwwr?   pandas_dtypes_seriesc                     | j                         D cg c]!  \  }}t        |j                        s| d| # }}}|rt        ddj	                  |             y c c}}w )Nz: zIpandas dtypes must be int, float or bool.
Fields with bad pandas dtypes: z, )r1  r  r   r   r   )r  column_namepandas_dtypebad_pandas_dtypess       r@   r   r     s|     *>)C)C)E%K&|'8'89 -r,( 
 XY]YbYbctYuXvw
 	
 s   &Atarget_dtypec                    t        | j                         	 | j                  |d      S # t        $ r  | j	                  |d      j
                  cY S t        $ r$ | j                  |t        j                        cY S w xY w)NFr   r   )rZ   na_value)	r   r   to_numpyr   r   r   r   r]   nan)rf   r  s     r@   _pandas_to_numpyr  *  st     !-	B}}<e}<< < {{<e{4;;; B}}<"&&}AABs   * &A>)A>=A>feature_namecategorical_featurepandas_categoricalc                    t        | j                        dk7  s| j                  d   dk  rt        d      | j                  d      } |dk(  r"| j                  D cg c]  }t        |       }}t        | j                  | j                        D cg c]  \  }}t        |t              s| }}}|D cg c]  }| |   j                  j                  r|  }}|0|D cg c]$  }t        | |   j                  j                        & }}nt        |      t        |      k7  rt        d      t        ||      D ]U  \  }}t        | |   j                  j                        t        |      k7  s5| |   j                  j                  |      | |<   W t        |      r7| |   j                  d	       j!                  d
t"        j$                  i      | |<   |dk(  r|}| j                  D cg c]  }|j&                   }	}|	j)                  t"        j*                         t#        j,                  |	 }
t/        | |
      |||fS c c}w c c}}w c c}w c c}w c c}w )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                 .    | j                   j                  S rD   )catcodesrF   s    r@   rU  z#_data_from_pandas.<locals>.<lambda>X  s     r?   r  )r   r   r   r   columnsr~   zipr   r   r'   r  orderedr   
categoriesset_categoriesapplyreplacer]   r  r   r   r^   result_typer  )rf   r  r  r  colrZ   cat_colscat_cols_not_orderedrK  	df_dtypesr  s              r@   _data_from_pandasr  ;  s    4::!tzz!}q0JKK 99%9 D v,0LL9SC99 '*$,,&Do
U
SXZmHnoHo6>&\sd3immF[F[s&\&\!HPQd49==#;#;<QQx=C 233XYY +=> 	CMCDIMM,,-h? IMM88BS		C 8}h--.CDLLbRTRXRX\ZX f$2)-55I5RZZ >>9-L 	L9	 3 : p&\Q 6s*   II+I6II!)I*I	file_namec                     t        j                  | t              }d| d}|(t        |d      5 }|j	                  |       d d d        |S |S # 1 sw Y   |S xY w)Ndefaultz
pandas_categorical:
rt  )rZ  dumpsr$  openwrite)r  r  categorical_json
pandas_strr@  s        r@   _dump_pandas_categoricalr  k  sf     zz"4>VW()9(:"=J)S! 	 QGGJ	 :	 s   AA	model_strc                 p   d}t        |       }| t        |        }t        | d      5 }	 t        ||      }|j	                  |t
               |j                         }t        |      dk\  rn|dz  }G	 d d d        d   j                  d      j                         }|j                  |      sK|d   j                  d      j                         }n(|&|j                  dd|      }||d  j                         }j                  |      r!t        j                  |t        |      d        S y # 1 sw Y   xY w)	Nzpandas_categorical:rbr   r  r   r  r   )r   r   r  maxseekr	   	readlinesr   r   
startswithrfindrZ  r[  )	r  r  
pandas_keyoffset
max_offsetr@  lines	last_lineidxs	            r@   _load_pandas_categoricalr  w  s4    'J*oFi((
)T" 	aVZ0vx(u:?! 
 	 "I$$W-335	##J/b	((1779I		oodAv.cdO))+	J'zz)C
O$5677#	 	s   A	D,,D5c                       e Zd ZdZdZej                  deee	e
e   f   dej                  fd       Zej                  defd       Zy)r1   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  rB   c                     t        d      )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)rv   r  s     r@   __getitem__zSequence.__getitem__  s    8 ""abbr?   c                     t        d      )z"Return row count of this sequence.z9Sub-classes of lightgbm.Sequence must implement __len__()r  r   s    r@   __len__zSequence.__len__  s     ""]^^r?   N)r:   r;   r<   r=   
batch_sizeabcabstractmethodr   r   slicer   r]   r   r  r  r>   r?   r@   r1   r1     sp    6 JcuS%c%:; c

 c c: 	_ _ _r?   c                   0   e Zd ZdZdedeee      deee	f   de
fdZedddeee	f   d	d fd
       Zedeeef   deee	f   d	d fd       Zd4dZd	eee	f   fdZ	 	 	 	 	 	 	 d5dededede
de
de
de
de
d	eej,                  ej0                  j2                  eej0                  j2                     f   fdZdedededed	ef
dZdej,                  dedededeej,                     d	eej,                  ef   fdZdej,                  dededed	eej,                  ef   f
dZd eej0                  j>                  ej0                  j@                  f   d!ej,                  d"d#d$d#d%d#d&ed'ed(e
d	eeej0                  j>                     eej0                  j@                     f   fd)Z!d*ej0                  j@                  dedededeej,                     d	eej,                  ef   fd+Z"d*ej0                  j@                  dededed	eeeej0                  j>                     eej0                  j@                     f   ef   f
d,Z#d*ej0                  j@                  dededed	eej,                  ef   f
d-Z$d.ej0                  j>                  dededed	eeeej0                  j>                     eej0                  j@                     f   ef   f
d/Z%d.ej0                  j>                  dededed	eej,                  ef   f
d0Z&d1e'dededed	eej,                  ef   f
d2Z(d	efd3Z)y)6_InnerPredictorz_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                    || _         || _        || _        t        |      | _        t        j                  d      }t        t        j                  | j                   t        j                  |                   |j                  | _        y)aX  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  r8  r  rK   rL   rM   r   LGBM_BoosterGetNumClassesrQ   rR   	num_class)rv   r  r  r  r  out_num_classs         r@   r   z_InnerPredictor.__init__  sm    * &"/"40@Q**]+	
 ',,r?   boosterr,   rB   c                     t        j                  d      }t        t        j                  |j
                  t        j                  |                    | |j
                  |j                  |d      S )zInitialize an ``_InnerPredictor`` from a ``Booster``.

        Parameters
        ----------
        booster : Booster
            Booster.
        pred_parameter : dict
            Other parameters for the prediction.
        r   Fr  r  r  r  )rK   rL   rM   r   LGBM_BoosterGetCurrentIterationr  rQ   r  )rg  r  r  out_cur_iters       r@   from_boosterz_InnerPredictor.from_booster  s_     ||A00\*	
 "??&99)	
 	
r?   
model_filec           	      0   t        j                         }t        j                  d      }t        t	        j
                  t        t        |            t        j                  |      t        j                  |                    | |t        |      |d      S )a  Initialize 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  )
rK   c_void_prL   rM   r   LGBM_BoosterCreateFromModelfilerP   r~   rQ   r  )rg  r  r  r  out_num_iterationss        r@   from_model_filez_InnerPredictor.from_model_file   sy      *#\\!_00s:'/0^,	
 )7*M)	
 	
r?   Nc                     	 | j                   r)t        t        j                  | j                               y y # t
        $ r Y y w xY wrD   )r  rM   r   LGBM_BoosterFreer  AttributeErrorr   s    r@   __del__z_InnerPredictor.__del__?  s>    	&&400>? ' 		s   48 	AAc                     | j                   j                         }|j                  dd        |j                  dd        |S )Nhandler  )__dict__r   rs  )rv   thiss     r@   __getstate__z_InnerPredictor.__getstate__F  s5    }}!!#4 D!r?   rf   start_iterationnum_iteration	raw_score	pred_leafpred_contribdata_has_headervalidate_featuresc	                 	   t        |t              rt        d      t        |t              r|r|j                  D 	cg c]  }	t        |	       }
}	t        j                  t        |
      z         }|
D 	cg c]  }	|	j                  d       c}	|dd t        t        j                  | j                  |t        j                  t        |
                         t        |t              rt        |dd| j                         d   }t"        }|rt$        }|rt&        }|rt(        }t        |t
        t*        f      rt-               5 }t        t        j.                  | j                  t1        t        |            t        j                  |      t        j                  |      t        j                  |      t        j                  |      t1        | j2                        t1        |j4                                     t7        j8                  |j4                  t6        j:                        }|j<                  d   }ddd       nt        |t>        j@                  jB                        r| jE                  ||||      \  }}nXt        |t>        j@                  jF                        r| jI                  ||||	      \  }}nt        |t6        jJ                        r| jM                  ||||
      \  }}ntO        |      r| jQ                  ||||      \  }}nt        |tR              r/	 t7        jT                  |      }| jM                  ||||
      \  }}nt        |tZ              r1t]                | jM                  |j_                         |||
      \  }}nC	 ta        d       t>        j@                  jC                  |      }| jE                  ||||      \  }}|rjg                  t6        jh                        }t        tR        t>        j@                  jj                  f      }|sU|jl                  k7  s|s|rB|jl                  |z  dk(  r|jo                  |d      }|S tY        d|jl                   d| d      |S c c}	w c c}	w # 1 sw Y   xY w# tV        $ r}tY        d      |d}~ww xY w# tV        $ r'}t        dtc        |      jd                         |d}~ww xY w)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  rf   r  r  r  r   r   csrr  r  predict_typecscr  r  r  )rU   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~   rK   r  r   r  rM   r    LGBM_BoosterValidateFeatureNamesr  rL   r  r  _C_API_PREDICT_NORMAL_C_API_PREDICT_RAW_SCORE_C_API_PREDICT_LEAF_INDEX_C_API_PREDICT_CONTRIBr   r:  LGBM_BoosterPredictForFilerP   r  r   r]   loadtxtr_   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!   rL  r  r   r   r:   r   r  spmatrixsizereshape)rv   rf   r  r  r  r  r  r  r  rA   
data_names	ptr_namesr  r@  predsnrowerrr  	is_sparses                      r@   predictz_InnerPredictor.predictL  s[   V dG$effl+0A*.,,7Q#a&7J73z?:=I7AB!AHHW-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-- /+)	 . KE4 ell556-- /+)	 . KE4 bjj).. /+)	 / KE4 t$77 /+)	 8 KE4 d#Vxx~ .. /+)	 / KE4 l+/1..MMO /+)	 / KE4`FGll--d3 -- /+)	 . KE4 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\__`sH   Q94Q>C2R#R *R, R	R)R$$R),	S5"SSr'  r  c                    |t         kD  rt        dt          d      t        j                  d      }t	        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |                   |j                  S )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/   rK   r  rM   r   LGBM_BoosterCalcNumPredictr  rL   rQ   rR   )rv   r  r  r'  r  n_predss         r@   __get_num_predsz_InnerPredictor.__get_num_preds  s     *??Il K<<  ..#++T"\*_-]+W%		
 }}r?   rU   r&  c                    t        |      \  }}t        |      \  }}	}
| j                  |||j                  d   |      }|&t	        j
                  |t        j                        }n1t        |j                        dk7  st        |      |k7  rt        d      t        j                  d      }t        t        j                  | j                  |t        j                  |	      t        j                   |j                  d         t        j                   |j                  d         t        j                  |      t        j                  |      t        j                  |      t        j                  |      t#        | j$                        t        j&                  |      |j                  j)                  t        j*                  t        j,                                           ||j.                  k7  rt        d      ||j                  d   fS )Nr   r  r  r'  r  r   r   +Wrong length of pre-allocated predict array Wrong length for predict results)rg   r  _InnerPredictor__get_num_predsr   r]   emptyr_   r   r   rK   r  rM   r   LGBM_BoosterPredictForMatr  rL   rO   rP   r  rQ   r  r  r  rR   )rv   rU   r  r  r  r&  rf   re   r  type_ptr_data_r.  out_num_predss                r@   __inner_predict_np2dz$_InnerPredictor.__inner_predict_np2d  s    %S)f%3D%9"-&&+'1%	 ' 
 =HHWBJJ7E"c%jG&;JKKq)**]+syy|,syy|,V$\*_-]+t**+]+$$V^^FOO%DE	
  m)))?@@ciil""r?   c           
         t        |j                        dk7  rt        d      |j                  d   }|t        kD  rt	        j
                  t        |t              }t	        j                  dgt        |      z   |gz         D cg c]  }| j                  ||||       }}t	        j                  dg|z   t        j                        j                         }	t	        j                  t        |      t        j                        }
t        t	        j                   ||      t        |	|	dd             D ]!  \  }\  }}| j#                  |||||
||        # |
|fS | j#                  ||||d      S c c}w )	zPredict for a 2-D numpy matrix.r   z1Input numpy.ndarray or list must be 2 dimensionalr   startstopstepr   r   N)rU   r  r  r  r&  )r   r   r   r,  r]   arangediffr   r4  r   intpcumsumr5  sumr_   r  array_split#_InnerPredictor__inner_predict_np2d)rv   rU   r  r  r  r'  sectionsr   r.  n_preds_sectionsr&  chunkstart_idx_predend_idx_preds                 r@   __pred_for_np2dz_InnerPredictor.__pred_for_np2d/  ss    syy>QPQQyy|*yyz:NH !tH~!5!>? $$_mQUG   "xxgRWWELLNHHS\<E9<sH-s3CEUVWVXEY/Z: 
55 ))$3"/!-|< * 	
 $;,, /+) -  's   E2cs	out_shapeout_ptr_indptrr  out_ptr_indicesout_ptr_dataindptr_type	data_typeis_csrc	                    |d   }	|d   }
|t         k(  rt        ||
      }n"|t        k(  rt        ||
      }nt	        d      |t
        k(  rt        ||	      }n"|t        k(  rt        ||	      }nt	        d      t        ||	      }|j                  j                  d   }|s|dz  }t        j                  ||j                  d   |z        }g }d}|D ]  }||j                  d   dz
     }|||d   z   ||z    }|||d   z   ||z    }||z  }|j                  d   |j                  d   dz   g}|r3|j                  t        j                  j!                  |||f|             |j                  t        j                  j#                  |||f|              t%        t'        j(                  |||t+        j,                  |      t+        j,                  |                   t/        |      dk(  r|d   S |S )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   r  r  r  r  rM   r   LGBM_BoosterFreePredictSparserK   rL   r   )rv   rM  rN  rO  rP  rQ  rR  rS  rT  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                          r@   __create_sparse_nativez&_InnerPredictor.__create_sparse_nativeY  s    %Q<q\
,,/^JWJ../^JWJEFF,,/\JZ[H../\JZ[HGHH,/JZ[!#!3"a'"HHZ1A1A!1DG]1]^* 	oI ))//!*<q*@ A$Vil%:VFW=WXJv	!4v@Q7QRG''FRXXa[1_5H"))%,,*A*A7JXaBbdl*mn"))%,,*A*A7JXaBbdl*mn	o 	..[)Y'	
 !"a'%a((!!r?   r  c                    t        |j                        dz
  }| j                  ||||      }|&t        j                  |t        j
                        }n1t        |j                        dk7  st        |      |k7  rt        d      t        j                  d      }t        |j                        \  }	}
}t        |j                        \  }}}|j                  d   t        k  sJ |j                  j                  t        j                   d      }t#        t%        j&                  | j(                  |	t        j*                  |
      |j                  j-                  t        j.                  t        j0                              |t        j*                  |      t        j                  t        |j                              t        j                  t        |j                              t        j                  |j                  d         t        j*                  |      t        j*                  |      t        j*                  |      t3        | j4                        t        j6                  |      |j                  j-                  t        j.                  t        j8                                           ||j:                  k7  rt        d      ||fS )	Nr   r1  r   r2  r   Fr  r3  )r   rV  r4  r]   r5  r_   r   r   rK   r  r  r  rf   r,  indicesr   r  rM   r   LGBM_BoosterPredictForCSRr  rL   r  r  rO   rP   r  rQ   r  rR   )rv   r  r  r  r  r&  r'  r.  r9  
ptr_indptrtype_ptr_indptrr8  r  r7  csr_indicess                  r@   __inner_predict_csrz#_InnerPredictor.__inner_predict_csr  s     3::"&&+'%	 ' 
 =HHWBJJ7E"c%jG&;JKKq))5cjj)A&
OQ%3CHH%="-yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+]+$$V^^FOO%DE	
& m)))?@@d{r?   c                    t        |j                        \  }}}t        |j                        \  }}	}
|j                  j                  t        j                  d      }t        }|t        k(  r) t        j                  t        j                               }n( t        j                  t        j                               } t        j                  t        j                               }|	t        k(  r) t        j                  t        j                               }n( t        j                  t        j                                }t        j"                  dt        j$                        }t'        t)        j*                  | j,                  |t        j.                  |      |j                  j1                  t        j                  t        j                              |t        j.                  |	      t        j                  t3        |j                              t        j                  t3        |j                              t        j                  |j4                  d         t        j.                  |      t        j.                  |      t        j.                  |      t7        | j8                        t        j.                  |      |j                  j1                  t        j                  t        j                              t        j:                  |      t        j:                  |      t        j:                  |                   | j=                  |||||||	d      }t3        |j                        dz
  }||fS )NFr  r   r   r   TrM  rN  rO  rP  rQ  rR  rS  rT  )r  rV  r  rf   rg  r   r]   r  _C_API_MATRIX_TYPE_CSRr  rK   r  rO   r  r  r  r  r5  r  rM   r   LGBM_BoosterPredictSparseOutputr  rL   r  r   r   rP   r  rQ   %_InnerPredictor__create_sparse_native)rv   r  r  r  r  ri  rj  __r  r7  r8  rk  matrix_typerO  rP  rQ  rN  matricesr'  s                      r@   __inner_predict_csr_sparsez*_InnerPredictor.__inner_predict_csr_sparse  sQ    +7szz*B'
OR%3CHH%="-kk(((>,00;V^^FNN;=N;V^^FNN;=N8&..8:0096>>&..9;L:6>>&//:<LHHQbhh/	00_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+[)  (()GH^,_-\*%	
, ..)+%'# / 	
 3::"~r?   c           
         |t         k(  r| j                  ||||      S t        |j                        dz
  }|t        kD  rdgt        t        j                  t        |t                    z   |gz   }t        j                  |      D cg c]  }| j                  ||||       }}t        j                  dg|z   t        j                        j                         }	t        j                  t        |      t        j                        }
t!        t!        ||dd       t!        |	|	dd             D ]'  \  \  }}\  }}| j#                  ||| ||||
||        ) |
|fS | j#                  ||||d      S c c}w )zPredict for a CSR data.r  r   r   r<  r   N)r  r  r  r  r&  )r  )_InnerPredictor__inner_predict_csr_sparser   rV  r,  r   r]   r@  rA  r4  r   rB  rC  r5  rD  r_   r  "_InnerPredictor__inner_predict_csr)rv   r  r  r  r  r'  rG  r   r.  rH  r&  	start_idxend_idxrJ  rK  s                  r@   __pred_for_csrz_InnerPredictor.__pred_for_csr  s    1122 /+)	 3   3::"*sT"))*4j"YZZ^b]ccHfhfmfmnvfwxabt++O]A|\xGx!xxgRWWELLNHHS\<EHKHhqrl+S1ACSTUTVCW-XI 
D$G&D~| ((Ig.$3"/!-|< ) 	
 $;++ /+) ,  ! ys   	E5r  c                    t        |j                        \  }}}t        |j                        \  }}	}
|j                  j                  t        j                  d      }t        }|t        k(  r) t        j                  t        j                               }n( t        j                  t        j                               } t        j                  t        j                               }|	t        k(  r) t        j                  t        j                               }n( t        j                  t        j                                }t        j"                  dt        j$                        }t'        t)        j*                  | j,                  |t        j.                  |      |j                  j1                  t        j                  t        j                              |t        j.                  |	      t        j                  t3        |j                              t        j                  t3        |j                              t        j                  |j4                  d         t        j.                  |      t        j.                  |      t        j.                  |      t7        | j8                        t        j.                  |      |j                  j1                  t        j                  t        j                              t        j:                  |      t        j:                  |      t        j:                  |                   | j=                  |||||||	d      }|j4                  d   }||fS )NFr  r   r   r   rn  )r  rV  r  rf   rg  r   r]   r  _C_API_MATRIX_TYPE_CSCr  rK   r  rO   r  r  r  r  r5  r  rM   r   rp  r  rL   r  r   r   rP   r  rQ   rq  )rv   r  r  r  r  ri  rj  rr  r  r7  r8  csc_indicesrs  rO  rP  rQ  rN  rt  r'  s                      r@   __inner_predict_sparse_cscz*_InnerPredictor.__inner_predict_sparse_csc.  sL    +7szz*B'
OR%3CHH%="-kk(((>,00;V^^FNN;=N;V^^FNN;=N8&..8:0096>>&..9;L:6>>&//:<LHHQbhh/	00_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+[)  (()GH^,_-\*%	
, ..)+%'# / 	
 yy|~r?   c                    |j                   d   }|t        kD  r#| j                  |j                         |||      S |t        k(  r| j                  ||||      S | j                  ||||      }t        j                  |t        j                        }t        j                  d      }t        |j                        \  }	}
}t        |j                        \  }}}|j                   d   t        k  sJ |j                   j#                  t        j$                  d      }t'        t)        j*                  | j,                  |	t        j.                  |
      |j                  j1                  t        j2                  t        j4                              |t        j.                  |      t        j                  t7        |j                              t        j                  t7        |j                              t        j                  |j                   d         t        j.                  |      t        j.                  |      t        j.                  |      t9        | j:                        t        j<                  |      |j                  j1                  t        j2                  t        j>                                           ||j@                  k7  rtC        d      ||fS )	zPredict for a CSC data.r   r  r  r1  r   Fr  r3  )"r   r,  r  tocsrr  )_InnerPredictor__inner_predict_sparse_cscr4  r]   r5  r_   rK   r  r  rV  r  rf   rg  r   r  rM   r   LGBM_BoosterPredictForCSCr  rL   r  r  rO   r   rP   r  rQ   r  rR   r   )rv   r  r  r  r  r'  r.  r&  r9  ri  rj  rr  r  r7  r8  r~  s                   r@   __pred_for_cscz_InnerPredictor.__pred_for_csch  s1    yy|*&&IIK /+)	 '   1122 /+)	 3   &&+'%	 ' 
 

3q)*6szz*B'
OR%3CHH%="-yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,\*_-]+t**+]+$$V^^FOO%DE	
& m)))?@@d{r?   r  c                    t         rt        st        d      t        d |j                  j
                  D              st        d      | j                  |||j                  |      }t        j                  |t        j                        }t        j                  d      }t        |      }t        t!        j"                  | j$                  t        j                  |j&                        t        j(                  |j*                        t        j(                  |j,                        t        j.                  |      t        j.                  |      t        j.                  |      t1        | j2                        t        j4                  |      |j                  j7                  t        j8                  t        j:                              
             ||j<                  k7  rt        d      ||j                  fS )zPredict for a PyArrow table.zACannot predict from Arrow without 'pyarrow' and 'cffi' installed.c              3   f   K   | ])  }t        |      xs t        |      xs t        |       + y wrD   r   r   r   r   ts     r@   r   z;_InnerPredictor.__pred_for_pyarrow_table.<locals>.<genexpr>  1     rZ[#A&U*;A*>UBRSTBUUr   /1=Arrow table may only have integer or floating point datatypesr1  r   r   r3  )r   r   r/   r   r   typesr   r4  num_rowsr]   r5  r_   rK   r  r   rM   r   LGBM_BoosterPredictForArrowr  r   r  r   r   rL   rP   r  rQ   r  r  r  rR   )	rv   r  r  r  r  r.  r&  r9  c_arrays	            r@   __pred_for_pyarrow_tablez(_InnerPredictor.__pred_for_pyarrow_table  sp    "n cdd r_d_k_k_q_qrr\]] &&+'%	 ' 
 

3q) %U+,,w//0 2 23 2 23\*_-]+t**+]+$$V^^FOO%DE	
 m)))?@@enn$$r?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S zGet the index of the current iteration.

        Returns
        -------
        cur_iter : int
            The index of the current iteration.
        r   rK   rL   rM   r   r  r  rQ   rR   rv   r  s     r@   current_iterationz!_InnerPredictor.current_iteration  H     ||A00\*	
 !!!r?   rB   N)r   r  FFFFF)*r:   r;   r<   r=   _BoosterHandler   r   r   r~   r   boolr   rn  r  r   r   r  r  r  _LGBM_PredictDataTyper   r]   r   r  r  r!  r*  r4  r   rF  r  r  r  rq  rx  rw  r  r  r  r&   r  r  r>   r?   r@   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 "r?   r  c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 dUdedee   ded    dee   dee   dee	   d	e
d
edeeeef      dedee   fdZdVdZdedej*                  fdZdededd fdZdeej*                     deej*                     dededd f
dZdej*                  dd fdZdeeef   fdZdWdZdee   dedeeee   ej*                  f      dd fdZ dee   dee   ded    dee   dee   dee	   dee   d	e
d
edeeeef      dee   dd fdZ!e"d ee#   d!e$e   de%ej*                     fd"       Z&d ee#   dede'eej*                     eej*                     f   fd#Z(d ee#   dee   dd fd$Z)d%ej*                  d&edee   dd fd'Z*d(eej*                     d&edee   dd fd)Z+d*e,jZ                  j\                  d&edee   dd fd+Z/d,e,jZ                  j`                  d&edee   dd fd-Z1d.e2d&edee   dd fd/Z3e"deeef   d0eeef   d1e4e   defd2       Z5dWd3Z6	 	 	 	 	 	 dXdedee   dee   dee   dee	   deeeef      dee   dd fd4Z7	 dYdee   deeeef      dd fd5Z8d6eee9f   dd fd7Z:deeeef      dd fd8Z;dWd9Z<d:edee=   dd fd;Z>d:edeej*                     fd<Z?d
edd fd=Z@dee   dd fd>ZAdZd?ZBd	e
dd fd@ZCdee   dd fdAZDdee   dd fdBZEdee	   dd fdCZFdee   dd fdDZGdee   dd fdEZHdee   fdFZIdee   fdGZJdee   fdHZKdee	   fdIZLdee   fdJZMdee   fdKZNdee   fdLZOdefdMZPdefdNZQdOeeef   defdPZRd[dQede4d    fdRZSd\dSZTd6eee9f   dd fdTZUy)]r-   aO  
    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.
    Nrf   rw  	referencerx  rz  ry  r  r  rI   free_raw_datar{  c                     d| _         || _        || _        || _        || _        || _        || _        || _        || _        || _	        t        |	      | _        |
| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        y)a|  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  rf   rw  r  rx  rz  r{  ry  r  r  r   rI   r  used_indices_need_slice
_predictorr  _params_back_upversion
_start_row)rv   rf   rw  r  rx  rz  ry  r  r  rI   r  r{  s               r@   r   zDataset.__init__  s    n 26	
"
 $<HJ] v&*15598<9=r?   rB   c                 D    	 | j                          y # t        $ r Y y w xY wrD   )_free_handler  r   s    r@   r  zDataset.__del__:  s%    	 		s    	rH   c           
         t        | j                               }t        ||      }t        j                  |t        j
                        }t        |      \  }}}t        j                  d      }t        t        j                  t        j                  |      t        |      |t        j                  |                   ||j                  k(  sJ |S )aD  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   )r8  
get_paramsrT   r]   r5  r  r  rK   rO   rM   r   LGBM_SampleIndicesrP   rQ   rR   )rv   rH   	param_strrS   rg  r  r8  actual_sample_cnts           r@   _create_sample_indiceszDataset._create_sample_indices@  s    " 't'89	&z9=
((:RXX6%g.!Q"NN1-##z*y!./		
 .44444r?   ref_datasetc           	          t        j                         | _        t        t	        j
                  |t        j                  |      t        j                  | j                                     | S )ag  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.
        )rK   r  r  rM   r   LGBM_DatasetCreateByReferencer  rQ   )rv   rH   r  s      r@   _init_from_ref_datasetzDataset._init_from_ref_datasetb  sN    & (..z*T\\*	
 r?   sample_datasample_indicesrS   c                    t        |      }t        |      |k(  sJ d       t        |      D ]  }||   j                  t        j                  k7  rt        d| d||   j                   d      ||   j                  t        j                  k7  sct        d| d||   j                   d        t        j                  t        j                        |z         } t        j                  t        j                        |z         }t        |      D ]*  }t        ||         d   ||<   t        ||         d   ||<   , t        j                  |D 	cg c]  }	t        |	       c}	t        j                        }
t        |
      \  }}}t        j                         | _        t!        | j#                               }t%        t'        j(                  t        j*                  |t        j                  t        j                  t        j                                    t        j*                  |t        j                  t        j                  t        j                                    t        j                  |      |t        j                  |      t        j                  |      t        j,                  |      t/        |      t        j0                  | j                        	             | S c c}	w )	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   rangerZ   r]   doubler   r  rK   r  r  rO   r  r  r   r  r  r8  r  rM   r   #LGBM_DatasetCreateFromSampledColumnr   r  rP   rQ   )rv   r  r  rS   rH   ncolr   sample_col_ptrindices_col_ptrdnum_per_colnum_per_col_ptrr8  
params_strs                 r@   _init_from_samplezDataset._init_from_sample  sE   2 >";4'Q)QQ't 	eA1~##ryy0 <s'+a.:N:N9O~!^__a &&"((2 ?1#W^A=N=T=T<UUb!cdd		e 0Vv~~foo/NQU/U.X /TfnnV^^.Lt.S-Vt 	DA .{1~ >q AN1!-nQ.?!@!COA	D hh?1A?rxxP ,[ 9A('(9:
44NFNN6>>&//;Z,[\OV^^FNN6>><Z-[\t$z*z*z*z"T\\*
	
 %  @s   K$c                    |j                   \  }}|j                  |j                        }t        |      \  }}}t	        t        j                  | j                  ||t        j                  |      t        j                  |      t        j                  | j                                     | xj                  |z  c_
        | S )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  rM   r   LGBM_DatasetPushRowsr  rK   rO   r  )rv   rf   r'  r  data_ptrrS  r8  s          r@   
_push_rowszDataset._push_rows  s     ZZ
d||DII&!/!5)Q%%t$t$t/		
 	4r?   c                     | j                   \t        j                  ddddddddd	d
ddddddddddd      }| j                   j                         D ci c]  \  }}||v s|| c}}S i S c c}}w )zGet 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)rI   rN  rh  r1  )rv   dataset_paramsrS  rT  s       r@   r  zDataset.get_params  s     ;;"+//*%"$%"$!&!+N. &*[[%6%6%8PTQA<OAqDPPI Qs   A+ A+c                     | j                   /t        t        j                  | j                                d | _         d| _        | j
                  d | _        | S )NT)r  rM   r   LGBM_DatasetFreer  r  rf   r   s    r@   r  zDataset._free_handle  sJ    <<#t,,T\\:;DL(DIr?   	predictorr  c                 N    d}t        |t        t        f      r3 j                  't	         fdt
        j                  d      D              } j                         }|u|j                  |d|      }|j                         }|Ɖ j                  rJ t        |t        t        f      rt        j                  ||j                  z  t        j                        }|t        |      k(  sJ t!        t        |            D ]G  }t!        |j                        D ]-  }	|||   |j                  z  |	z      |||j                  z  |	z   <   / I |}|j                  dkD  rt        j                  |j"                  t        j                        }
t!        |      D ]:  }t!        |j                        D ]   }	|||j                  z  |	z      |
|	|z  |z   <   " < |
}n? j$                  1t        j&                   j$                  dt        j                  	      }n S  j)                  |        S )
NFc              3   V   K   | ]   }j                   j                  |d        " yw)FN)rI   rh  )r   aliasrv   s     r@   r   z7Dataset._set_init_score_by_predictor.<locals>.<genexpr>  s      !jE$++//%"?!js   &)r  T)rf   r  r  r   r   g        )
fill_valuerZ   )r   r~   r   rI   anyrN  rh  num_datar*  rd   r  r]   r5  r  r_   r   r  r"  ry  	full_likeset_init_score)rv   r  rf   r  r  r  ry  sub_init_scorer   jnew_init_scores   `          r@   _set_init_score_by_predictorz$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%'XXh9L9L.LTVT^T^%_N#s<'8888"3|#45 !&y':':!; AJT ,Q)2E2E E IKN1y/B/B+BQ+FG
 "0J""Q&!#*//!Lx cA"9#6#67 c;Ea)J]J]F]`aFa;bq8|a'78cc ,
__(doo#RZZXJKJ'r?   c           
         |	d | _         | S ||j                  | _        |j                  }	t        |t              r$t        |||	| j                        \  }}}	| _        nt        |      r|dk(  r|j                  }|
i n|
}
t        j                  | j                  j                        j                  j                         }|
j                         D ]  }||v st        | d| d        t        |	t              r#t!               }i }t        |t              rt#        |      D ci c]  \  }}||
 }}}|	D ]q  }t        |t$              r||v r|j'                  ||          ,t        |t(              r|j'                  |       Nt+        dt-        |      j.                   d| d       |rqt0        j3                  d      D ]K  }||
v st        |
|   t              rt!        |
|         |k(  st        | d	       |
j5                  |d        M t7        |      |
d
<   t9        |
      }|
| _        d }t        |t<              r|j?                         j                   }n|t+        d      t        |t$        t@        f      rttC        jD                         | _         tG        tI        jJ                  tM        t%        |            tM        |      |tC        jN                  | j                                      nt        |tP        jR                  jT                        r| jW                  |||       nt        |tP        jR                  jX                        r| j[                  |||       nGt        |t\        j^                        r| ja                  |||       nt        |      r| jc                  |||       nt        |t              rVte        |      dkD  rHtg        |      r| ji                  |||       ntk        |      r| jm                  ||       nt+        d      t        |tn              r| jm                  |g|       not        |tp              r,ts                | ja                  |ju                         ||       n3	 tP        jR                  jU                  |      }| jW                  |||       || jy                  |       | j{                         t}        d      || j                  |       || j                  |       || j                  |       t        |t              r.| j                  |t        d       | j                  ||d        n7|| j                  |       n#|!t+        dt-        |      j.                         | j                  |      S c c}}w # tv        $ r'}t+        dt-        |      j.                         |d }~ww xY w)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  rf   r  zWrong predictor type )Gr  r  r  r   r(   r  r   column_namesinspect	signature	__class__
_lazy_init
parametersrr  r   r   r3  r   r~   addr   r   r   r:   rN  rh  rs  sortedr8  rI   r-   	constructr   rK   r  rM   r   LGBM_DatasetCreateFromFilerP   rQ   r  r  r  _Dataset__init_from_csrr  _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!   rL  r  r   	set_label	get_labelr   
set_weight	set_groupset_positionr  r  r  r  set_feature_name)rv   rf   rw  r  rx  rz  ry  r  r  r  rI   r{  
args_namesr7  categorical_indicesfeature_dictr   r   	cat_aliasr  r  r  r(  s                          r@   r  zDataset._lazy_init6  s9    <DLK &/&B&BD#"+"?"?dL)O`)$7#'#:#:	PLD, 3T5L t$)?,,L ~6&&t~~'@'@ALLQQS
;;= 	Cj e ""%&bd	 )40"%%L,-7@7NOGAtaOO+ ydC(T\-A'++L,>?c*'++D1#k$t*2E2E1FFXY]X^^v$wxxy #!/!3!34I!J 4I F* *6)+<d CFS\L]H^buHu(I;6S)TU

9d34 066I/J+,'/
i)#--/77K"RSSdS$K(!??,DL//3t9%:&LL.	 ell556  z;?ell55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&:+Aab--	[_-`#
+"3DO4L4L3MNOO$$\22c  Px ! b"A$t*BUBUAV WX^aabs   (V>2V# #	W,"WWseqsrg  c              #     K   d}d}| |   }|D ]v  }||k\  sJ d       ||t        |      z   k\  r*|t        |      z  }|dz  }| |   }||t        |      z   k\  r*||z
  }||   }|j                  d   r|n|j                          x y w)Nr   z+sample indices are expected to be monotonicr   OWNDATA)r   r`   r   )r  rg  r  seq_idseqrow_id	id_in_seqrows           r@   _yield_row_from_seqlistzDataset._yield_row_from_seqlist  s     6l 	>FV#R%RR#FSX--#c("!6l FSX-- Ii.C9-#388:=	>s   AB0Bc                    | j                  |      }t        j                  t        | j	                  ||                  }|j
                  }g }g }t        j                  t        |      t        j                        }|D ]`  }t        j                  |      t        kD  t        j                  |      z  }	||	   }
||	   }|j                  |
       |j                  |       b ||fS )zSample data from seqs.

        Mimics behavior in c_api.cpp:LGBM_DatasetCreateFromMats()

        Returns
        -------
            sampled_rows, sampled_row_indices
        r   )r  r]   r   r   r  Tr@  r   r  absrE   isnanr   )rv   r  rH   rg  sampledfilteredfiltered_idxsampled_row_ranger  col_predicatefiltered_colfiltered_row_idxs               r@   __samplezDataset.__sample  s     --j9 ((4 < <T7 KLM))IIc'l"((C 	2CVVC[>9RXXc]JM}-L0?OOL) 01	2 %%r?   c                    t        d |D              }|| j                  ||       nNt        | j                               }t	        ||      }| j                  ||      \  }}| j                  ||||       |D ]a  }t        |      }	t        |dd      xs t        j                  }
t        d|	|
      D ]%  }t        ||
z   |	      }| j                  |||        ' c | S )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   2   K   | ]  }t        |        y wrD   r  )r   r
  s     r@   r   z+Dataset.__init_from_seqs.<locals>.<genexpr>  s     2cS2r)  Nr  r   )rD  r  r8  r  rT   _Dataset__sampler  r   r   r1   r  r  minr  )rv   r  r  rH   r  rS   r  col_indicesr
  r'  r  r=  ends                r@   __init_from_seqszDataset.__init_from_seqs  s     2T22
 "''
K@*4??+<=I*:yAJ'+}}T:'F$K"";ZT 	0Cs8D lD9PX=P=PJq$
3 0%*,d3E#/0	0 r?   rU   r  c                    t        |j                        dk7  rt        d      t        j                         | _        t        |      \  }}t        |      \  }}}t        t        j                  |t        j                  |      t        j                  |j                  d         t        j                  |j                  d         t        j                  |      t        |      |t        j                  | j
                                     | S )z(Initialize data from a 2-D numpy matrix.r   )Input numpy.ndarray must be 2 dimensionalr   r   )r   r   r   rK   r  r  rg   r  rM   r   LGBM_DatasetCreateFromMatrL   rO   rP   rQ   )	rv   rU   r  r  rf   re   r  r7  r8  s	            r@   __init_from_np2dzDataset.__init_from_np2d	  s     syy>QHII($S)f%3D%9"-**]+syy|,syy|,V$z"T\\*		
 r?   matsc                    |d   j                   d   }t        j                  t        |      ft        j                        }|d   j
                  t        j                  k(  r5 t        j                  t        j                        t        |      z         }n4 t        j                  t        j                        t        |      z         }t        j                  t        |      z         }g }d}	t        |      D ]  \  }
}t        |j                         dk7  rt        d      |j                   d   |k7  rt        d      |j                   d   ||
<   t        |      \  }}t        |      \  }}}|	dk7  r||	k7  rt        d      |||
<   |||
<   |}	|j!                  |        t        j"                         | _        t'        t)        j*                  t        j,                  t        |            t        j.                  |t        j                  t        j                  t        j                                    t        j                  |	      |j                  j1                  t        j                  t        j,                              t        j,                  |      |t3        |      |t        j4                  | j$                        	             | S )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]   r5  r   r  rZ   r_   rK   r  r  r  rL   r   r   rg   r  r   r  r  rM   r   LGBM_DatasetCreateFromMatsrO   r   r  rP   rQ   )rv   r&  r  r  r  r'  r  layoutsholdersr7  r   rU   re   chunk_ptr_datachunk_type_ptr_dataholders                   r@   __init_from_list_np2dzDataset.__init_from_list_np2d	  s    Aw}}QxxTbhh/7==BJJ&Cv7#d)CFHBv~~6TBEH<<#d)+.o 	#FAs399~" !LMMyy|t# !PQQiilDG',KC:H:M7N/"':m'K !CDD(HQKGAJ/MNN6"#	#& (++s4y)HfnnV^^FOO5T&UV]+##FNN6>>$BCt$z"T\\*
	
 r?   r  c                    t        |j                        t        |j                        k7  r7t        dt        |j                         dt        |j                               t	        j
                         | _        t        |j                        \  }}}t        |j                        \  }}}	|j                  d   t        k  sJ |j                  j                  t        j                  d      }
t        t!        j"                  |t	        j$                  |      |
j                  j'                  t	        j(                  t        j*                              |t	        j$                  |      t	        j,                  t        |j                              t	        j,                  t        |j                              t	        j,                  |j                  d         t/        |      |t	        j0                  | j                                     | S )z"Initialize data from a CSR matrix.Length mismatch:  vs r   Fr  )r   rg  rf   r   rK   r  r  r  rV  r  r   r,  r   r]   r  rM   r   LGBM_DatasetCreateFromCSRrL   r  r  rO   r  rP   rQ   )rv   r  r  r  ri  rj  rr  r  r7  r8  rk  s              r@   __init_from_csrzDataset.__init_from_csrR	  f    s{{s388},0S[[1A0B$s388}oVWW(*6szz*B'
OR%3CHH%="-yy|z)))kk(((>**_-""**6>>&..+IJ]+s3::/s388}-syy|,z"T\\*	
 r?   r  c                    t        |j                        t        |j                        k7  r7t        dt        |j                         dt        |j                               t	        j
                         | _        t        |j                        \  }}}t        |j                        \  }}}	|j                  d   t        k  sJ |j                  j                  t        j                  d      }
t        t!        j"                  |t	        j$                  |      |
j                  j'                  t	        j(                  t        j*                              |t	        j$                  |      t	        j,                  t        |j                              t	        j,                  t        |j                              t	        j,                  |j                  d         t/        |      |t	        j0                  | j                                     | S )z"Initialize data from a CSC matrix.r0  r1  r   Fr  )r   rg  rf   r   rK   r  r  r  rV  r  r   r,  r   r]   r  rM   r   LGBM_DatasetCreateFromCSCrL   r  r  rO   r  rP   rQ   )rv   r  r  r  ri  rj  rr  r  r7  r8  r~  s              r@   __init_from_csczDataset.__init_from_csct	  r4  r?   r  c                    t         rt        st        d      t        d |j                  j
                  D              st        d      t        |      }t        j                         | _
        t        t        j                  t        j                  |j                        t        j                  |j                         t        j                  |j"                        t%        |      |t        j&                  | j                                     | S )z%Initialize data from a PyArrow table.zFCannot init Dataset from Arrow without 'pyarrow' and 'cffi' installed.c              3   f   K   | ])  }t        |      xs t        |      xs t        |       + y wrD   r  r  s     r@   r   z4Dataset.__init_from_pyarrow_table.<locals>.<genexpr>	  r  r  r  )r   r   r/   r   r   r  r   r   rK   r  r  rM   r   LGBM_DatasetCreateFromArrowr  r   r   r   rP   rQ   )rv   r  r  r  r  s        r@   __init_from_pyarrow_tablez!Dataset.__init_from_pyarrow_table	  s     "n hii r_d_k_k_q_qrr\]] %U+(,,w//0 2 23 2 23z"T\\*		
 r?   other_paramsignore_keysc                     |j                         D ]  \  }}||vs|| vs	| |   |k7  s y | j                         D ]  \  }}||vs||vs	|||   k7  s y y)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.
        FTrR  )rI   r<  r=  rS  rT  s        r@   _compare_params_for_warningz#Dataset._compare_params_for_warning	  sz    0 !&&( 	!DAq#F?fQi1n 	! LLN 	!DAq#L(Aa,@ 	! r?   c                 @	   | j                   | j                  | j                  j                         }| j                         }||k7  rC| j                  ||t        j                  d            st        d       | j                  |       | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  d| j$                         n[t'        | j                  t(        j*                  d      }|j,                  j.                  sJ | j                  j                  t)        j0                  | j                  j                        j3                  t(        j*                  d	
      }t)        j4                  t)        j6                  t9        t;        |            |      | j                     d      \  }| _        t=        j>                         | _         tA        | j$                        }tC        tE        jF                  | j                  jI                         j                   |j<                  jK                  t=        jL                  t<        jN                              t=        jN                  |jP                  d         tS        |      t=        jT                  | j                                      | jV                  s| jY                          | j                  | j[                  | j                         | j                  | j]                  | j                         | j_                         ta        d      tc        | j                   td              r| j                   | j                  j                   ur| jY                          | jg                  | j                   | j                  |       n| j                  | j                  | j                  d| j                  | j                  | j                  | j                   | j"                  | jh                  | j$                  | j                         | jV                  rd| _
        | jk                         | _        | S )zsLazy init.

        Returns
        -------
        self : Dataset
            Constructed Dataset object.
        Nr  )rI   r<  r=  z1Overriding the parameters from Reference Dataset.r  )rf   rw  r  rx  rz  r{  ry  r  r  r  rI   r  rZ   r   Fr  )repeatsT)return_countsr   zLabel should not be None.r  )rf   rw  r  rx  rz  ry  r  r  r  rI   r{  )6r  r  r  r?  rN  rh  r   _update_paramsr  r  rf   rw  rx  rz  r{  ry  r  r  rI   r   r]   r  r`   r  r   r   uniquerepeatr  r   rK   r  r8  rM   r   LGBM_DatasetGetSubsetr  r  r  rO   r   rP   rQ   r  get_datar  r   r  r   r   r  r  r  get_feature_name)rv   reference_paramsrI   r  
group_infor8  r  s          r@   r  zDataset.construct	  sf    <<~~)#'>>#<#<#> *--;;%%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)4: $*??#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 OO4>>3L3LL99&*ooDIIT` : 
 **";;**#"oo!%!2!2(,(@(@;;!]]    !! 	 $ 5 5 7Dr?   c                     t        ||| |||||| j                  	      }| j                  |_        | j                  |_        |S )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.
        )rw  r  rx  rz  r{  ry  rI   r  )r-   r  r  r  )	rv   rf   rw  rx  rz  ry  rI   r{  r   s	            r@   create_validzDataset.create_valid0
  sP    N !,,

 !%!8!8
r?   c                     || j                   }t        d| | j                  | j                  || j                        }| j
                  |_        | j                  |_        t        |      |_        |S )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  rI   r  )	rI   r-   r  r  r  r  r  r  r  )rv   r  rI   r   s       r@   subsetzDataset.subsetf
  sm    & >[[F** $ 8 8,,
 !%!8!8!,/
r?   filenamec           
          t        t        j                  | j                         j                  t        t        |                         | S )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.
        )rM   r   LGBM_DatasetSaveBinaryr  r  rP   r~   rv   rP  s     r@   save_binaryzDataset.save_binary
  s=    $ 	'' ((s8}%	
 r?   c                     s S t              d fd} j                  	 |         S t        j                  t	        t         j                              t	        t                          }|dk7  rQ j                   |         j                           S t        t        j                         j                  d             S )Nc                      j                   s _         y t        j                         _        j                   j                          y rD   )rI   r   r  re  )rI   rv   s   r@   re  z&Dataset._update_params.<locals>.update
  s4    ;;$'/'<$""6*r?   r   r   r  )r   r  r   LGBM_DatasetUpdateParamCheckingrP   r8  rI   rf   r  r/   r   r   )rv   rI   re  r   s   ``  r@   rD  zDataset._update_params
  s    K&!	+ <<H  66)$++67)&12C ax99(H%%'  ((>(>(@(G(G(PQQr?   c                 `    | j                   !t        | j                        | _        d | _        | S rD   )r  r   r  rI   r   s    r@   _reverse_update_paramszDataset._reverse_update_params
  s+    <<"4#7#78DK#'D r?   
field_namec                    | j                   t        d| d      |dt        t        j                  | j                   t        |      dt        j                  d      t        j                  t        |                      | S t        |      st        |      rt        |      rJ|dk7  rt        d| d      t        |j                  D cg c]  }|j                  D ]  }|  c}}      }t        |      }t        t        j                   | j                   t        |      t        j"                  |j$                        t        j&                  |j(                        t        j&                  |j*                                     | xj,                  dz  c_        | S |dk(  rat.        j0                  }t3        |      rt5        |||	      }njt7        |      r!t9        |||	      }|j;                  d
      }n>t=        d      |dv rt.        j>                  }nt.        j@                  }t5        |||	      }|jB                  t.        j@                  k(  s|jB                  t.        j0                  k(  rtE        |      \  }}}	nF|jB                  t.        j>                  k(  rtG        |      \  }}}	nt=        d|jB                   d      |t        |   k7  rt=        d      t        t        j                  | j                   t        |      |t        j                  tI        |            t        j                  |                   | xj,                  dz  c_        | S c c}}w )a  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   ry  z,pyarrow tables are not supported for field ''r   rA  rX   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.>   rz  r{  z-Expected np.float32/64 or np.int32, met type(r  zInput type error for set_field)%r  	ExceptionrM   r   LGBM_DatasetSetFieldrP   rK   rL   _FIELD_TYPE_MAPPERr   r   r   r#   r  r   r   LGBM_DatasetSetFieldFromArrowr  r   r  r   r   r  r]   r_   r   r   r   r   rd   r   r  r^   rZ   r  r  r   )
rv   rZ  rf   r   rI  r  rZ   r  r  r8  s
             r@   	set_fieldzDataset.set_field
  s   & <<k*5NOPP<))LL:&LLOLL!3J!?@ K T"&7&= !&-$'ST^S__`%abb' &*\\!%*\\ "  ).G22LL:&NN7#3#34OOG$6$67OOG$6$67 LLALK %JJE &(UL"4((ULzzz,@ 
 22

$TZHD ::#tzzRZZ'?%3D%9"HiZZ288#%1$%7"HiKDJJ<WXYZZ*:66<==%%z"SY'Y'	
 	ws   M
c                    | j                   t        d| d      t        j                  d      }t        j                  d      } t        j                  t        j
                               }t        t        j                  | j                   t        |      t        j                  |      t        j                  |      t        j                  |                   |j                  t        |   k7  rt        d      |j                  dk(  ry|j                  t        k(  rMt        t        j                   |t        j                  t        j"                              |j                        }n|j                  t$        k(  rMt'        t        j                   |t        j                  t        j(                              |j                        }nk|j                  t*        k(  rMt-        t        j                   |t        j                  t        j.                              |j                        }nt        d      |dk(  r9| j1                         }|j2                  |z  }|d	kD  r|j5                  ||fd
      }|S )ad  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 typery  r   rX   r\   )r  r]  rK   rL   r  r  rM   r   LGBM_DatasetGetFieldrP   rQ   rR   r_  r   r  r  r   rO   r  r  r  r  r  r  r  r"  r#  )rv   rZ  r]  out_typer   arrr  num_classess           r@   	get_fieldzDataset.get_field+  s   & <<k*5NOPPll1o<<?-fnnV__-/%%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
r?   c                     | j                   |k(  r| S | j                  g| j                   || _         | j                         S |dk(  r| S | j                   dk7  rt        dt	        |              || _         | j                         S t        d      )a&  Set 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  rf   r  r   r   r/   )rv   r  s     r@   set_categorical_featurezDataset.set_categorical_featureh  s      ##'::K99 ''/+>(((**$.++v5 66:;N6O5PR ,?(((**P r?   c                    || j                   | S t        |t              rVt        | j                   t              r<|| j                   k(  r-|j                         | j                   j                         k(  r| S | j                  	|| _         | S | j
                  1|| _         | j                  | j                   | j
                  d       | S | j                  g| j                  [| j                  j
                  E|| _         | j                  | j                   | j                  j
                  | j                         | S t        d      )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  rf   r  r  r  r/   )rv   r  s     r@   _set_predictorzDataset._set_predictor  s.    !8K	?3
4??Tc8dT__,++-1R1R1TT<<'DO( ' YY"'DO--//YY! . "  *t~~/IdnnNaNaNm'DO--//^^((!.. .  	  P r?   c                 V   | j                  |j                        j                  |j                        j	                  |j
                         | j                         j                  |j                               r| S | j                  || _	        | j                         S t        d      )a  Set 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.)ri  r  r  r  rk  r  get_ref_chainintersectionrf   r  r  r/   )rv   r  s     r@   set_referencezDataset.set_reference  s     	$$Y%B%BCTT""	

.--
.,,Y-D-D-FGK99 &DN$$&&P r?   c                    |dk7  r|| _         | j                  ||dk7  rt        |      | j                         k7  r)t	        dt        |       d| j                          d      |D cg c]  }t        |       }}t        t        j                  | j                  t        t        j                  |      t        j                  t        |                         | S c c}w )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   rP   rM   r   LGBM_DatasetSetFeatureNamesr  rK   r  rL   )rv   r  r   c_feature_names       r@   r  zDataset.set_feature_name  s     6! ,D<<#(@\U[E[< D$4$4$66 -c,.?-@@RSWScScSeRffst  8DDtfTlDND00LLV__n=LL\!23  Es   )Cc                    || _         | j                  t        |t              rRt	        |j
                        dkD  rt        d      t        j                  t        |t        j                              }n*t        |      r|}nt        |t        j                  d      }| j                  d|       | j                  d      | _         | S )aT  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  rw  rA  )rw  r  r   r(   r   r  r   r]   rd   r  r^   r   r   ra  rg  )rv   rw  label_arrays      r@   r  zDataset.set_label  s     
<<#%.u}}%)$%WXX hh'7BJJ'WX"5)#/RZZgVNN7K00DJr?   c                    |_t        |      r:t        j                  t        j                  |d            j	                         rd}nt        j                  |dk(        rd}|| _        | j                  Q|Ot        |      st        |t
        j                  d      }| j                  d|       | j                  d      | _        | S )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   rx  rA  )r   r%   r   equalas_pyr]   rx  r  r   r^   ra  rg  )rv   rx  s     r@   r  zDataset.set_weight
  s    "  (>>*"2"261"=>DDF!F!$ <<#(:$V,*6(SNN8V,..2DKr?   c                     || _         | j                  *|(| j                  d|       | j                  d      | _         | S )a  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.
        ry  )ry  r  ra  rg  )rv   ry  s     r@   r  zDataset.set_init_score+  s=      %<<#
(>NN<4"nn\:DOr?   c                     || _         | j                  h|ft        |      st        |t        j
                  d      }| j                  d|       | j                  d      }|t	        j                  |      | _         | S )a  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.
        rz  rA  )	rz  r  r   r   r]   r  ra  rg  rA  )rv   rz  constructed_groups      r@   r  zDataset.set_groupA  sm    ( 
<<#(9$U+)%rxxgNNN7E* $w 7 ,WW%67
r?   c                     || _         | j                  0|.t        |t        j                  d      }| j                  d|       | S )aS  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{  rA  )r{  r  r   r]   r  ra  )rv   r{  s     r@   r   zDataset.set_position`  s?      !<<#(<(
SHNN:x0r?   c                    | j                   t        d      | j                         }t        j                  d      }d}t        j
                  d      }t        |      D cg c]  }t        j                  |       }}t        j                  |z  t        t        j                  |       }t        t        j                  | j                   t        j                  |      t        j                  |      t        j
                  |      t        j                  |      |             ||j                  k7  rt!        d      |j                  }||k  rt        |      D cg c]  }t        j                  |       }}t        j                  |z  t        t        j                  |       }t        t        j                  | j                   t        j                  |      t        j                  |      t        j
                  |      t        j                  |      |             t        |      D 	cg c]   }	||	   j                  j#                  d      " c}	S c c}w c c}w c c}	w )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/   rr  rK   rL   c_size_tr  rX  r  r4  r   rM   r   LGBM_DatasetGetFeatureNamesrQ   rR   r   r   
rv   rr  r]  reserved_string_buffer_sizerequired_string_buffer_sizer8  string_buffersptr_string_buffersactual_string_buffer_sizer   s
             r@   rI  zDataset.get_feature_namev  s    << RSS&&(ll1o&)#&,ooa&8#\abm\noWX&556QRoo$oo;c&BRBRTb>cd,,[)[) ;<89"		
 ++++UVV$?$E$E!&)BB^cdo^pqYZf99:STqNq"(//K"?#fFVFVXfBg!h00LLLL-LL-OO$=>LL!<=&	 BG{ASTAq!''..w7TT; p" r Us   !II.%I c                 ^    | j                   | j                  d      | _         | j                   S )a  Get 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.
        rw  )rw  rg  r   s    r@   r  zDataset.get_label  s(     ::0DJzzr?   c                 ^    | j                   | j                  d      | _         | j                   S )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.
        rx  )rx  rg  r   s    r@   
get_weightzDataset.get_weight  s(     ;;..2DK{{r?   c                 ^    | j                   | j                  d      | _         | j                   S )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.
        ry  )ry  rg  r   s    r@   get_init_scorezDataset.get_init_score  s(     ??""nn\:DOr?   c                    | j                   t        d      | j                  r| j                  | j                  | j                  j
                  | _        | j
                  t        | j
                  t        j                  t        j                  j                  f      r$| j
                  | j                  ddf   | _        nst        | j
                  t              r8| j
                  j                  | j                     j                         | _        n!t        | j
                  t              r-t!                | j
                  | j                  ddf   | _        nt        | j
                  t"              r| j
                  | j                     | _        nt%        | j
                        r`t'        | j
                        dkD  rHt        j(                  t+        | j-                  | j
                  | j                                    | _        n,t/        dt1        | j
                        j2                   d       d| _        | j
                  t5        d      | j
                  S )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  rf   r   r]   r   r  r  r!  r(   ilocr   r!   rL  r1   r   r   r   r   r  r   r   r:   r/   r   s    r@   rH  zDataset.get_data  s    <<FGG 1 1 =$..B\++DIyy$dii"**ell6K6K)LM $		$*;*;Q*> ?DI		<8 $		t/@/@ A F F HDI		<879 $		$*;*;Q*> ?DI		84 $		$*;*; <DI*4995#dii.1:L "d.J.J499VZVgVg.h)i jDI (dii)A)A(BBqr  %D99P  yyr?   c                     | j                   F| j                  d      | _         | j                   $t        j                  | j                         | _         | j                   S )aq  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.
        rz  )rz  rg  r]   rA  r   s    r@   	get_groupzDataset.get_group  sF     ::0DJzz%WWTZZ0
zzr?   c                 ^    | j                   | j                  d      | _         | j                   S )a&  Get 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{  rg  r   s    r@   get_positionzDataset.get_position  s(     ==  NN:6DM}}r?   c                     | j                   ]t        j                  d      }t        t	        j
                  | j                   t        j                  |                   |j                  S t        d      )zGet 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  rK   rL   rM   r   LGBM_DatasetGetNumDatarQ   rR   r/   rv   r   s     r@   r  zDataset.num_data  s\     <<#,,q/C++LLLL% 99 NOOr?   c                     | j                   ]t        j                  d      }t        t	        j
                  | j                   t        j                  |                   |j                  S t        d      )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  rK   rL   rM   r   LGBM_DatasetGetNumFeaturerQ   rR   r/   r  s     r@   rr  zDataset.num_feature#  s\     <<#,,q/C..LLLL% 99 QRRr?   featurec           	      n   | j                   t        |t              r| j                  j	                  |      }n|}t        j                  d      }t        t        j                  | j                   t        j                  |      t        j                  |                   |j                  S t        d      )aF  Get 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  indexrK   rL   rM   r   LGBM_DatasetGetFeatureNumBinrQ   rR   r/   )rv   r  feature_indexr   s       r@   feature_num_binzDataset.feature_num_bin7  s     <<#'3' $ 1 1 7 7 @ ',,q/C11LLLL/LL% 99 UVVr?   	ref_limitc                     | }t               }t        |      |k  r]t        |t              r;|j	                  |       |j
                  |j
                  |vr|j
                  }n	 |S 	 |S t        |      |k  r]|S )a  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.
        )r3  r   r   r-   r  r  )rv   r  head	ref_chains       r@   rm  zDataset.get_ref_chainW  s|    " "%%	)ny($(d#NN.T^^95T>>D   )ny( r?   c                 "   | j                   |j                   t        d      t        t        j                  | j                   |j                                | j
                  du }t        | j
                        j                  }|j
                  	d| _        n| j
                  t        | j
                  t        j                        rt        |j
                  t        j                        r2t        j                  | j
                  |j
                  f      | _        nzt        |j
                  t        j                  j                        r@t        j                  | j
                  |j
                  j                         f      | _        nt        |j
                  t               r<t        j                  | j
                  |j
                  j"                  f      | _        nt        |j
                  t$              rJt'                t        j                  | j
                  |j
                  j)                         f      | _        nRd| _        nIt        | j
                  t        j                  j                        rq| j
                  j+                         }t        |j
                  t        j                  t        j                  j                  f      r>t        j                  j                  | j
                  |j
                  f|      | _        nt        |j
                  t               rHt        j                  j                  | j
                  |j
                  j"                  f|      | _        n"t        |j
                  t$              rVt'                t        j                  j                  | j
                  |j
                  j)                         f|      | _        nd| _        nt        | j
                  t               rt,        st/        d      t        |j
                  t        j                        r4t1        | j
                  t!        |j
                        fdd      | _        n%t        |j
                  t        j                  j                        rBt1        | j
                  t!        |j
                  j                               fdd      | _        nt        |j
                  t               r+t1        | j
                  |j
                  fdd      | _        npt        |j
                  t$              rLt'                t1        | j
                  t!        |j
                  j)                               fdd      | _        n
d| _        nt        | j
                  t$              rt'                t        |j
                  t        j                        rIt%        t        j                  | j
                  j)                         |j
                  f            | _        not        |j
                  t        j                  j                        rVt%        t        j                  | j
                  j)                         |j
                  j                         f            | _        nt        |j
                  t               rRt%        t        j                  | j
                  j)                         |j
                  j"                  f            | _        nt        |j
                  t$              rVt%        t        j                  | j
                  j)                         |j
                  j)                         f            | _        nd| _        nd| _        | j
                  :dt        |j
                        j                   d	| d
}||rdndz  }t3        |       | j5                         | _        t3        d       d| _        d| _        | S )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   rM   r   LGBM_DatasetAddFeaturesFromrf   r   r:   r   r]   r   hstackr  r  r!  toarrayr(   r   r!   rL  r  	getformatr   r/   r    r   rI  r  r  r  )rv   otherwas_noneold_self_data_typesparse_formaterr_msgs         r@   add_features_fromzDataset.add_features_fromu  sB    <<5==#8ijj,,	
 99$!$))_55::DIYY"$))RZZ0ejj"**5 "		499ejj*A BDI

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

L9 "		499ejj6G6G*H IDI

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

4KTa 3 bDI

L9 % 3 3TYY

@Q@Q4R[h 3 iDI

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

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

3K'LSTcg hDI

ELL,A,AB &		<

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

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

L979 &		<

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

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

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

L9 ,RYY		8J8J8LejjNaNaNc7d-e fDI $DI 	99+D,<,E,E+FF[%&&:<  RZN`rG ! 113Z	
 $* "&r?   c           
          t        t        j                  | j                         j                  t        t        |                         | S )aK  Save 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.
        )rM   r   LGBM_DatasetDumpTextr  r  rP   r~   rS  s     r@   
_dump_textzDataset._dump_text  s=     	%% ((s8}%	
 r?   )
NNNNNr  r  NTNr  )rB   r-   )NNNNNNrD   )r  r-   rB   r-   )d   )r  r-   rB   r-   )Vr:   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  rm  r1   r   r   r  r   r  r  r  r  r  r  r  r  r  r  r&   r  r   r?  r  rM  rO  r   rT  rD  rY  _LGBM_SetFieldTypera  rg  ri  rk  ro  r  r  r  r  r  r   rI  r  r  r  rH  r  r  r  rr  r  rm  r  r  r>   r?   r@   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 	 r?   r-   c                   &   e Zd ZdZ	 	 	 	 d]deeeef      dee   dee	ee
f      dee   fdZd^d	Zd_d
Zdededd fdZdeeef   fdZdeeef   ddfdZdeeef   fdZd_dZd_dZ	 	 	 d`de	ee   ee   ef   dedededd f
dZd_dZdefdZdedd fdZdededd fdZdeeef   dd fdZ	 	 dadee   d ee   defd!Z d"e!jD                  d#e!jD                  defd$Z#d_d%Z$defd&Z%defd'Z&defd(Z'de(fd)Z)de(fd*Z*	 dbdeded+ee	e+ee+   f      dee,   fd,Z-	 dbd+ee	e+ee+   f      dee,   fd-Z.	 dbd+ee	e+ee+   f      dee,   fd.Z/	 	 	 dcd/e	ee
f   d0ee   d1ed2edd f
d3Z0	 	 ddd1ed4edd fd5Z1dedd fd6Z2	 	 	 dcd0ee   d1ed2edefd7Z3	 	 	 	 ded0ee   d1ed2ed8ee4eeef   geeef   f      deeef   f
d9Z5	 	 	 	 	 	 	 dfde6d1ed0ee   d:ed;ed<ed=ed>edede	e!jD                  e7jp                  jr                  ee7jp                  jr                     f   fd?Z:	 	 	 	 	 	 	 	 	 	 dgde;d@e<dAe(dBee   dCee=   dDee>   dEee?   dFe@dGeAdHeeeef      dIed>ededd fdJZBdKedLede(fdMZCdKedLedNe(dd fdOZDdefdPZEdee   fdQZF	 	 dhd2edRee   de!jD                  fdSZG	 	 didTe	eef   dUee	eef      dVede	eHe!jD                  e!jD                  f   e!jD                  ef   fdWZIdXedYed+ee	e+ee+   f      dee,   fdZZJdYede!jD                  fd[ZKd^d\ZLy)jr,   zBooster in LightGBM.NrI   	train_setr  r  c           	         t        j                         | _        d| _        d| _        d| _        d| _        d| _        i | _        |i n
t        |      }|t        |t              s!t        dt        |      j                         t        d|d      }|d   |j!                  dd       n|d   }t        |t"              rt%        |j'                  d	            }n>t        |t(        t*        f      rt%        |      }d	j-                  |      }nt/        d
      t        d||      }t        d|d      }| j1                  ||d   |j3                  dd      |d          |j5                          |j7                  |j9                                t;        |      }t=        t?        j@                  |j                  tC        |      t        jD                  | j                                     || _#        g | _$        g | _%        d| _&        |jN                  | _(        | jP                  =t=        t?        jR                  | j                  | jP                  j                               t        jT                  d      }t=        t?        jV                  | j                  t        jD                  |                   |jX                  | _-        dg| _.        dg| _/        | ja                          |jb                  | _1        |jd                  | _3        || _9        y|t        jT                  d      }	t=        t?        jh                  tC        t#        |            t        jD                  |	      t        jD                  | j                                     t        jT                  d      }t=        t?        jV                  | j                  t        jD                  |                   |jX                  | _-        tk        |      | _1        |rtm        d       | jo                         }|| _9        y|| jq                  |       || _9        yt        d      )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ro  rI   rp  r&  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):rK   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:   rv  rs  r~   r   r|  r   r3  r   r   set_networkrh  r  re  r  r8  rM   r   LGBM_BoosterCreaterP   rQ   r  
valid_setsname_valid_sets_Booster__num_datasetr  _Booster__init_predictorLGBM_BoosterMergerL   r  rR   _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_stringrI   )
rv   rI   r  r  r  r  num_machines_from_machine_listr  r  r  s
             r@   r   zBooster.__init__  s   ( ('+$ *',$ 68~8F+; i1"PQUV_Q`QiQiPj kll( *"F j!)

:t,!*-h,589L5M24+658]2"xx1H$%BCC,$2!"@
 -$7!"'
   %&,-@&A$*JJz3$?!'!7	 !  !MM)..01+F3J''%%:&LL. 'DN-/DO.0D !"D$-$8$8D!$$0**--55 #LLOM..LLLL/  -22DGKfD',17D(  "&/&B&BD#%.%6%6D": 9 #!'a443z?+LL!34LL. #LLOM..LLLL/  -22D&>&TD#Z[++-F  """9-
  m r?   rB   c                     	 | j                   r| j                          	 | j                  )t	        t        j                  | j                               y y # t        $ r Y Bw xY w# t        $ r Y y w xY wrD   )r  free_networkr  r  rM   r   r  r   s    r@   r  zBooster.__del__  sl    	}}!!#	||'400>? (  		
  		s"   A 4A$ 	A! A!$	A0/A0c                 $    | j                  d       S rD   )__deepcopy__r   s    r@   __copy__zBooster.__copy__  s      &&r?   rb  kwargsc                 >    | j                  d      }t        |      S )Nr  r  r  )model_to_stringr,   )rv   rb  r  r  s       r@   r  zBooster.__deepcopy__  s     ((r(:	++r?   c                     | j                   j                         }|d   }|j                  dd        |j                  dd        || j                  d      |d<   |S )Nr  r  r  r  r  )r  r   rs  r  )rv   r   r  s      r@   r  zBooster.__getstate__  s[    }}!!#id#t$"222DDOr?   statec           	      |   |j                  d|j                  dd             }|}t        j                         }t        j                  d      }t	        t        j                  t        |      t        j                  |      t        j                  |                   ||d<   | j                  j                  |       y )Nr  r  r   )rh  rK   r  rL   rM   r   LGBM_BoosterLoadModelFromStringrP   rQ   r  re  )rv   r  r  r  r  s        r@   __setstate__zBooster.__setstate__  s    IIi8T)BC	 __&F!'a449%LL!34LL(  &E)U#r?   c           	         d}t        j                  d      }t        j                  |      }t        j                  t        j                  |            }t        t        j                  | j                  t        j                  |      t        j                  |      |             |j                  }||kD  rt        j                  |      }t        j                  t        j                  |            }t        t        j                  | j                  t        j                  |      t        j                  |      |             t        j                  |j                  j                  d            S )NrP  r   r   )rK   r  rX  r  r   rM   r   LGBM_BoosterGetLoadedParamr  rQ   rR   rZ  r[  r   )rv   r\  r]  r^  r_  r`  s         r@   r  z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=>>r?   c                     | j                   j                  dd       | j                   j                  dd       d| _        | S )zFree Booster's Datasets.

        Returns
        -------
        self : Booster
            Booster without Datasets.
        r  Nr  r   )r  rs  r  r   s    r@   free_datasetzBooster.free_dataset  s9     	+t,,-r?   c                 "    g | _         g | _        | S rD   )r  r  r   s    r@   _free_bufferzBooster._free_buffer  s    &(#')$r?   r  r  r  r  c           
      (   t        |t        t        f      rdj                  |      }t	        t        j                  t        |      t        j                  |      t        j                  |      t        j                  |                   d| _
        | S )a1  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.
        r&  T)r   r   r3  r   rM   r   LGBM_NetworkInitrP   rK   rL   r  )rv   r  r  r  r  s        r@   r  zBooster.set_network  sq    2 hs,xx)H!!x ./_-\*		
 r?   c                 N    t        t        j                                d| _        | S )zFree Booster's network.

        Returns
        -------
        self : Booster
            Booster with freed network.
        F)rM   r   LGBM_NetworkFreer  r   s    r@   r  zBooster.free_network  s!     	4((*+r?   c                    t         st        d      | j                         dk(  rt        d      dt        t        t
        f   dt        fd	 	 	 	 ddt        t        t
        f   dt        dt        t           d	t        t        t              d
t        t           dt        t        t
        f   ffd	 	 	 	 ddt        t        t
        f   dt        dt        t           d	t        t        t              d
t        t           dt        t        t        t
        f      ffd| j                         }|d	   }g }|d   D ]"  }|j                   |d   |d   |             $ t        ||d   j                               S )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treerB   c                 &    d| j                         v S )Nsplit_index)rr  r  s    r@   _is_split_nodez2Booster.trees_to_dataframe.<locals>._is_split_node<  s     DIIK//r?   
node_depth
tree_indexfeature_namesparent_nodec                    dt         t        t        f   dt        t           dt        f	fd}dt         t        t        f   dt        t
        t              dt        t           f	fd}dt         t        t        f   dt        fd}t               }||d<   ||d<    || |      |d	<   d |d
<   d |d<   ||d<    || |      |d<   d |d<   d |d<   d |d<   d |d<   d |d<   d |d<   d |d<   d |d<    	|       rd || d
   |      |d
<    || d   |      |d<   | d   |d<   | d   |d<   | d   |d<   | d   rdnd|d<   | d   |d<   | d   |d<   | d   |d<   | d   |d<   |S | d   |d<    ||       s| d   |d<   | d   |d<   |S )Nr  r  rB   c                 n    || dnd} |       }|rdnd}| j                  |rdndd      }| | | S )N-r   SLr  
leaf_indexr   )rh  )r  r  tree_numis_split	node_typenode_numr  s         r@   _get_node_indexzOBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._get_node_indexF  sS     0:/Ej\+2)$/#+C	88XM<QRS"I;xj99r?   r  c                 B     |       r|
|| d      }|S | d   }|S d }|S )Nsplit_featurer>   )r  r  r  r  s      r@   _get_split_featurezRBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._get_split_featureQ  sK     "$'$0'4T/5J'K
 $# (,O'< $# $(L##r?   c                 >    t        | j                               ddhk(  S )N
leaf_value
leaf_count)r3  rr  r  s    r@   _is_single_node_treezTBooster.trees_to_dataframe.<locals>.create_node_record.<locals>._is_single_node_tree^  s    499;'L,+GGGr?   r   
node_index
left_childright_childparent_indexr  
split_gain	thresholddecision_typemissing_directionmissing_typerR   rx  countdefault_leftleftrightinternal_valueinternal_weightinternal_countr  leaf_weightr  )r   r~   r   r   r   r   r  r   )
r  r   r  r  r  r  r  r  noder  s
            r@   create_node_recordz6Booster.trees_to_dataframe.<locals>.create_node_record?  s    	:38n	:$SM	: 	:$38n$'S	2$ #$H4S> Hd H 6A]D!+D!+D!0z!BD!%D"&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%)-%8DN$($6DMKr?   c           	           | ||||      }|g} 
|       r2ddg}|D ])  } | |   |dz   |||d         }	|j                  |	       + |S )N)r  r   r  r  r  r  r  r   r  )extend)r  r   r  r  r  r'  reschildrenchildsubtree_listr  r(  tree_dict_to_node_lists             r@   r/  z:Booster.trees_to_dataframe.<locals>.tree_dict_to_node_list  s     &%%+'D &Cd#(-8% 
-E#9!%[#->#-&3$($6$L JJ|,
- Jr?   	tree_infotree_structure)r  r  r  r  )r   NNN)r   r/   	num_treesr   r~   r   r  r   r   r   
dump_modelr*  r(   rr  )rv   
model_dictr  
model_listr  r  r(  r/  s        @@@r@   trees_to_dataframezBooster.trees_to_dataframe  s   8  W 
 >>q  ^__	0c3h 	0D 	0
  (,15)-F	sCx.F	F	 !F	 $DI.	F	
 "#F	 #s(^F	T  (,15)-	sCx.		 !	 $DI.		
 "#	 $sCx.!	B __&
"?3
{+ 	D&./D<N^k	 J
10B0B0DEEr?   r   c                     || _         | S )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  )rv   r   s     r@   set_train_data_namezBooster.set_train_data_name  s     !%r?   rf   c                 2   t        |t              s!t        dt        |      j                         |j
                  | j                  urt        d      t        t        j                  | j                  |j                         j                               | j                  j                  |       | j                  j                  |       | xj                   dz  c_        | j"                  j                  d       | j$                  j                  d       | S )a  Add 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  r  r/   rM   r   LGBM_BoosterAddValidDatar  r  r  r   r  r  r  r  )rv   rf   r   s      r@   	add_validzBooster.add_valid  s     $(NtTXzObObNcdee??$"7"77 jkk)) ((	
 	t$##D)a##**40$$++E2r?   c                     t        |      }|r2t        t        j                  | j                  t        |                   | j                  j                  |       | S )zReset parameters of Booster.

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

        Returns
        -------
        self : Booster
            Booster with new parameters.
        )r8  rM   r   LGBM_BoosterResetParameterr  rP   rI   re  )rv   rI   r  s      r@   reset_parameterzBooster.reset_parameter  sO     (/
//LL:& 	6"r?   fobjc                 f   |2| j                   | j                  j                  k7  r| j                  }d}n)|| j                  u xr | j                   |j                  k(  }||st        |t              s!t        dt        |      j                         |j                  | j                  urt        d      || _        t        t        j                  | j                  | j                  j                         j                               d| j                   d<   | j                  j                  | _         t#        j$                  d      }|| j&                  rt        d      t        t        j(                  | j                  t#        j*                  |                   t-        | j.                        D cg c]  }d c}| _        |j2                  dk(  S | j&                  sd| j5                  d	d
i      _         || j7                  d      | j                        \  }}| j9                  ||      S c c}w )a%  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  r  r/   rM   r   LGBM_BoosterResetTrainingDatar  r  r  rK   rL   r  LGBM_BoosterUpdateOneIterrQ   r  r  r  rR   r?  _Booster__inner_predict_Booster__boost)rv   r  r@  is_the_same_train_setis_finishedr8  gradhesss           r@   re  zBooster.update  s   N !7!74>>;Q;Q!QI$)!$-$?$oDDZDZ^g^o^oDo! )>i1"PQUV_Q`QiQiPj kll##4+@+@@#$pqq&DN22LLNN,,.66 .2D''*%)^^%;%;D"ll1o<++#$STT..LLLL- <AASAS;T+UaE+UD($$))//VZ$$k6%:;Sd2215t~~FJD$<<d++ ,Vs   3	H.rJ  rK  c                    | j                   dkD  r$|j                  d      }|j                  d      }t        |t        j                  d      }t        |t        j                  d      }|j
                  j                  sJ |j
                  j                  sJ t        |      t        |      k7  r$t        dt        |       dt        |       d	      | j                  j                         }t        |      || j                   z  k7  r4t        dt        |       dt        |       d
| d| j                    d	      t        j                  d      }t        t        j                  | j                   |j                  j#                  t        j$                  t        j&                              |j                  j#                  t        j$                  t        j&                              t        j(                  |                   t+        | j,                        D cg c]  }d c}| _        |j0                  dk(  S c c}w )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   rX   r\   gradientrA  hessianzLengths of gradient (z) and Hessian (rq  z$) don't match training data length (z() * number of models per one iteration (r  r   F)r  rd   r   r]   r^   r`   r  r   r   r  r  rK   rL   rM   r   LGBM_BoosterUpdateOneIterCustomr  r  r  r  rQ   r  r  r  rR   )rv   rJ  rK  num_train_datarI  r8  s         r@   __boostz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'Q!'Q$  A%% (Rs   	H>c                     t        t        j                  | j                               t	        | j
                        D cg c]  }d c}| _        | S c c}w )zRollback one iteration.

        Returns
        -------
        self : Booster
            Booster with rolled back one iteration.
        F)rM   r   LGBM_BoosterRollbackOneIterr  r  r  r  )rv   r8  s     r@   rollback_one_iterzBooster.rollback_one_iter  sD     	433DLLAB7<T=O=O7P'Q!'Q$ (Rs    	Ac                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S r  r  r  s     r@   r  zBooster.current_iteration  r  r?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S )zGet number of models per iteration.

        Returns
        -------
        model_per_iter : int
            The number of models per iteration.
        r   )rK   rL   rM   r    LGBM_BoosterNumModelPerIterationr  rQ   rR   )rv   model_per_iters     r@   num_model_per_iterationzBooster.num_model_per_iteration  sH      a11^,	
 ###r?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S )zGet number of weak sub-models.

        Returns
        -------
        num_trees : int
            The number of weak sub-models.
        r   )rK   rL   rM   r   LGBM_BoosterNumberOfTotalModelr  rQ   rR   )rv   r3  s     r@   r3  zBooster.num_trees  sF     LLO	//Y'	
 r?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S )zGet upper bound value of a model.

        Returns
        -------
        upper_bound : float
            Upper bound value of the model.
        r   )rK   r  rM   r   LGBM_BoosterGetUpperBoundValuer  rQ   rR   r  s     r@   upper_boundzBooster.upper_bound  G     ooa //S!	
 yyr?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S )zGet lower bound value of a model.

        Returns
        -------
        lower_bound : float
            Lower bound value of the model.
        r   )rK   r  rM   r   LGBM_BoosterGetLowerBoundValuer  rQ   rR   r  s     r@   lower_boundzBooster.lower_bound  r_  r?   fevalc                 F   t        |t              st        d      d}|| j                  u rd}n;t	        t        | j                              D ]  }|| j                  |   u s|dz   } n |dk(  r!| j                  ||       | j                  dz
  }| j                  |||      S )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   r  r<  r  _Booster__inner_eval)rv   rf   r   rc  data_idxr   s         r@   evalzBooster.eval  s    L $(@AA4>>!H3t/0 4??1-- 1uH
 r>NN4&))A-H  x77r?   c                 <    | j                  | j                  d|      S )aO  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   )re  r  )rv   rc  s     r@   
eval_trainzBooster.eval_train  s     @   !6!65AAr?   c           	          t        d| j                        D cg c],  }| j                  | j                  |dz
     ||      D ]  }| . c}}S c c}}w )aX  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  r  re  r  )rv   rc  r   r"  s       r@   
eval_validzBooster.eval_valid:  se    D 1d001
))$*>*>q1u*Eq%P
  

 	
 
s   1ArP  r  r  importance_typec                 N   || j                   }t        |   }t        t        j                  | j
                  t        j                  |      t        j                  |      t        j                  |      t        t        |                         t        | j                  |       | S )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.
        )r  _FEATURE_IMPORTANCE_TYPE_MAPPERrM   r   LGBM_BoosterSaveModelr  rK   rL   rP   r~   r  r  )rv   rP  r  r  rl  importance_type_ints         r@   
save_modelzBooster.save_model`  s    :   //M=oN&&_-]+01s8}%	
 	!!8!8(Cr?   end_iterationc           	          t        t        j                  | j                  t	        j
                  |      t	        j
                  |                   | S )a  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.
        )rM   r   LGBM_BoosterShuffleModelsr  rK   rL   )rv   r  rr  s      r@   shuffle_modelszBooster.shuffle_models  s@    ( 	**_-]+	
 r?   c           	      j   t        t        j                  | j                               | j	                          t        j                         | _        t        j                  d      }t        t        j                  t        |      t        j                  |      t        j                  | j                                     t        j                  d      }t        t        j                  | j                  t        j                  |                   |j                  | _        t        |      | _        | S )zLoad Booster from a string.

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

        Returns
        -------
        self : Booster
            Loaded Booster object.
        r   r  )rM   r   r  r  r  rK   r  rL   r  rP   rQ   r  rR   r  r  r  )rv   r  r  r  s       r@   r  zBooster.model_from_string  s     	4((67(#\\!_00y!/0T\\*	
 Q**]+	
 )..":Y"Or?   c                    || j                   }t        |   }d}t        j                  d      }t        j                  |      }t        j
                  t        j                  |            }t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      |             |j                  }	|	|kD  rt        j                  |	      }t        j
                  t        j                  |            }t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |	      t        j                  |      |             |j                  j                  d      }
|
t        | j                         z  }
|
S )aN  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.
        rP  r   r   )r  rn  rK   r  rX  r  r   rM   r   LGBM_BoosterSaveModelToStringr  rL   rQ   rR   r   r  r  )rv   r  r  rl  rp  r\  r]  r^  r_  r`  r   s              r@   r  z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'(?(?@@
r?   rW  c                    || j                   }t        |   }d}t        j                  d      }t        j                  |      }t        j
                  t        j                  |            }	t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      |	             |j                  }
|
|kD  rt        j                  |
      }t        j
                  t        j                  |            }	t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |
      t        j                  |      |	             t        j                  |j                  j!                  d      |      }t        j                  t        j"                  | j$                  t&                    |d<   |S )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.
        rP  r   r   rV  r  r  )r  rn  rK   r  rX  r  r   rM   r   LGBM_BoosterDumpModelr  rL   rQ   rR   rZ  r[  r   r  r  r$  )rv   r  r  rl  rW  rp  r\  r]  r^  r_  r`  r   s               r@   r4  z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%
 ! 
r?   r  r  r  r  r  c	           
          t         j                  | t        |	            }
||dk  r| j                  }nd}|
j	                  ||||||||      S )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  )rf   r  r  r  r  r  r  r  )r  r  r   r  r*  )rv   rf   r  r  r  r  r  r  r  r  r  s              r@   r*  zBooster.predict]  su    r $00#F+ 1 
	  !# $ 3 3 "  +'%+/ ! 	
 		
r?   rw  
decay_rater  rx  rz  ry  r  r  r  r  c                    | j                   rt        d      |
i }
t        j                  | t	        |            }|j                  |dd|      }|j                  \  }}t        j                  d      }t        t        j                  | j                  t        j                  |                   t        d| j                  d	      }t!        |j"                        |d<   |j%                  |
       t'        ||||||||	||

      }||d<   t)        ||      }t        t        j*                  |j                  |j                               |j-                  d      }t/        |      \  }}}t        t        j0                  |j                  |t        j2                  |      t        j2                  |                   | j4                  |_        |S )ar  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)rf   r  r  r  r   r  r  )
rf   rw  r  rx  rz  ry  r  r  rI   r  refit_decay_rate)r  r/   r  r  r   r*  r   rK   rL   rM   r   LGBM_BoosterGetLinearr  rQ   rv  rI   r  rR   re  r-   r,   r  r#  r  LGBM_BoosterRefitrO   r  )rv   rf   rw  r}  r  rx  rz  ry  r  r  r  r  r  r  r  
leaf_predsr'  r  out_is_linear
new_paramsr  new_boosterr  r8  s                           r@   refitz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$		
  $}}r?   tree_idleaf_idc           
         t        j                  d      }t        t        j                  | j
                  t        j                  |      t        j                  |      t        j                  |                   |j                  S )a#  Get 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   )	rK   r  rM   r   LGBM_BoosterGetLeafValuer  rL   rQ   rR   )rv   r  r  r   s       r@   get_leaf_outputzBooster.get_leaf_outputF  s_     ooa ))W%W%S!		
 yyr?   rR   c           
          t        t        j                  | j                  t	        j
                  |      t	        j
                  |      t	        j                  |                   | S )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.
        )rM   r   LGBM_BoosterSetLeafValuer  rK   rL   r  )rv   r  r  rR   s       r@   set_leaf_outputzBooster.set_leaf_output`  sL    0 	))W%W%&		
 r?   c                     t        j                  d      }t        t        j                  | j
                  t        j                  |                   |j                  S )zGet number of features.

        Returns
        -------
        num_feature : int
            The number of features.
        r   )rK   rL   rM   r   LGBM_BoosterGetNumFeaturer  rQ   rR   )rv   out_num_features     r@   rr  zBooster.num_feature  sH     !,,q/**_-	
 $$$r?   c                    | j                         }t        j                  d      }d}t        j                  d      }t	        |      D cg c]  }t        j
                  |       }}t        j                  |z  t        t        j                  |       }t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |      |             ||j                  k7  rt        d      |j                  }||k  rt	        |      D cg c]  }t        j
                  |       }}t        j                  |z  t        t        j                  |       }t        t        j                  | j                  t        j                  |      t        j                  |      t        j                  |      t        j                  |      |             t	        |      D 	cg c]   }	||	   j                  j!                  d      " c}	S c c}w c c}w c c}	w )zGet names of features.

        Returns
        -------
        result : list of str
            List with names of features.
        r   r  r  r   )rr  rK   rL   r  r  rX  r  r4  r   rM   r   LGBM_BoosterGetFeatureNamesr  rQ   rR   r   r   r  s
             r@   r  zBooster.feature_name  s    &&(ll1o&)#&,ooa&8#\abm\noWX&556QRoo$oo;c&BRBRTb>cd,,[)[) ;<89"		
 ++++UVV$?$E$E!&)BB^cdo^pqYZf99:STqNq"(//K"?#fFVFVXfBg!h00LLLL-LL-OO$=>LL!<=&	 BG{ASTAq!''..w7TT; p" r Us   
H?I%I		iterationc                     || j                   }t        |   }t        j                  | j	                         t        j
                        }t        t        j                  | j                  t        j                  |      t        j                  |      |j                  j                  t        j                  t        j                                           |t        k(  r|j!                  t        j"                        S |S )a  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   )r  rn  r]   r5  rr  r_   rM   r   LGBM_BoosterFeatureImportancer  rK   rL   r  r  r  _C_API_FEATURE_IMPORTANCE_SPLITr   r  )rv   rl  r  rp  results        r@   feature_importancezBooster.feature_importance  s    . ++I=oN$**,BJJ?..Y'01%%fnnV__&EF		
 "AA==**Mr?   r  binsxgboost_stylec                    dt         t        t        f   ddffd| j                         }|j	                  d      |d   }g |D ]  } |d           |t        |t              r:|r8t        t        j                              }t        |t        ||      n|d      }t        j                  |	      \  }}	|r@t        j                  |	dd |f      }
|
|
dddf   d
kD     }
t        rt        |
ddg      S |
S ||	fS )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.
        rootrB   Nc                     d| v rnt        t              r	| d      }n| d   }|k(  r2t        | d   t              rt        d      j                  | d           | d           | d          yy)zRecursively add thresholds.r  Nr  r  z@Cannot compute split value histogram for the categorical featurer  r  )r   r~   r/   r   )r  r  r  r  r  r   s     r@   r  z.Booster.get_split_value_histogram.<locals>.add  s    $ ,GS1I$1$2G$HM$($9M G+!${"3S9+,nood;&78D&'D'( %r?   r  r0  r1  r   )r  r   
SplitValueCountr2  )r   r~   r   r4  rh  r   r   r   r]   rE  r  r  	histogramcolumn_stackr   r(   )rv   r  r  r  model
tree_infosr0  n_uniquehist	bin_edgesr   r  r  r   s    `         @@@r@   get_split_value_histogramz!Booster.get_split_value_histogram  s   N	)d38n 	) 	) 	) !		/2;'
 # 	-I	*+,	- <:dC0]299V,-Hd.>s8T*HaPD,,vD9i//9QR=$"78Cc!Q$i!m$C#C,1HII
?"r?   	data_namerf  c                 @   || j                   k\  rt        d      | j                          g }| j                  dkD  r?t	        j
                  | j                  t        j                        }t        j                  d      }t        t        j                  | j                  t        j                  |      t        j                  |      |j                  j                  t        j                  t        j                                            |j"                  | j                  k7  rt        d      t%        | j                        D ]4  }|j'                  || j(                  |   ||   | j*                  |   f       6 t-        |      r|g}||dk(  r| j.                  }n| j0                  |dz
     }|D ]i  }	|	 |	| j3                  |      |      }
t5        |
t6              r!|
D ]  \  }}}|j'                  ||||f        O|
\  }}}|j'                  ||||f       k |S )z%Evaluate training or validation data.1Data_idx should be smaller than number of datasetr   r   zWrong length of eval resultsr   )r  r   r  _Booster__num_inner_evalr]   r5  r_   rK   rL   rM   r   LGBM_BoosterGetEvalr  rQ   r  r  r  rR   r  r   _Booster__name_inner_eval"_Booster__higher_better_inner_evalr   r  r  rF  r   r   )rv   r  rf  rc  r   r  r]  r   cur_dataeval_function	feval_ret	eval_namer(  is_higher_betters                 r@   __inner_evalzBooster.__inner_eval2  s    t)))PQQ  1$XXd332::FF ,,q/K((LLLL*LL-MM))&..*IJ	   D$9$99 !?@@4001 r

It'='=a'@&)TMlMlmnMopqrE?GE1}>>??8a<8!& 	N ()$*>*>x*H(S	i.<E R8	3(8

Iy#?O#PQR 8A4Is$4JJ	9c;KLM	N 
r?   c           	         || j                   k\  rt        d      | j                  |   |dk(  r(| j                  j	                         | j
                  z  }n-| j                  |dz
     j	                         | j
                  z  }t        j                  |t        j                        | j                  |<   | j                  |   st        j                  d      }| j                  |   j                  j                  t        j                  t        j                              }t!        t#        j$                  | j&                  t        j(                  |      t        j*                  |      |             |j,                  t/        | j                  |         k7  rt        d|       d| j                  |<   | j                  |   }| j
                  dkD  r7|j0                  | j
                  z  }|j3                  || j
                  d      }|S )	z,Predict for training and validation dataset.r  r   r   r   z)Wrong length of predict results for data TrX   r\   )r  r   r  r  r  r  r  r]   r5  r_   r  rK   r  r  r  r  rM   r   LGBM_BoosterGetPredictr  rL   rQ   rR   r   r"  r#  )rv   rf  r.  r]  r  r  r  s          r@   __inner_predictzBooster.__inner_predict_  s   t)))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^^Hd.>.>c^JFr?   c                    | j                   r,d| _         t        j                  d      }t        t	        j
                  | j                  t        j                  |                   |j                  | _	        | j                  dkD  rt        j                  d      }d}t        j                  d      }t        | j                        D cg c]  }t        j                  |       }}t        j                  | j                  z  t        t        j                  |       }t        t	        j                   | j                  t        j                  | j                        t        j                  |      t        j                  |      t        j                  |      |             | j                  |j                  k7  rt#        d      |j                  }||k  rt        | j                        D cg c]  }t        j                  |       }}t        j                  | j                  z  t        t        j                  |       }t        t	        j                   | j                  t        j                  | j                        t        j                  |      t        j                  |      t        j                  |      |             t        | j                        D 	cg c]   }	||	   j                  j%                  d      " c}	| _        | j&                  D 
cg c]  }
|
j)                  d       c}
| _        yyyc c}w c c}w c c}	w c c}
w )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  rK   rL   rM   r   LGBM_BoosterGetEvalCountsr  rQ   rR   r  r  r  rX  r  r4  r   LGBM_BoosterGetEvalNamesr   r   r  r  r  )rv   out_num_evalr]  r  r  r8  r  r  r  r   r   s              r@   __get_eval_infozBooster.__get_eval_info~  s   ''+0D(!<<?L..LLLL. %1$6$6D!$$q($ll1o.1+.4ooa.@+V[\`\q\qVr"QRF//0KL" " '-oo8M8M&MPSTZTdTdftPu%v"11T%:%:;[1(CD%@A*	 ((K,=,==$%XYY,G,M,M).1JJX]^b^s^sXt&ST334MN&N & +1//D<Q<Q*QV--~>*& 55 LL"LL)>)>?"LL5"OO,EF"LL)DE.	 \aaeavav[w)xVW.*;*A*A*H*H*Q)x&_c_u_u3W[DOO$QR3/S ) ( "&&  *y3s   
L;.M %MM
)NNNNr  )rB   r,   )r  r  r   NNrD   )Nr   r|  )r   r  )Nr   r|  N)r   NFFFFF)
g?NNNNr  r  NTF)r|  N)NF)Mr:   r;   r<   r=   r   r   r~   r   r-   r   r   r   r  r  r  r  r  r  r  r  r   r   r   r  r  r(   r7  r9  r<  r?  _LGBM_CustomObjectiveFunctionr  re  r]   r   rG  rT  r  rY  r3  r   r^  rb  _LGBM_CustomEvalFunction!_LGBM_BoosterEvalMethodResultTyperg  ri  rk  rq  ru  r  r  r   r4  r  r  r  r!  r*  r  r  r  r  r  r  r  r  r  r  rr  r  r  r   r  re  rF  r  r>   r?   r@   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r?   r,   )rw   r}   r  rD   r  )r=   libpathr   r  rK   r  rZ  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.sparser  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  r  r!  r  r  r  r  r  rE   _MULTICLASS_OBJECTIVESr]  r/   rG   rT   rg   ri   rq   r   r   r   r   r   r0   r   r   r   r   bytesr   rh  r  r   restype	CFUNCTYPEcallbackLGBM_RegisterLogCallbackr   r5  rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rP   r   Arrayr  r$  r-  r8  r:  FutureWarningr.   rL  rN  rv  r,  r  r  r  r  ra   rb   r  r  r  r  ro  r}  r  _C_API_FEATURE_IMPORTANCE_GAINr_  rn  r  r  r  r  r   r  r  r  r  ABCr1   r  r-   r  r  r,   r>   r?   r@   <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 * * w{{'/%+__D"vfoo6H]+DM$t$$T]]3q82D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   ![ [&%[&