
    ri             &          d Z ddlZddl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mZmZmZmZmZmZmZ ddlmZ ddlZddlmZ d	d
lmZmZmZm Z 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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 d	dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= g dZ>ee*e-e.f         Z?ee*e-f         Z@ee*e.f         ZAeejB        e1e2ejC        f         ZDeeejE                 eejF                 eejG                 eejH                 f         ZI G d d          ZJdeeJeKf         fdZL G d de          ZMdee&         de&fdZNde&deeO         deeeOe'f         eeOeKf         f         fdZPdeeD         deDfdZQdedeee                  fdZRde6deeO         de6fdZSdeeOef         d ee6         d!eeeOeDf                  d"eOd#eKd$eKd%eTd&eKd'eJd(edee6         fd)ZUd*e?d+eTdeeD         fd,ZVd"eOd-eeO         deeOeKf         fd.ZW	 	 	 	 	 	 	 	 	 	 	 dOde&d*e@d/e?deeOef         d ee6         d0eeA         d1ee?         d2eeA         d3eeee@e?f                           d4eeeO                  d5eeeA                  d6eeeeXeOf                           d7eee?                  d8eeeA                  d9ee:         d:eeeeK         eeKd;f         f                  d(ede6f$d<ZYd=eDd>e6d?eTd@eTdAeTdBeTd(edeDfdCZZdDdDdDdDejE        fd>e6d*e@de&d?eTd@eTdAeTdBeTdEeId(edee*ee*         f         fdFZ[ G dG dH          Z\ G dI dJe5e\          Z] G dK dLe8e\          Z^ G dM dNe7e\          Z_dS )PzDistributed training with LightGBM and dask.distributed.

This module enables you to perform distributed training with LightGBM on
dask.Array and dask.DataFrame collections.

It is based on dask-lightgbm, which was based on dask-xgboost.
    N)defaultdict)deepcopy)Enumauto)partial)AnyDictIterableListOptionalTupleTypeUnion)urlparse   )LightGBMError_choose_param_value_ConfigAliases	_log_info_log_warning)DASK_INSTALLEDPANDAS_INSTALLEDSKLEARN_INSTALLEDClientFutureLGBMNotFittedErrorconcat
dask_Arraydask_array_from_delayeddask_bag_from_delayeddask_DataFramedask_Seriesdefault_clientdelayedpd_DataFrame	pd_Serieswait)	LGBMClassifier	LGBMModel
LGBMRankerLGBMRegressor#_LGBM_ScikitCustomObjectiveFunction_LGBM_ScikitEvalMetricType_lgbmmodel_doc_custom_eval_note_lgbmmodel_doc_fit_lgbmmodel_doc_predict)DaskLGBMClassifierDaskLGBMRankerDaskLGBMRegressorc                   "    e Zd ZdefdZddZdS )_RemoteSocketreturnc                 0   t          j         t           j        t           j                  | _         | j                             t           j        t           j        d           | j                             d           | j                                         d         S )Nr   ) r   )socketAF_INETSOCK_STREAM
setsockopt
SOL_SOCKETSO_REUSEADDRbindgetsocknameselfs    c/var/www/html/pippo.cuttalo.com/services/trading/venv/lib/python3.11/site-packages/lightgbm/dask.pyacquirez_RemoteSocket.acquireD   si    mFNF4FGGv0&2EqIII!!!{&&((++    Nc                 8    | j                                          d S N)r9   closerA   s    rC   releasez_RemoteSocket.releaseJ   s    rE   )r6   N)__name__
__module____qualname__intrD   rI    rE   rC   r5   r5   C   sC        , , , , ,     rE   r5   r6   c                  N    t                      } |                                 }| |fS rG   )r5   rD   )sports     rC   _acquire_portrR   N   s!    A99;;Dd7NrE   c                   b    e Zd ZdZ e            Z e            Z e            Z e            ZdS )_DatasetNameszPlaceholder names used by lightgbm.dask internals to say 'also evaluate the training data'.

    Avoid duplicating the training data when the validation set refers to elements of training data.
    N)	rJ   rK   rL   __doc__r   TRAINSETSAMPLE_WEIGHT
INIT_SCOREGROUPrN   rE   rC   rT   rT   T   sF         
 tvvHDFFMJDFFEEErE   rT   clientc                 &    | t                      S | S )zChoose a Dask client to use.

    Parameters
    ----------
    client : dask.distributed.Client or None
        Dask client.

    Returns
    -------
    client : dask.distributed.Client
        A Dask client.
    )r#   rZ   s    rC   _get_dask_clientr]   `   s     ~rE   workersc                 n   i }|D ]$}|                      t          |gdd          ||<   %i }i }|                                D ][\  }}|                      t          j        d          |          ||<   |                      t          j        d          |          ||<   \|                     |          }||fS )a  Assign an open port to each worker.

    Returns
    -------
    worker_to_socket_future: dict
        mapping from worker address to a future pointing to the remote socket.
    worker_to_port: dict
        mapping from worker address to an open port in the worker's host.
    F)r^   allow_other_workerspurer   r   )submitrR   itemsoperator
itemgettergather)rZ   r^   worker_to_futureworkerworker_to_socket_futureworker_to_port_futuresocket_futureworker_to_ports           rC   _assign_open_ports_to_workersrm   s   s      
 
#)==H %	 $1 $
 $
   !!1!7!7!9!9 ] ]*0--8KA8N8NP]*^*^'(.h6I!6L6Lm(\(\f%% ]]#899N"N22rE   seqc                    t          | d         t          j                  rt          j        | d          S t          | d         t          t
          f          rt          | d          S t          | d         t          j                  rt          j	        | d          S t          dt          | d                   j         d          )Nr   )axiscsrformatzXData must be one of: numpy arrays, pandas dataframes, sparse matrices (from scipy). Got .)
isinstancenpndarrayconcatenater%   r&   r   ssspmatrixvstack	TypeErrortyperJ   )rn   s    rC   _concatr~      s    #a&"*%% 	
~c****	CF\95	6	6 
c""""	CFBK	(	( 
yU++++gklopqlrgsgsg|
 
 	
rE   argsc                      d | D             S )Nc                 &    g | ]}d  |D             S )c                     g | ]}||S rG   rN   ).0zs     rC   
<listcomp>z3_remove_list_padding.<locals>.<listcomp>.<listcomp>   s    ---1q}Q}}}rE   rN   )r   args     rC   r   z(_remove_list_padding.<locals>.<listcomp>   s'    >>>#----->>>rE   rN   )r   s    rC   _remove_list_paddingr      s    >>>>>>rE   
lgbm_modelrequired_namesc                 \    |D ](}|| j         vr
i | j         |<   || j        vr
i | j        |<   )| S )a  Append missing (key, value) pairs to a LightGBM model's evals_result_ and best_score_ OrderedDict attrs based on a set of required eval_set names.

    Allows users to rely on expected eval_set names being present when fitting DaskLGBM estimators with ``eval_set``.
    )evals_result_best_score_)r   r   	eval_names      rC   _pad_eval_namesr      sP    
 $ 3 3	J44424J$Y/J22202J"9-rE   paramsmodel_factorylist_of_partsmachineslocal_listen_portnum_machinesreturn_modeltime_outremote_socketkwargsc	                 
  ()* ||||d}
|                      |
           t          |t                    }t          d |D                       }t          d |D                       }d|d         v rt          d |D                       }nd }d|d         v rt          d |D                       }nd }d	|d         v rt          d
 |D                       }nd }t	          d |D                       }|	                    dd           )|	                    d          (d }d }d }d }d }|rft          d |D                       }t          d |D                       }g }g }|rg }|rg }|rg }g *t          |          D ]}g }g }g }g }g }|D ]} |                     d          s)r	)|         }!nd| }!| d         |         }"|"t          j
        u r7|                    | d                    |                    | d                    n6|                    |"d                    |                    |"d                    |!|vr|                    |!           |                     d          }#|#rK|#|         t          j        u r|                    | d                    n|                    |#|                    |                     d          }$|$rK|$|         t          j        u r|                    | d	                    n|                    |$|                    |                     d          }%|%rL|%|         t          j        u r|                    | d                    |                    |%|                    t!          |||||          \  }}}}}|r2|                    t          |          t          |          f           n*                    |           g|r"|                    t          |                     |r"|                    t          |                     |r"|                    t          |                     Ո*fdt          |          D             }&)r)fd|&D             }(r(fd|&D             |	d<    |d i | }'||                                 	 |r |'j        ||f||||||||d|	 n |'j        ||f||||||d|	 t'          |'dd          r|'j                                         n0# t'          |'dd          r|'j                                         w w xY w|rt-          |'|          }'|r|'nd S )!N)r   r   r   r   c                     g | ]
}|d          S )datarN   r   xs     rC   r   z_train_part.<locals>.<listcomp>   s    555!AfI555rE   c                     g | ]
}|d          S )labelrN   r   s     rC   r   z_train_part.<locals>.<listcomp>   s    777AQwZ777rE   weightr   c                     g | ]
}|d          S )r   rN   r   s     rC   r   z_train_part.<locals>.<listcomp>   s    ===!!H+===rE   groupc                     g | ]
}|d          S )r   rN   r   s     rC   r   z_train_part.<locals>.<listcomp>   s    ;;;7;;;rE   
init_scorec                     g | ]
}|d          S )r   rN   r   s     rC   r   z_train_part.<locals>.<listcomp>   s    EEE!aoEEErE   c              3   \   K   | ]'}t          |                    d g                     V  (dS )eval_setN)lengetr   s     rC   	<genexpr>z_train_part.<locals>.<genexpr>   s8      DD#aeeJ++,,DDDDDDrE   
eval_nameseval_class_weightc              3   D   K   | ]}|                     d           duV  dS )eval_sample_weightNr   r   s     rC   r   z_train_part.<locals>.<genexpr>   s5      $d$dQRQUU+?%@%@%L$d$d$d$d$d$drE   c              3   D   K   | ]}|                     d           duV  dS )eval_init_scoreNr   r   s     rC   r   z_train_part.<locals>.<genexpr>   s4      !^!^1!%%(9":":$"F!^!^!^!^!^!^rE   r   valid_r   r   r   r   r   
eval_groupc                     g | ]}|v|	S rN   rN   )r   imissing_eval_component_idxs     rC   r   z_train_part.<locals>.<listcomp>;  s$    ___A1D^;^;^a;^;^;^rE   c                      g | ]
}|         S rN   rN   )r   r   r   s     rC   r   z_train_part.<locals>.<listcomp>=  s    JJJ!
1JJJrE   c                      g | ]
}|         S rN   rN   )r   r   r   s     rC   r   z_train_part.<locals>.<listcomp>?  s    *\*\*\A+<Q+?*\*\*\rE   )sample_weightr   r   r   r   r   r   r   )r   r   r   r   r   r   fitted_F)r   rN   )update
issubclassr*   r~   maxpopr   anyrangerT   rV   appendextendrW   rX   rY   r   rI   fitgetattrbooster_free_networkr   )+r   r   r   r   r   r   r   r   r   r   network_params	is_rankerr   r   r   r   r   n_evalslocal_eval_setlocal_eval_nameslocal_eval_sample_weightlocal_eval_init_scorelocal_eval_grouphas_eval_sample_weighthas_eval_init_scoreevals_result_namesr   x_ey_ew_einit_score_eg_epartevals_result_namer   eval_weightr   r   eval_component_idxmodelr   r   r   s+                                           @@@rC   _train_partr      s    .$	 N MM.!!!=*55I 55}55566D7777788E=###==}===>>-""";;];;;<<}Q'''EE}EEEFF


 DDmDDDDDGL$//J

#677N#  V]!$$d$dVc$d$d$d!d!d!!^!^P]!^!^!^^^! 	*')$ 	'$&! 	"! &(" w >	6 >	6ACCCLC% )2 )2xx
++   5(21%%(4%
+A.}555JJtF|,,,JJtG}----JJx{+++JJx{+++$,>>>&--.?@@@"hh';<< 3"1~)DDD

4>2222

;q>222"&((+<"="=" @&q)]-EEE$++D,>????$++OA,>???!XXl33
 2!!}(;;;

4=1111

:a=111 0DCcS_ad/e/e,Cc< %%ws||WS\\&BCCCC*11!444 >(//=== D%,,W\-B-BCCC 6 ''555 `___w___ 	KJJJJ7IJJJ 	]*\*\*\*\I[*\*\*\F&'M##F##E * 	EI %%'#; 5++      EI
 %%'#; 5+
 
 
 
 
 5)U++ 	*N''))) 5)U++ 	*N''))))	*  J6HIII *55d*s   /1T -T8r   	is_matrixc                    |                                  }t          |t          j                  rZ|r|j        d         dk    sJ n|j        dk    s|j        d         dk    sJ |                                                                }|S )Nr   )
to_delayedru   rv   rw   shapendimflattentolist)r   r   partss      rC   _split_to_partsr   k  s    OOE%$$ ) 	:;q>Q&&&&&:??ek!n&9&9&9&9&&((LrE   worker_addressesc                    |                      d          }t          t          |                    t          |          k    rt          d|  d          t	          t                    }|D ]B}|                     d          \  }}||                             t          |                     Ci }|D ]H}t          |          j        }|st          d| d          ||         	                                ||<   I|S )a  Create a worker_map from machines list.

    Given ``machines`` and a list of Dask worker addresses, return a mapping where the keys are
    ``worker_addresses`` and the values are ports from ``machines``.

    Parameters
    ----------
    machines : str
        A comma-delimited list of workers, of the form ``ip1:port,ip2:port``.
    worker_addresses : list of str
        An iterable of Dask worker addresses, of the form ``{protocol}{hostname}:{port}``, where ``port`` is the port Dask's scheduler uses to talk to that worker.

    Returns
    -------
    result : Dict[str, int]
        Dictionary where keys are work addresses in the form expected by Dask and values are a port for LightGBM to use.
    ,z Found duplicates in 'machines' (zA). Each entry in 'machines' must be a unique IP-port combination.:z/Could not parse host name from worker address '')
splitr   set
ValueErrorr   addrM   r   hostnamer   )	r   r   machine_addressesmachine_to_portaddresshostrQ   outworker_hosts	            rC   _machines_to_worker_mapr   v  s   $ !s++
3 !!""c*;&<&<<<zxzzz
 
 	
 "#&&O$ - -]]3''
d!!#d)),,,,
C# : :w''0 	[YwYYYZZZ&{37799GJrE   r   r   r   r   r   r   r   r   r   r   eval_metriceval_at.c           
         ABCDEFG t                    t          fdt          j        d          D                       }t          fdt          j        d          D                       }t	          dd          h d}d         |vrt          d	d          d
           dd<   t          j        dd          D ].}|v r(t          d| d                               |           /t          |d          }t          |d          }d t          ||          D             }t          |          }|4t          |d          }t          |          D ]}||         ||         d<   |4t          |d          }t          |          D ]}||         ||         d<   |4t          |d          }t          |          D ]}||         ||         d<   |rLt          d |D                       }t          t                    }|
rt          t                    }|rt          t                    } |rt          t                    }!t          |          D ]n\  }\  }"}#|"j        }$|"|u r<|#|u r8t          |          D ]'}%||%                             t"          j                   (nt          |"d          }&t          |#d          }'t          |          D ]}(|(|z  }%|(|$k     r|&|(         })|'|(         }*nd})d}*|(|k     r ||%                             |)g|*gf           H||%         d         d                             |)           ||%         d         d                             |*           |
r|
|         |u r8t          |          D ]'}%||%                             t"          j                   (nt          |
|         d          }+t          |          D ]\}(|(|$k     r	|+|(         },nd},|(|z  }%|(|k     r||%                             |,g           ;||%         d                             |,           ]|r||         |u r8t          |          D ]'}%|!|%                             t"          j                   (nt          ||         d          }-t          |          D ]\}(|(|$k     r	|-|(         }.nd}.|(|z  }%|(|k     r|!|%                             |.g           ;|!|%         d                             |.           ]|r||         |u r9t          |          D ]'}%| |%                             t"          j                   (t          ||         d          }/t          |          D ]\}(|(|$k     r	|/|(         }0nd}0|(|z  }%|(|k     r| |%                             |0g           ;| |%         d                             |0           ]p|                                D ]I\  }%}1|1||%         d<   |
r||%         ||%         d<   |r|!|%         ||%         d<   |r| |%         ||%         d<   Jt          t/          t0          |                    }                     |          }t5          |           |D ]}2|2j        dk    r|2c S d  |D             }3                     |          }4t          t                    }5|4                                D ]@\  }6}7|5t;          t=          |7                                                 |3|6                    A|rA|5D ]>}8d}9|5|8         D ]}2d|2                                v rd}9 n|9st          d!|8 d"           ?|	r|	d#<   |r|d$<   |r|d%<   |r|d&<   t;          t=          |5                    C                                  Ft	          dd'                              d          At	          dd                              d          Bi G|5!                                }:B!tE          d(           tG          B|:)          En|r[tE          d*           d+ |:D             };t          |;          t          |:          k     rd,}<tI          |<          Afd-|:D             EnAtE          d.           tK           t          |5!                                                    \  GEd/&                    d0 E                                D                       Bt          E          D BCDEFGf
d1|5                                D             }= '                    |=          }>d2 |>D             }>|>d         }?|s2t          j        d          D ]}@|?j(                            |@d           |s2t          j        d          D ]}@|?j(                            |@d           t          j        dd3          D ]}@|?j(                            |@d           |?S )4a  Inner train routine.

    Parameters
    ----------
    client : dask.distributed.Client
        Dask client.
    data : Dask Array or Dask DataFrame of shape = [n_samples, n_features]
        Input feature matrix.
    label : Dask Array, Dask DataFrame or Dask Series of shape = [n_samples]
        The target values (class labels in classification, real numbers in regression).
    params : dict
        Parameters passed to constructor of the local underlying model.
    model_factory : lightgbm.LGBMClassifier, lightgbm.LGBMRegressor, or lightgbm.LGBMRanker class
        Class of the local underlying model.
    sample_weight : Dask Array or Dask Series of shape = [n_samples] or None, optional (default=None)
        Weights of training data. Weights should be non-negative.
    init_score : Dask Array or Dask Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task), or Dask Array or Dask DataFrame of shape = [n_samples, n_classes] (for multi-class task), or None, optional (default=None)
        Init score of training data.
    group : Dask Array or Dask Series 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.
    eval_set : list of (X, y) tuples of Dask data collections, or None, optional (default=None)
        List of (X, y) tuple pairs to use as validation sets.
        Note, that not all workers may receive chunks of every eval set within ``eval_set``. When the returned
        lightgbm estimator is not trained using any chunks of a particular eval set, its corresponding component
        of ``evals_result_`` and ``best_score_`` will be empty dictionaries.
    eval_names : list of str, or None, optional (default=None)
        Names of eval_set.
    eval_sample_weight : list of Dask Array or Dask Series, or None, optional (default=None)
        Weights for each validation set in eval_set. Weights should be non-negative.
    eval_class_weight : list of dict or str, or None, optional (default=None)
        Class weights, one dict or str for each validation set in eval_set.
    eval_init_score : list of Dask Array, Dask Series or Dask DataFrame (for multi-class task), or None, optional (default=None)
        Initial model score for each validation set in eval_set.
    eval_group : list of Dask Array or Dask Series, or None, optional (default=None)
        Group/query for each validation set in eval_set.
    eval_metric : str, callable, list or None, optional (default=None)
        If str, it should be a built-in evaluation metric to use.
        If callable, it should be a custom evaluation metric, see note below for more details.
        If list, it can be a list of built-in metrics, a list of custom evaluation metrics, or a mix of both.
        In either case, the ``metric`` from the Dask model parameters (or inferred from the objective) will be evaluated and used as well.
        Default: 'l2' for DaskLGBMRegressor, 'binary(multi)_logloss' for DaskLGBMClassifier, 'ndcg' for DaskLGBMRanker.
    eval_at : list or tuple of int, optional (default=None)
        The evaluation positions of the specified ranking metric.
    **kwargs
        Other parameters passed to ``fit`` method of the local underlying model.

    Returns
    -------
    model : lightgbm.LGBMClassifier, lightgbm.LGBMRegressor, or lightgbm.LGBMRanker class
        Returns fitted underlying model.

    Note
    ----

    This method handles setting up the following network parameters based on information
    about the Dask cluster referenced by ``client``.

    * ``local_listen_port``: port that each LightGBM worker opens a listening socket on,
            to accept connections from other workers. This can differ from LightGBM worker
            to LightGBM worker, but does not have to.
    * ``machines``: a comma-delimited list of all workers in the cluster, in the
            form ``ip:port,ip:port``. If running multiple Dask workers on the same host, use different
            ports for each worker. For example, for ``LocalCluster(n_workers=3)``, you might
            pass ``"127.0.0.1:12400,127.0.0.1:12401,127.0.0.1:12402"``.
    * ``num_machines``: number of LightGBM workers.
    * ``timeout``: time in minutes to wait before closing unused sockets.

    The default behavior of this function is to generate ``machines`` from the list of
    Dask workers which hold some piece of the training data, and to search for an open
    port on each worker to be used as ``local_listen_port``.

    If ``machines`` is provided explicitly in ``params``, this function uses the hosts
    and ports in that list directly, and does not do any searching. This means that if
    any of the Dask workers are missing from the list or any of those ports are not free
    when training starts, training will fail.

    If ``local_listen_port`` is provided in ``params`` and ``machines`` is not, this function
    constructs ``machines`` from the list of Dask workers which hold some piece of the
    training data, assuming that each one will use the same ``local_listen_port``.
    c              3       K   | ]}|v V  	d S rG   rN   r   aliasr   s     rC   r   z_train.<locals>.<genexpr>  s'      eeEeeeeeerE   r   c              3       K   | ]}|v V  	d S rG   rN   r   s     rC   r   z_train.<locals>.<genexpr>  s'      YYUf_YYYYYYrE   r   tree_learnerr   )main_param_namer   default_value>   r   votingfeaturedata_parallelvoting_parallelfeature_parallelzParameter tree_learner set to z/, which is not allowed. Using "data" as defaultr   num_threadsz
Parameter z will be ignored.T)r   r   Fc                     g | ]
\  }}||d S ))r   r   rN   )r   r   ys      rC   r   z_train.<locals>.<listcomp>+  s$    PPP!Qa!$$PPPrE   Nr   r   r   c              3   0   K   | ]}|d          j         V  dS )r   N)npartitionsr   s     rC   r   z_train.<locals>.<genexpr>B  s)      "F"F1Q4#3"F"F"F"F"F"FrE   r   r   r   r   r   r   errorc                     i | ]
}|j         |S rN   )key)r   r   s     rC   
<dictcomp>z_train.<locals>.<dictcomp>  s    9994$999rE   zWorker z was not allocated eval_set data. Therefore evals_result_ and best_score_ data may be unreliable. Try rebalancing data across workers.r   r   r   r   ip0  z$Using passed-in 'machines' parameter)r   r   z3Using passed-in 'local_listen_port' for all workersc                 6    h | ]}t          |          j        S rN   r   r   )r   as     rC   	<setcomp>z_train.<locals>.<setcomp>  s!    KKKQHQKK0KKKrE   z'local_listen_port' was provided in Dask training parameters, but at least one machine in the cluster has multiple Dask worker processes running on it. Please omit 'local_listen_port' or pass 'machines'.c                     i | ]}|S rN   rN   )r   r   r   s     rC   r  z_train.<locals>.<dictcomp>  s    %a%a%aWg/@%a%a%arE   z%Finding random open ports for workersr   c                 F    g | ]\  }}t          |          j         d | S )r   r  )r   worker_addressrQ   s      rC   r   z_train.<locals>.<listcomp>
  s6    vvv?S~t((1::D::vvvrE   c                    
 g | ]d\  }} j         t          fi 	d |         i|
|         	                    dd                              |d          |k    |gdddeS )r  r   x   NF)r   r   r   r   r   r   r   r   r   r^   r`   ra   )rb   r   r   )r   rh   r   rZ   r   r   master_workerr   r   r   worker_address_to_portworker_ncoresri   s      rC   r   z_train.<locals>.<listcomp>  s       " "FM! 		
'CfCm]6-BCC'4V<%ZZ
C00155fdCC M1H %	
 	
 	
 	
  rE   c                     g | ]}||S rN   rN   )r   vs     rC   r   z_train.<locals>.<listcomp>,  s    '''QQ'q'''rE   timeout))r   r   r   r   r   r   r   r   zipr   r   r   r   list	enumerater
  r   rT   rV   rW   rX   rY   rc   mapr$   computer'   statuswho_hasnextiterresultncoreskeysr   r   r   rm   joinrf   _other_params)HrZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   listen_port_in_paramsmachines_in_paramsallowed_tree_learnersparam_alias
data_partslabel_partsr   n_partsweight_partsr   group_partsinit_score_partsn_largest_eval_parts	eval_setseval_sample_weightseval_groupseval_init_scoresX_evaly_evaln_this_eval_parts	parts_idxeval_x_partseval_y_partsjr   r   eval_w_partsr   eval_init_score_partsr   eval_g_partsr   e_setr   key_to_part_dictr%  
worker_mapr  r^   rh   has_eval_setr   unique_hostsmsgfutures_classifiersresultsr   paramr   r   r  r   r  r  ri   sH   `  ``           `                                                @@@@@@@rC   _trainrO    s   N fF  eeee^=OPc=d=deeeee YYYY.:LZ:X:XYYYYY &  F
   n%:::tVN-Cttt	
 	
 	
 "(~
 &).-HH $ $&  DkDDDEEEJJ{### !dd;;;J!u>>>KPP3z;3O3OPPPE%jjG &MUKKKw 	1 	1A!-aE!HX%5EBBBw 	/ 	/A +AE!HW*
eLLLw 	9 	9A%5a%8E!H\""  nH  #"F"FX"F"F"FFF  	  	juk k  	tbmnrbsbsK 	ygrswgxgx#,X#6#6 S	C S	CA & 2 ~~&E//!&w H HIi(//0FGGGGH  /FdKKK.FeLLL344 @ @A !GI ,,,*1o*1o""7{{!),33cUSENCCCC "),R03::3???!),R03::3????! K%a(M99%*7^^ [ [	+I6==m>YZZZZ[ $38J18MY^#_#_#_L ##788 
K 
K000".q/CC"&C$%K	w;;/	:AA3%HHHH/	:2>EEcJJJJ Q"1%33%*7^^ U U	(3::=;STTTTU -<QRAS_d,e,e,e)"#788 
Q 
Q000+@+CLL+/L$%K	w;;,Y7>>~NNNN,Y7;BB<PPPP Ca=E))%*7^^ K K	#I.55m6IJJJJK $3
1QV#W#W#WL"#788 
C 
C000".q/CC"&C$%K	w;;'	2993%@@@@'	226==cBBBB !* 1 1 	H 	HIu+0E)Z(! X9LY9Wi !56 R6Fy6Qi !23 H1<Y1Gi . We$$%%ENN5!!EKKK  ;'!!KKK "
 :95999nnU##GT""J F FW4W&&'../?/DEEEE    	 	F L"6*  ..#'LE /   ;f ; ; ;    *)| 8&7"# , +} $#yj))**MMMOOM !+  F
 

#677 "  F
 zz*%%H 24!((8999!8-"
 "
 "

 ! 	KLLLKK:JKKKL<  3'7#8#888> 
 $C(((%a%a%a%aP`%a%a%a""=>>>>[Z__..//? ?;#%; 88vvWmWsWsWuWuvvv
 
 -..L            " &0%5%5%7%7#  ( mm/00G''''''GAJE ! 1#'(;<< 	1 	1E##E40000 1#'
33 	1 	1E##E40000#NI>> - -t,,,,LrE   r   r   	raw_score
pred_proba	pred_leafpred_contribc                 V   | j         d         dk    rt          j        g           }n'|r |j        | f|||d|}n |j        | f|||d|}t          | t                    rFt          |j                   dk    rt          || j                  }nt          || j        d          }|S )Nr   )rP  rR  rS     )indexpredictions)rV  name)
r   rv   arraypredict_probapredictru   r%   r   rV  r&   )r   r   rP  rQ  rR  rS  r   r(  s           rC   _predict_partr\  A  s     z!}"	 
$$
%	
 

 
 
 
%	
 

 
 
 $%% Mv|!!!&
;;;FFvTZmLLLFMrE   Fdtypec           	         t          t          t          t          f          st	          d          t          |t                    r |j        t          f| ||||d|j	        S t          |t                    r| j        }	|	dk    r9|r6t          |j        t          j                  rt          t          f| d|ddd|}
|                                }t#          |dddf                   }t$          dt&          t(                   d	t*          d
t(          fd            }|                    |
          }| j        dz   }|j        d         }d t1          |	          D             }|j        }t3          |                                          D ]V\  }}t1          |	          D ]A}t5           |||          ||         |f|          }||                             |           BWt          |t          j                  rt          t          j        d          }nBt          |t          j                  rt          t          j        d          }nt          j        }g }t1          |	          D ]P}|                    t5           t%          |          ||                   |j        d         |f|                     Q|S |                     |dg                   !                                }t          t          f| ||||d|} ||          }|j        d         f}i }tE          |j                  dk    r||j        d         fz  }nd|d<    |j#        |f|||d|S tI          dtK          |          j&         d          )a  Inner predict routine.

    Parameters
    ----------
    model : lightgbm.LGBMClassifier, lightgbm.LGBMRegressor, or lightgbm.LGBMRanker class
        Fitted underlying model.
    data : Dask Array or Dask DataFrame of shape = [n_samples, n_features]
        Input feature matrix.
    raw_score : bool, optional (default=False)
        Whether to predict raw scores.
    pred_proba : bool, optional (default=False)
        Should method return results of ``predict_proba`` (``pred_proba=True``) or ``predict`` (``pred_proba=False``).
    pred_leaf : bool, optional (default=False)
        Whether to predict leaf index.
    pred_contrib : bool, optional (default=False)
        Whether to predict feature contributions.
    dtype : np.dtype, optional (default=np.float32)
        Dtype of the output.
    **kwargs
        Other parameters passed to ``predict`` or ``predict_proba`` method.

    Returns
    -------
    predicted_result : Dask Array of shape = [n_samples] or shape = [n_samples, n_classes]
        The predicted values.
    X_leaves : Dask Array of shape = [n_samples, n_trees] or shape = [n_samples, n_trees * n_classes]
        If ``pred_leaf=True``, the predicted leaf of every tree for each sample.
    X_SHAP_values : Dask Array of shape = [n_samples, n_features + 1] or shape = [n_samples, (n_features + 1) * n_classes] or (if multi-class and using sparse inputs) a list of ``n_classes`` Dask Arrays of shape = [n_samples, n_features + 1]
        If ``pred_contrib=True``, the feature contributions for each sample.
    <dask, pandas and scikit-learn are required for lightgbm.dask)r   rP  rQ  rR  rS  rU  FTNr   rc   r   r6   c                     | |         S rG   rN   )rc   r   s     rC   _extractz_predict.<locals>._extract  s    QxrE   r   c                     g | ]}g S rN   rN   )r   _s     rC   r   z_predict.<locals>.<listcomp>  s    *J*J*J!2*J*J*JrE   )valuer   metarq   rr   csc	drop_axis)chunksre  r]  z6Data must be either Dask Array or Dask DataFrame. Got rt   )'allr   r   r   r   ru   r!   map_partitionsr\  valuesr   
_n_classes_metary   rz   r   r   r    r$   r   r   rM   n_features_rh  r   r!  r   r   
csr_matrixr{   
csc_matrixr   r#  r(  r   
map_blocksr|   r}   rJ   )r   r   rZ   rP  rQ  rR  rS  r]  r   num_classespredict_functiondelayed_chunksbagra  predsnum_colsnrows_per_chunkr   	pred_metarB  	partitionr   r   	concat_fn
out_arraysdata_row
predict_fnpred_rowrh  map_blocks_kwargss                                 rC   _predictr  h  s.   R  02CDEE \Z[[[$'' fi"t"
!%
 
 
 
 	 
D*	%	% \i &??|?
4:r{0S0S?& %!        "__..N'qqq!t(<==C S	  c  c       W  &&'788E (1,H"k!nO*J*Ju[7I7I*J*J*JC 
I )%*:*:*<*< = = ( (9{++ ( (A2&hy!44.q18<&  D
 FMM$''''( )R]33 &#BIe<<<		Ir}55 &#BIe<<<		I	 ,.J;''  !!+0gi00Q88#z!}h7&      >>$s),,3355
!%
 
 
 

 :h''#';q>"3x~""x~a(**FF-.k*t
	
 

  
 
 	
 gQUVZQ[Q[QdggghhhrE   c            "       *   e Zd Zedefd            Zdeeef         fdZ	 	 	 	 	 	 	 	 	 	 	 dde	e
         dededee         d	ee         d
ee         deeeeef                           deee                  deee                  deeeeef                           deee                  deee                  dee         deeee         eedf         f                  dedd f dZde	e
         de
fdZeded e
f         ded e
f         ddfd            ZdS )_DaskLGBMModelr6   c                 l    t          | dd          st          d          t          | j                  S )z:obj:`dask.distributed.Client`: Dask client.

        This property can be passed in the constructor or updated
        with ``model.set_params(client=client)``.
        r   Fz4Cannot access property client_ before calling fit().r\   )r   r   r]   rZ   rA   s    rC   client_z_DaskLGBMModel.client_  s;     tY.. 	]$%[\\\t{3333rE   c                     | j                             dd          }| j                            dd           t          | j                   }|                    ddi           || _        |S )z4Remove un-picklable attributes before serialization.rZ   N)__dict__r   r,  r   r   rZ   )rB   rZ   r   s      rC   _lgb_dask_getstatez!_DaskLGBMModel._lgb_dask_getstate	  sd    ""8T22x...t}%%

Hd#$$$
rE   Nr   Xr  r   r   r   r   r   r   r   r   r   r   r   .r   c                    t           st          d          t          t           t          t          f          st          d          |                     d          }|                    dd            t          di dt          | j	                  d|d|d|d|d	|d
|d|d|d|d|	d|
d|d|d|d||} | j
        di |                                 |                     ||            | S )Nz"dask is required for lightgbm.daskr_  TrZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rN   )r   r   ri  r   r   
get_paramsr   rO  r]   rZ   
set_params_lgb_dask_copy_extra_params)rB   r   r  r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                     rC   _lgb_dask_fitz_DaskLGBMModel._lgb_dask_fit  s   $  	F DEEEN$46GHII 	` ^___&&

8T""" 
 
 
#DK000

 !
 6	

 (-
 (-
 "z
 %
 X
 "z
  21
 0/
 ,O
 "z
 $
  G#
 
( 	--%**,,---((555rE   c                     |                                  }|                    dd             |di |}|                     | |           |j                            dd            |S )NrZ   rN   )r  r   r  r,  )rB   r   r   r   s       rC   _lgb_dask_to_localz!_DaskLGBMModel._lgb_dask_to_localE  sn    ""

8T"""''''((u555$///rE   sourcedestc                     |                                  }| j        }t          |                                                              |                                          }|D ]}t          ||||                    d S rG   )r  r  r   r*  
differencesetattr)r  r  r   
attributesextra_param_namesrX  s         rC   r  z*_DaskLGBMModel._lgb_dask_copy_extra_paramsM  s}    
 ""$$_

 1 122==fkkmmLL% 	2 	2DD$
4 01111	2 	2rE   NNNNNNNNNNN)rJ   rK   rL   propertyr   r  r	   r   r  r   r)   _DaskMatrixLike_DaskCollectionr   _DaskVectorLiker   r   strr   dictr-   rM   r  r  staticmethodr  rN   rE   rC   r  r    s/       	4 	4 	4 	4 X	4DcN     4804+/LP*.>B>B;?6:<@?C1 1I1 1 	1
  01 _-1 (1 4o&F GHI1 T#Y'1 %T/%:;1 $DtSy)9$:;1 "$"781 T/231 891 %S	5c? :;<1  !1" 
#1 1 1 1fY I     2&	122$i/02 
2 2 2 \2 2 2rE   r  c            +       *    e Zd ZdZddddddddd	d
ddddd	d	ddddddededededededeeee	f                  deee
ef                  dedededededededed eeeej        j        d!f                  d"ee         d#ed$ee         d%ef* fd&Zej        j        Ze                    d'          \  ZZZd(e d)d*d+d,e e d(e_        d-eeef         fd.Z	 	 	 	 	 	 	 	 dZd/ed0ed1ee         d2ee         d3eeeeef                           d4eee                  d5eee                  d6eeee
ef                           d7eee                  d8ee         d%ed-d fd9Z e j!        d:d;d<d=d>d?d@d?A          Zede"                    dB                   ee"                    dC          d         z   Zede"                    dD                   ee"                    dE          d         z   Zede"                    dF                    dGe# d(e_        	 	 	 	 	 	 d[d/edIe$dJedKee         dLe$dMe$dNe$d%ed-e%fdOZ& e'j!        dPd:dQdRdSdTU          e&_        	 	 	 	 	 	 d[d/edIe$dJedKee         dLe$dMe$dNe$d%ed-e%fdVZ( e'j!        dWd:dXdRdSdTU          e(_        d-efdYZ) xZ*S )\r1   z/Distributed version of lightgbm.LGBMClassifier.gbdt   r  皙?d   @ N        MbP?         ?r   r   boosting_type
num_leaves	max_depthlearning_raten_estimatorssubsample_for_bin	objectiveclass_weightmin_split_gainmin_child_weightmin_child_samples	subsamplesubsample_freqcolsample_bytree	reg_alpha
reg_lambdarandom_staten_jobsimportance_typerZ   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  np.random.Generatorr  r  rZ   r   c                    || _          t                      j        di d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|| dS )zADocstring is inherited from the lightgbm.LGBMClassifier.__init__.r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  NrN   rZ   super__init__rB   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rZ   r   	__class__s                         rC   r  zDaskLGBMClassifier.__init__\  "   4  	
 	
 	
'-	
!z	
  i	
 (-		

 &	
 0/	
  i	
 &	
 *>	
 .-	
 0/	
  i	
 *>	
 .-	
  i	
  "z!	
" &#	
$ 6%	
& ,O)	
 	
 	
 	
 	
rE   **kwargs	
        Jclient : dask.distributed.Client or None, optional (default=None)
         4Dask client. If ``None``, ``distributed.default_client()`` will be used at runtime. The Dask client used by this class will not be saved if the model object is pickled.
        r6   c                 *    |                                  S rG   r  rA   s    rC   __getstate__zDaskLGBMClassifier.__getstate__      &&(((rE   r  r  r   r   r   r   r   r   r   r   c                 B     | j         dt          |||||||||	|
d| | S )z<Docstring is inherited from the lightgbm.LGBMClassifier.fit.)r   r  r  r   r   r   r   r   r   r   r   rN   )r  r(   )rB   r  r  r   r   r   r   r   r   r   r   r   s               rC   r   zDaskLGBMClassifier.fit  sW     	 	
('!!1/+#	
 	
 	
 	
 	
 rE   ?Dask Array or Dask DataFrame of shape = [n_samples, n_features]@Dask Array, Dask DataFrame or Dask Series of shape = [n_samples]QDask Array or Dask Series of shape = [n_samples] or None, optional (default=None)zDask Array or Dask Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task), or Dask Array or Dask DataFrame of shape = [n_samples, n_classes] (for multi-class task), or None, optional (default=None):Dask Array or Dask Series or None, optional (default=None)Clist of Dask Array or Dask Series, or None, optional (default=None)zjlist of Dask Array, Dask Series or Dask DataFrame (for multi-class task), or None, optional (default=None)X_shapey_shapesample_weight_shapeinit_score_shapegroup_shapeeval_sample_weight_shapeeval_init_score_shapeeval_group_shapegroup :
eval_set :eval_group :eval_metric :callbacks :z**kwargs
        Other parameters passed through to ``LGBMClassifier.fit()``.

    Returns
    -------
    self : lightgbm.DaskLGBMClassifier
        Returns self.

    FrP  start_iterationnum_iterationrR  rS  validate_featuresc                     t          d|                                 || j        j        t	          | j                  ||||||d
|S )z@Docstring is inherited from the lightgbm.LGBMClassifier.predict.)
r   r   r]  rZ   rP  r  r  rR  rS  r  rN   )r  to_localclasses_r]  r]   rZ   	rB   r  rP  r  r  rR  rS  r  r   s	            rC   r[  zDaskLGBMClassifier.predict  s_      
--//-%#DK00+'%/
 
 
 
 	
rE   +Return the predicted value for each sample.predicted_resultzCDask Array of shape = [n_samples] or shape = [n_samples, n_classes]zVDask Array of shape = [n_samples, n_trees] or shape = [n_samples, n_trees * n_classes]zDask Array of shape = [n_samples, n_features + 1] or shape = [n_samples, (n_features + 1) * n_classes] or (if multi-class and using sparse inputs) a list of ``n_classes`` Dask Arrays of shape = [n_samples, n_features + 1]descriptionr  output_namepredicted_result_shapeX_leaves_shapeX_SHAP_values_shapec                 x    t          d|                                 |dt          | j                  ||||||d
|S )zFDocstring is inherited from the lightgbm.LGBMClassifier.predict_proba.T)
r   r   rQ  rZ   rP  r  r  rR  rS  r  rN   r  r  r]   rZ   r  s	            rC   rZ  z DaskLGBMClassifier.predict_proba  sZ      
--//#DK00+'%/
 
 
 
 	
rE   z@Return the predicted probability for each class for each sample.predicted_probabilityc                 6    |                      t                    S )zCreate regular version of lightgbm.LGBMClassifier from the distributed version.

        Returns
        -------
        model : lightgbm.LGBMClassifier
            Local underlying model.
        )r  r(   rA   s    rC   r  zDaskLGBMClassifier.to_local  s     &&~666rE   )NNNNNNNNFr   NFFF)+rJ   rK   rL   rU   r  rM   floatr   r   r,   r  rv   randomRandomStater   r   r  r(   	_base_docrz  _before_kwargs_kwargs_after_kwargsr	   r  r  r  r  r   r   r-   r   r/   rs   findr.   boolr   r[  r0   rZ  r  __classcell__r  s   @rC   r1   r1   Y  s       99
 $"!'OS37 #"&!#"%[_ $&#'-0
 0
 0
 0
 	0

 0
 0
 0
 0
 E#'J"JKL0
 uT3Y/00
 0
  0
 0
 0
 0
   !0
" #0
$ %0
& uS")*?AV%VWX'0
( )0
* +0
,  -0
. /0
 0
 0
 0
 0
 0
d '/I-6-@-@-L-L*NG]	 	   
    H)d38n ) ) ) ) 4804LP*.>B>B;?<@    0	
 _- 4o&F GHI T#Y' %T/%:; $DtSy)9$:; "$"78 89  
   > *")QRo BP!f K^	 	 	I 5INN955569>>R^C_C_CaCa9bbI:INN>:::;i	WfHgHgHiHi>jjI !!@9>>-#@#@!@A 	 	 %	 	 	CK   '+""'
 

 
 	

  }
 
 
  
 
 

 
 
 
4 4,3AQ&do |  GO   '+""'
 

 
 	

  }
 
 
  
 
 

 
 
 
4 :29VQ+do |  M7. 7 7 7 7 7 7 7 7rE   r1   c            +           e Zd ZdZddddddddd	d
ddddd	d	ddddddededededededeeee	f                  deee
ef                  dedededededededed eeeej        j        d!f                  d"ee         d#ed$ee         d%ef* fd&Zej        j        Ze                    d'          \  ZZZd(e d)d*d+d,e e d(e_        d-eeef         fd.Z	 	 	 	 	 	 	 dVd/ed0ed1ee         d2ee         d3eeeeef                           d4eee                  d5eee                  d6eee                  d7ee         d%ed-d fd8Z e j!        d9d:d;d;d<d=d=d=>          Zede"                    d?                   ee"                    d@          d         z   Zede"                    dA                   ee"                    dB          d         z   Zede"                    dC                   ee"                    dD          d         z   Zede"                    dE                    dFe# d(e_        	 	 	 	 	 	 dWd/edHe$dIedJee         dKe$dLe$dMe$d%ed-e%fdNZ& e'j!        dOd9dPdQdRdST          e&_        d-efdUZ( xZ)S )Xr3   z.Distributed version of lightgbm.LGBMRegressor.r  r  r  r  r  r  Nr  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  r  rZ   r   c                    || _          t                      j        di d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|| dS )z@Docstring is inherited from the lightgbm.LGBMRegressor.__init__.r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  NrN   r  r  s                         rC   r  zDaskLGBMRegressor.__init__(  r  rE   r  r  r  r  r  r  r6   c                 *    |                                  S rG   r  rA   s    rC   r  zDaskLGBMRegressor.__getstate__b  r  rE   r  r  r   r   r   r   r   r   r   c
                 @     | j         dt          |||||||||	d
|
 | S )z;Docstring is inherited from the lightgbm.LGBMRegressor.fit.)
r   r  r  r   r   r   r   r   r   r   rN   )r  r+   )rB   r  r  r   r   r   r   r   r   r   r   s              rC   r   zDaskLGBMRegressor.fite  sT     	 	
''!!1+#	
 	
 	
 	
 	
 rE   r  r  r  r  r  r  r  r  eval_class_weight :eval_init_score :r  r  r  z**kwargs
        Other parameters passed through to ``LGBMRegressor.fit()``.

    Returns
    -------
    self : lightgbm.DaskLGBMRegressor
        Returns self.

    FrP  r  r  rR  rS  r  c                 v    t          d|                                 |t          | j                  ||||||d	|S )z?Docstring is inherited from the lightgbm.LGBMRegressor.predict.	r   r   rZ   rP  r  r  rR  rS  r  rN   r  r  s	            rC   r[  zDaskLGBMRegressor.predict  W      
--//#DK00+'%/
 
 
 
 	
rE   r  r  !Dask Array of shape = [n_samples]*Dask Array of shape = [n_samples, n_trees]1Dask Array of shape = [n_samples, n_features + 1]r  c                 6    |                      t                    S )zCreate regular version of lightgbm.LGBMRegressor from the distributed version.

        Returns
        -------
        model : lightgbm.LGBMRegressor
            Local underlying model.
        )r  r+   rA   s    rC   r  zDaskLGBMRegressor.to_local  s     &&}555rE   )NNNNNNNr  )*rJ   rK   rL   rU   r  rM   r  r   r   r,   r  rv   r  r  r   r   r  r+   r  rz  r  r  r  r	   r  r  r  r  r   r   r-   r   r/   rs   r  r.   r   r   r[  r0   r  r  r  s   @rC   r3   r3   %  s       88
 $"!'OS37 #"&!#"%[_ $&#'-0
 0
 0
 0
 	0

 0
 0
 0
 0
 E#'J"JKL0
 uT3Y/00
 0
  0
 0
 0
 0
   !0
" #0
$ %0
& uS")*?AV%VWX'0
( )0
* +0
,  -0
. /0
 0
 0
 0
 0
 0
d &.I-6-@-@-L-L*NG]	 	   
    H)d38n ) ) ) ) 4804LP*.>B;?<@    0	
 _- 4o&F GHI T#Y' %T/%:; "$"78 89  
   : *")QRolP!fc^	 	 	I 5INN955569>>R^C_C_CaCa9bbIAINN+@AAABYy~~^qOrOrOtOtEuuI:INN>:::;i	WfHgHgHiHi>jjI !!@9>>-#@#@!@A 	 	 %	 	 	CK   '+""'
 

 
 	

  }
 
 
  
 
 

 
 
 
2 4,3AQ&BCO  GO6- 6 6 6 6 6 6 6 6rE   r3   c            +            e Zd ZdZddddddddd	d
ddddd	d	ddddddededededededeeee	f                  deee
ef                  dedededededededed eeeej        j        d!f                  d"ee         d#ed$ee         d%ef* fd&Zej        j        Ze                    d'          \  ZZZd(e d)d*d+d,e e d(e_        d-eeef         fd.Z	 	 	 	 	 	 	 	 	 	 d[d0ed1ed2ee         d3ee         d4ee         d5eeeeef                           d6eee                  d7eee                  d8eee                  d9eee                  d:ee         d;eee         eed<f         f         d%ed-d fd=Z e j!        d>d?d@d@dAdBdBdBC          Zede"                    dD                   ee"                    dE          d         z   Zede"                    dF                   dGz   d*dHdIz   d*d+ee"                    dF          d          z   Zede"                    dJ                    dKe# d(e_        	 	 	 	 	 	 d\d0edMe$dNedOee         dPe$dQe$dRe$d%ed-e%fdSZ& e'j!        dTd>dUdVdWdXY          e&_        d-efdZZ( xZ)S )]r2   z+Distributed version of lightgbm.LGBMRanker.r  r  r  r  r  r  Nr  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  r  rZ   r   c                    || _          t                      j        di d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|| dS )z=Docstring is inherited from the lightgbm.LGBMRanker.__init__.r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  NrN   r  r  s                         rC   r  zDaskLGBMRanker.__init__  r  rE   r  r  r  r  r  r  r6   c                 *    |                                  S rG   r  rA   s    rC   r  zDaskLGBMRanker.__getstate__
  r  rE   r   rU           r  r  r   r   r   r   r   r   r   r   r   r   .c                 F     | j         dt          |||||||||	|
||d| | S )z8Docstring is inherited from the lightgbm.LGBMRanker.fit.)r   r  r  r   r   r   r   r   r   r   r   r   r   rN   )r  r*   )rB   r  r  r   r   r   r   r   r   r   r   r   r   r   s                 rC   r   zDaskLGBMRanker.fit  s]    " 	 	
$'!!1+!#	
 	
 	
 	
 	
  rE   r  r  r  r  r  r  r  r  zfeature_name :zCeval_at : list or tuple of int, optional (default=(1, 2, 3, 4, 5))
8z2The evaluation positions of the specified metric.
r  z**kwargs
        Other parameters passed through to ``LGBMRanker.fit()``.

    Returns
    -------
    self : lightgbm.DaskLGBMRanker
        Returns self.

    FrP  r  r  rR  rS  r  c                 v    t          d|                                 |t          | j                  ||||||d	|S )z<Docstring is inherited from the lightgbm.LGBMRanker.predict.r
  rN   r  r  s	            rC   r[  zDaskLGBMRanker.predictQ  r  rE   r  r  r  r  r  r  c                 6    |                      t                    S )zCreate regular version of lightgbm.LGBMRanker from the distributed version.

        Returns
        -------
        model : lightgbm.LGBMRanker
            Local underlying model.
        )r  r*   rA   s    rC   r  zDaskLGBMRanker.to_locals  s     &&z222rE   )
NNNNNNNNNr  r  )*rJ   rK   rL   rU   r  rM   r  r   r   r,   r  rv   r  r  r   r   r  r*   r  rz  r  r  r  r	   r  r  r  r  r   r   r-   r   r/   rs   r  r.   r   r   r[  r0   r  r  r  s   @rC   r2   r2     sJ       55
 $"!'OS37 #"&!#"%[_ $&#'-0
 0
 0
 0
 	0

 0
 0
 0
 0
 E#'J"JKL0
 uT3Y/00
 0
  0
 0
 0
 0
   !0
" #0
$ %0
& uS")*?AV%VWX'0
( )0
* +0
,  -0
. /0
 0
 0
 0
 0
 0
d #+I-6-@-@-L-L*NG]	 	   
    H)d38n ) ) ) ) 4804+/LP*.>B;?6:<@5D! !! !  0	!
 _-! (! 4o&F GHI! T#Y'! %T/%:;! "$"78! T/23! 89! tCy%S/12! ! 
! ! ! !F *")QRolP!fc^	 	 	I AINN+@AAABYy~~^qOrOrOtOtEuuI 	4INN#34445
P	Q
G
G
G
G	H 
C
CIinn-=>>@@A
C
C	D  !!@9>>-#@#@!@A 	 	 %	 	 	CK   '+""'
 

 
 	

  }
 
 
  
 
 

 
 
 
2 4,3AQ&BCO  GO3* 3 3 3 3 3 3 3 3rE   r2   r  )`rU   rd   r9   collectionsr   copyr   enumr   r   	functoolsr   typingr   r	   r
   r   r   r   r   r   urllib.parser   numpyrv   scipy.sparsesparsery   basicr   r   r   r   r   compatr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   sklearnr(   r)   r*   r+   r,   r-   r.   r/   r0   __all__r  r  r  rw   rz   	_DaskPartfloat32float64int32int64_PredictionDtyper5   rM   rR   rT   r]   r  rm   r~   r   r   r   r   r   r   r  rO  r\  r  r  r1   r3   r2   rN   rE   rC   <module>r.     s      # # # # # #                     J J J J J J J J J J J J J J J J J J J J ! ! ! ! ! !           ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^                                     &
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   
NK?@
N23
K/0"*lIr{BC	bj)4
+;T"(^TRTRZ^[\        u]C/0    	 	 	 	 	D 	 	 	Xf- &    &!3!3#Y!3 4Vd38n,-!3 !3 !3 !3H

i 

Y 

 

 

 

? ?T#Y ? ? ? ?	 49     r+cNr+	?r+ S)^,-r+ 	r+
 r+ r+ r+ r+ !r+ r+ ir+ r+ r+ r+j/ d tI    %c %Xc] %tTWY\T\~ % % % %\ 04,0'+HL&*:>:>7;268<;?!` ``
` ` cN	`
 	?` O,` )` O$` tE/?"BCDE` c#` !o!67`  U49%5 67` d?34` o./` 45`  eDIuS#X678!`" #`$ %` ` ` `F$
$$ $ 	$
 $ $ $ $ $ $ $V  jQi QiQi
Qi Qi 	Qi
 Qi Qi Qi Qi Qi :tJ''(Qi Qi Qi QihZ2 Z2 Z2 Z2 Z2 Z2 Z2 Z2zI7 I7 I7 I7 I7 I7 I7 I7Xe6 e6 e6 e6 e6~ e6 e6 e6Pn3 n3 n3 n3 n3Z n3 n3 n3 n3 n3rE   