
    ri8                       d Z ddl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 ddlZddl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 m!Z!m"Z" ddl#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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 dd
l6m7Z7 erddl&m8Z8 g dZ9ee4eeee:         ee;         f                  ej<        e5ej=        j>        f         Z?ee	eej<                 ej<        geej<        ej<        f         f         e	eej<                 ej<        eej<                 geej<        ej<        f         f         e	eej<                 ej<        eej<                 eej<                 geej<        ej<        f         f         f         Z@ee	eej<                 ej<        gef         e	eej<                 ej<        gee         f         e	eej<                 ej<        eej<                 gef         e	eej<                 ej<        eej<                 gee         f         e	eej<                 ej<        eej<                 eej<                 gef         e	eej<                 ej<        eej<                 eej<                 gee         f         f         ZAeeBeAeeeBeAf                  f         ZCee?e f         ZDdedeej<                 fdZEdedej<        fdZFdedeej<                 fdZG G d d          ZH G d d          ZIdZJdZKdZLdeee
eef         ee         f                  deBde;dee         fdZM G d de0          ZN G d d e1eN          ZO G d! d"e,eN          ZP G d# d$eN          ZQdS )%z,Scikit-learn wrapper interface for LightGBM.    N)	signature)Path)TYPE_CHECKINGAnyCallableDictListOptionalTupleUnion   )_MULTICLASS_OBJECTIVESBoosterDatasetLightGBMError_choose_param_value_ConfigAliases_LGBM_BoosterBestScoreType%_LGBM_CategoricalFeatureConfiguration_LGBM_EvalFunctionResultType_LGBM_FeatureNameConfiguration_LGBM_GroupType_LGBM_InitScoreType_LGBM_LabelType_LGBM_WeightType_log_warning)_EvalResultDictrecord_evaluation)SKLEARN_INSTALLEDLGBMNotFittedError_LGBMAssertAllFinite_LGBMCheckClassificationTargets_LGBMCheckSampleWeight_LGBMClassifierBase_LGBMComputeSampleWeight_LGBMCpuCount_LGBMLabelEncoder_LGBMModelBase_LGBMRegressorBase_LGBMValidateData_sklearn_versiondt_DataTablepd_DataFrame)train)_sklearn_Tags)LGBMClassifier	LGBMModel
LGBMRankerLGBMRegressordatasetreturnc                 ~    |                                  }d}|$t          |t          j                  s
J |            |S )NzEstimators in lightgbm.sklearn should only retrieve query groups from a constructed Dataset. If you're seeing this message, it's a bug in lightgbm. Please report it at https://github.com/microsoft/LightGBM/issues.)	get_group
isinstancenpndarray)r4   group	error_msgs      f/var/www/html/pippo.cuttalo.com/services/trading/venv/lib/python3.11/site-packages/lightgbm/sklearn.py#_get_group_from_constructed_datasetr>   y   sD    E	C  =Jubj99==9===L    c                 z    |                                  }d}t          |t          j                  s
J |            |S )NzEstimators in lightgbm.sklearn should only retrieve labels from a constructed Dataset. If you're seeing this message, it's a bug in lightgbm. Please report it at https://github.com/microsoft/LightGBM/issues.)	get_labelr8   r9   r:   )r4   labelr<   s      r=   #_get_label_from_constructed_datasetrC      sE    E	C  eRZ((33)333Lr?   c                 ~    |                                  }d}|$t          |t          j                  s
J |            |S )NzEstimators in lightgbm.sklearn should only retrieve weights from a constructed Dataset. If you're seeing this message, it's a bug in lightgbm. Please report it at https://github.com/microsoft/LightGBM/issues.)
get_weightr8   r9   r:   )r4   weightr<   s      r=   $_get_weight_from_constructed_datasetrG      sD    !!F	C  >Z
;;>>Y>>>Mr?   c                   `    e Zd ZdZdefdZdej        dede	ej        ej        f         fdZ
dS )	_ObjectiveFunctionWrapperz#Proxy class for objective function.funcc                     || _         dS )aJ	  Construct a proxy class.

        This class transforms objective function to match objective function with signature ``new_func(preds, dataset)``
        as expected by ``lightgbm.engine.train``.

        Parameters
        ----------
        func : callable
            Expects a callable with following signatures:
            ``func(y_true, y_pred)``,
            ``func(y_true, y_pred, weight)``
            or ``func(y_true, y_pred, weight, group)``
            and returns (grad, hess):

                y_true : numpy 1-D array of shape = [n_samples]
                    The target values.
                y_pred : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (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.
                weight : numpy 1-D array of shape = [n_samples]
                    The weight of samples. Weights should be non-negative.
                group : numpy 1-D array
                    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.
                grad : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape [n_samples, n_classes] (for multi-class task)
                    The value of the first order derivative (gradient) of the loss
                    with respect to the elements of y_pred for each sample point.
                hess : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
                    The value of the second order derivative (Hessian) of the loss
                    with respect to the elements of y_pred for each sample point.

        .. note::

            For multi-class task, y_pred is a numpy 2-D array of shape = [n_samples, n_classes],
            and grad and hess should be returned in the same format.
        NrJ   selfrJ   s     r=   __init__z"_ObjectiveFunctionWrapper.__init__   s    R 			r?   predsr4   r5   c                    t          |          }t          t          | j                  j                  }|dk    r|                     ||          \  }}||fS t          |          }|dk    r|                     |||          \  }}||fS |dk    r't          |          }|                     ||||          S t          d|           )a  Call passed function with appropriate arguments.

        Parameters
        ----------
        preds : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
            The predicted values.
        dataset : Dataset
            The training dataset.

        Returns
        -------
        grad : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (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 of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (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.
                 zESelf-defined objective function should have 2, 3 or 4 arguments, got rC   lenr   rJ   
parametersrG   r>   	TypeError)	rN   rP   r4   labelsargcgradhessrF   r;   s	            r=   __call__z"_ObjectiveFunctionWrapper.__call__   s    . 5W==9TY''2331996511JD$:5g>>19965&99JD$:1997@@E99VUFE:::f`dffgggr?   N)__name__
__module____qualname____doc__#_LGBM_ScikitCustomObjectiveFunctionrO   r9   r:   r   r   r]    r?   r=   rI   rI      s        --)@ ) ) ) )V&hz&h &h 
rz2:%	&	&h &h &h &h &h &hr?   rI   c            	       X    e Zd ZdZdefdZdej        dede	e
ee
         f         fdZdS )	_EvalFunctionWrapperz$Proxy class for evaluation function.rJ   c                     || _         dS )a  Construct a proxy class.

        This class transforms evaluation function to match evaluation function with signature ``new_func(preds, dataset)``
        as expected by ``lightgbm.engine.train``.

        Parameters
        ----------
        func : callable
            Expects a callable with following signatures:
            ``func(y_true, y_pred)``,
            ``func(y_true, y_pred, weight)``
            or ``func(y_true, y_pred, weight, group)``
            and returns (eval_name, eval_result, is_higher_better) or
            list of (eval_name, eval_result, is_higher_better):

                y_true : numpy 1-D array of shape = [n_samples]
                    The target values.
                y_pred : numpy 1-D array of shape = [n_samples] or numpy 2-D array shape = [n_samples, n_classes] (for multi-class task)
                    The predicted values.
                    In case of custom ``objective``, 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.
                weight : numpy 1-D array of shape = [n_samples]
                    The weight of samples. Weights should be non-negative.
                group : numpy 1-D array
                    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_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``.
        NrL   rM   s     r=   rO   z_EvalFunctionWrapper.__init__   s    J 			r?   rP   r4   r5   c                 z   t          |          }t          t          | j                  j                  }|dk    r|                     ||          S t          |          }|dk    r|                     |||          S |dk    r't          |          }|                     ||||          S t          d|           )aa  Call passed function with appropriate arguments.

        Parameters
        ----------
        preds : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
            The predicted values.
        dataset : Dataset
            The training dataset.

        Returns
        -------
        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``.
        rR   rS   rT   z@Self-defined eval function should have 2, 3 or 4 arguments, got rU   )rN   rP   r4   rY   rZ   rF   r;   s          r=   r]   z_EvalFunctionWrapper.__call__  s    . 5W==9TY''23319999VU+++5g>>19999VUF3331997@@E99VUFE:::a[_aabbbr?   N)r^   r_   r`   ra   _LGBM_ScikitCustomEvalFunctionrO   r9   r:   r   r   r   r	   r]   rc   r?   r=   re   re      s        ..%; % % % %N$cz$c $c 
+T2N-OO	P	$c $c $c $c $c $cr?   re   aX  
    Build a gradient boosting model from the training set (X, y).

    Parameters
    ----------
    X : {X_shape}
        Input feature matrix.
    y : {y_shape}
        The target values (class labels in classification, real numbers in regression).
    sample_weight : {sample_weight_shape}
        Weights of training data. Weights should be non-negative.
    init_score : {init_score_shape}
        Init score of training data.
    group : {group_shape}
        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 or None, optional (default=None)
        A list of (X, y) tuple pairs to use as validation sets.
    eval_names : list of str, or None, optional (default=None)
        Names of eval_set.
    eval_sample_weight : {eval_sample_weight_shape}
        Weights of eval data. Weights should be non-negative.
    eval_class_weight : list or None, optional (default=None)
        Class weights of eval data.
    eval_init_score : {eval_init_score_shape}
        Init score of eval data.
    eval_group : {eval_group_shape}
        Group data of eval data.
    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 model parameters will be evaluated and used as well.
        Default: 'l2' for LGBMRegressor, 'logloss' for LGBMClassifier, 'ndcg' for LGBMRanker.
    feature_name : list of str, or 'auto', optional (default='auto')
        Feature names.
        If 'auto' and data is pandas DataFrame, 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.
    callbacks : list of callable, or None, optional (default=None)
        List of callback functions that are applied at each iteration.
        See Callbacks in Python API for more information.
    init_model : str, pathlib.Path, Booster, LGBMModel or None, optional (default=None)
        Filename of LightGBM model, Booster instance or LGBMModel instance used for continue training.

    Returns
    -------
    self : LGBMModel
        Returns self.
    a9  
    Note
    ----
    Custom eval function expects a callable with following signatures:
    ``func(y_true, y_pred)``, ``func(y_true, y_pred, weight)`` or
    ``func(y_true, y_pred, weight, group)``
    and returns (eval_name, eval_result, is_higher_better) or
    list of (eval_name, eval_result, is_higher_better):

        y_true : numpy 1-D array of shape = [n_samples]
            The target values.
        y_pred : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
            The predicted values.
            In case of custom ``objective``, 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.
        weight : numpy 1-D array of shape = [n_samples]
            The weight of samples. Weights should be non-negative.
        group : numpy 1-D array
            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_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``.
a_  
    {description}

    Parameters
    ----------
    X : {X_shape}
        Input features matrix.
    raw_score : bool, optional (default=False)
        Whether to predict raw scores.
    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).
    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.

    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
    -------
    {output_name} : {predicted_result_shape}
        The predicted values.
    X_leaves : {X_leaves_shape}
        If ``pred_leaf=True``, the predicted leaf of every tree for each sample.
    X_SHAP_values : {X_SHAP_values_shape}
        If ``pred_contrib=True``, the feature contributions for each sample.
    
collectionnameic                     | dS t          | t                    rt          |           |k    r| |         S dS t          | t                    r|                     |d          S t          | d          )z?Try to extract the ith element of one of the ``eval_*`` inputs.Nz should be dict or list)r8   listrV   dictgetrX   ri   rj   rk   s      r=   _extract_evaluation_meta_datarq     s     t	J	%	% :
 z??Qa= 4	J	%	% :~~a&&&4888999r?   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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        ej        j        f                  d!ee         d"ed#ef(d$Zd%e
eef         fd&Zed'd(d)e
eef         d%d(fd*            Zd%ed(         f fd+Zd%efd,Zdnd.ed%e
eef         f fd/Zd0ed%d fd1Zd2ed%e
eef         fd3Zd!ee         d%efd4Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 dod6ed7ed8ee         d9ee         d:ee         d;ee e!                  d<ee e                  d=ee e                  d>ee e                  d?ee e                  d@ee e                  dAee"         dBe#dCe$dDee e%                  dEeeee&e'd f                  d%d f"dFZ(e)*                    dGdHdIdJdKdLdMdNO          dPz   e+z   e(_        	 	 	 	 	 	 dpd6edRedSedTee         dUedVedWed#efdXZ,e-*                    dYdGdZd[d\d]^          e,_        e.d%efd_            Z/e.d%efd`            Z0e0j1        daed%dfdb            Z0e.d%e2fdc            Z3e.d%efdd            Z4e.d%eee	f         fde            Z5e.d%efdf            Z6e.d%efdg            Z7e.d%e'fdh            Z8e.d%e9fdi            Z:e.d%ej;        fdj            Z<e.d%e e         fdk            Z=e.d%ej;        fdl            Z>e>j?        dqdm            Z> xZ@S )rr1   z4Implementation of the scikit-learn API for LightGBM.gbdt   皙?d   @ N        MbP?         ?r   split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_typer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargsc                   t           st          d          || _        || _        || _        || _        || _        || _        || _        |	| _	        |
| _
        || _        || _        || _        || _        || _        || _        || _        || _        || _        d| _        i | _        i | _        d| _        i | _        || _        || _        d| _        d| _        d| _        d| _        d| _        d| _          | j!        di | dS )a  Construct a gradient boosting model.

        Parameters
        ----------
        boosting_type : str, optional (default='gbdt')
            'gbdt', traditional Gradient Boosting Decision Tree.
            'dart', Dropouts meet Multiple Additive Regression Trees.
            'rf', Random Forest.
        num_leaves : int, optional (default=31)
            Maximum tree leaves for base learners.
        max_depth : int, optional (default=-1)
            Maximum tree depth for base learners, <=0 means no limit.
            If setting this to a positive value, consider also changing ``num_leaves`` to ``<= 2^max_depth``.
        learning_rate : float, optional (default=0.1)
            Boosting learning rate.
            You can use ``callbacks`` parameter of ``fit`` method to shrink/adapt learning rate
            in training using ``reset_parameter`` callback.
            Note, that this will ignore the ``learning_rate`` argument in training.
        n_estimators : int, optional (default=100)
            Number of boosted trees to fit.
        subsample_for_bin : int, optional (default=200000)
            Number of samples for constructing bins.
        objective : str, callable or None, optional (default=None)
            Specify the learning task and the corresponding learning objective or
            a custom objective function to be used (see note below).
            Default: 'regression' for LGBMRegressor, 'binary' or 'multiclass' for LGBMClassifier, 'lambdarank' for LGBMRanker.
        class_weight : dict, 'balanced' or None, optional (default=None)
            Weights associated with classes in the form ``{class_label: weight}``.
            Use this parameter only for multi-class classification task;
            for binary classification task you may use ``is_unbalance`` or ``scale_pos_weight`` parameters.
            Note, that the usage of all these parameters will result in poor estimates of the individual class probabilities.
            You may want to consider performing probability calibration
            (https://scikit-learn.org/stable/modules/calibration.html) of your model.
            The 'balanced' mode uses the values of y to automatically adjust weights
            inversely proportional to class frequencies in the input data as ``n_samples / (n_classes * np.bincount(y))``.
            If None, all classes are supposed to have weight one.
            Note, that these weights will be multiplied with ``sample_weight`` (passed through the ``fit`` method)
            if ``sample_weight`` is specified.
        min_split_gain : float, optional (default=0.)
            Minimum loss reduction required to make a further partition on a leaf node of the tree.
        min_child_weight : float, optional (default=1e-3)
            Minimum sum of instance weight (Hessian) needed in a child (leaf).
        min_child_samples : int, optional (default=20)
            Minimum number of data needed in a child (leaf).
        subsample : float, optional (default=1.)
            Subsample ratio of the training instance.
        subsample_freq : int, optional (default=0)
            Frequency of subsample, <=0 means no enable.
        colsample_bytree : float, optional (default=1.)
            Subsample ratio of columns when constructing each tree.
        reg_alpha : float, optional (default=0.)
            L1 regularization term on weights.
        reg_lambda : float, optional (default=0.)
            L2 regularization term on weights.
        random_state : int, RandomState object or None, optional (default=None)
            Random number seed.
            If int, this number is used to seed the C++ code.
            If RandomState or Generator object (numpy), a random integer is picked based on its state to seed the C++ code.
            If None, default seeds in C++ code are used.
        n_jobs : int or None, optional (default=None)
            Number of parallel threads to use for training (can be changed at prediction time by
            passing it as an extra keyword argument).

            For better performance, it is recommended to set this to the number of physical cores
            in the CPU.

            Negative integers are interpreted as following joblib's formula (n_cpus + 1 + n_jobs), just like
            scikit-learn (so e.g. -1 means using all threads). A value of zero corresponds the default number of
            threads configured for OpenMP in the system. A value of ``None`` (the default) corresponds
            to using the number of physical cores in the system (its correct detection requires
            either the ``joblib`` or the ``psutil`` util libraries to be installed).

            .. versionchanged:: 4.0.0

        importance_type : str, optional (default='split')
            The type of feature importance to be filled into ``feature_importances_``.
            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.
        **kwargs
            Other parameters for the model.
            Check http://lightgbm.readthedocs.io/en/latest/Parameters.html for more parameters.

            .. warning::

                \*\*kwargs is not supported in sklearn, it may cause unexpected issues.

        Note
        ----
        A custom objective function can be provided for the ``objective`` parameter.
        In this case, it should have the signature
        ``objective(y_true, y_pred) -> grad, hess``,
        ``objective(y_true, y_pred, weight) -> grad, hess``
        or ``objective(y_true, y_pred, weight, group) -> grad, hess``:

            y_true : numpy 1-D array of shape = [n_samples]
                The target values.
            y_pred : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (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.
            weight : numpy 1-D array of shape = [n_samples]
                The weight of samples. Weights should be non-negative.
            group : numpy 1-D array
                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.
            grad : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
                The value of the first order derivative (gradient) of the loss
                with respect to the elements of y_pred for each sample point.
            hess : numpy 1-D array of shape = [n_samples] or numpy 2-D array of shape = [n_samples, n_classes] (for multi-class task)
                The value of the second order derivative (Hessian) of the loss
                with respect to the elements of y_pred for each sample point.

        For multi-class task, y_pred is a numpy 2-D array of shape = [n_samples, n_classes],
        and grad and hess should be returned in the same format.
        zyscikit-learn is required for lightgbm.sklearn. You must install scikit-learn and restart your session to use this module.Nru   rc   )"r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _Booster_evals_result_best_score_best_iteration_other_params
_objectiver   _class_weight
_class_map_n_features_n_features_in_classes
_n_classes
set_params)rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                        r=   rO   zLGBMModel.__init__  s1   \ ! 	]  
 +"$"*(!2, 0!2", 0"$(.+/.079$&-/#(9=48 "#%.2!!!&!!!!!r?   r5   c                      d}dg dd|||ddS )Na  In LightGBM, setting a sample's weight to 0 can produce a different result than omitting the sample. Such samples intentionally still affect count-based measures like 'min_data_in_leaf' (https://github.com/microsoft/LightGBM/issues/5626#issuecomment-1712706678) and the estimated distribution of features for Dataset construction (see https://github.com/microsoft/LightGBM/issues/5553).T)2darraysparse1dlabelszscikit-learn incorrectly asserts that private attributes cannot be set in __init__: (see https://github.com/microsoft/LightGBM/issues/2628))check_no_attributes_set_in_initcheck_sample_weight_equivalence-check_sample_weight_equivalence_on_dense_data.check_sample_weight_equivalence_on_sparse_data)	allow_nanX_types_xfail_checksrc   )rN   check_sample_weight_strs     r=   
_more_tagszLGBMModel._more_tags  sF    l 	  8884J 4KAXBY 
 
 	
r?   tagsr/   	tags_dictc                 z    |d         | j         _        d|d         v | j         _        d|d         v | j        _        | S )aS  Update ``sklearn.utils.Tags`` inherited from ``scikit-learn`` base classes.

        ``scikit-learn`` 1.6 introduced a dataclass-based interface for estimator tags.
        ref: https://github.com/scikit-learn/scikit-learn/pull/29677

        This method handles updating that instance based on the value in ``self._more_tags()``.
        r   r   r   r   )
input_tagsr   r   target_tagsone_d_labelsr   r   s     r=   _update_sklearn_tags_from_dictz(LGBMModel._update_sklearn_tags_from_dict  sA     %.k$:!!)Yy-A!A(2i	6J(J%r?   c                     t          t          d          sdt           }t          |          |                     t                                                      |                                           S )N__sklearn_tags__zW__sklearn_tags__() should not be called when using scikit-learn<1.6. Detected version: r   )hasattrr(   r+   AttributeErrorr   superr   r   )rN   err_msg	__class__s     r=   r   zLGBMModel.__sklearn_tags__  s~     ~'9:: 	*8%58 8  !))) 22))++oo'' 3 
 
 	
r?   c                 $    t          | dd          S )Nfitted_F)getattrrN   s    r=   __sklearn_is_fitted__zLGBMModel.__sklearn_is_fitted__  s    tY...r?   Tdeepc                    t                                          |          }t          j        |           }t          t	          |j        j        d         dd                    r|j        j        d         |_        n|j        j        d         |_        |                    |j                            ||                     |                    | j                   |S )ag  Get parameters for this estimator.

        Parameters
        ----------
        deep : bool, optional (default=True)
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : dict
            Parameter names mapped to their values.
        )r   r   
get_paramsNr   )	r   r   copycallabler   r   	__bases__updater   )rN   r   paramscpr   s       r=   r   zLGBMModel.get_params  s    B ###..Yt__GBL215|TJJKK 	5<1!4BLL <1!4BLbl--b$77888d()))r?   r   c                     |                                 D ]G\  }}t          | ||           t          | d|           rt          | d| |           || j        |<   H| S )zSet the parameters of this estimator.

        Parameters
        ----------
        **params
            Parameter names with their new values.

        Returns
        -------
        self : object
            Returns self.
        _)itemssetattrr   r   )rN   r   keyvalues       r=   r   zLGBMModel.set_params  sv     !,,.. 	, 	,JCD#u%%%tYYY'' 0i#ii///&+Ds##r?   stagec                    |dv sJ |                                  }|                    dd           t          j        d          D ];}||v r5|                    |          }t	          d| d           |dk    r|| _        <|dk    r| j        yt          | t                    rd| _        n\t          | t                    r| j	        dk    rd	| _        n4d
| _        n,t          | t                    rd| _        nt          d          t          | j                  r$|dk    rt          | j                  |d<   nd|d<   n
| j        |d<   |                    dd           |                    dd           |                    dd           t          |d         t          j        j                  r@|d                             t          j        t          j                  j                  |d<   nqt          |d         t          j        j                  rLt-          |d                             t          j        t          j                  j                            |d<   | j	        dk    r7t          j        d          D ]}|                    |d           | j	        |d<   t1          | d          rO| j        }t          j        d          D ].}||v r(t	          d| d           |                    |          }/||d<   t          | j        t4                    r| j        nd}|Tt          | t                    rd}n<t          | t                    r| j	        dk    rdnd}nt          | t                    rd}t7          d||          }|dk    r4t7          d|| j                  }|                     |d                   |d<   |S )ap  Process the parameters of this estimator based on its type, parameter aliases, etc.

        Parameters
        ----------
        stage : str
            Name of the stage (can be ``fit`` or ``predict``) this method is called from.

        Returns
        -------
        processed_params : dict
            Processed parameter names mapped to their values.
        >   fitpredictr   NzFound 'z8' in params. Will use it instead of 'objective' argumentr   
regressionrR   
multiclassbinary
lambdarankzUnknown LGBMModel type.Noner   r   r   r   	num_class_eval_ateval_atz6' in params. Will use it instead of 'eval_at' argumentl2multi_loglossbinary_loglossndcgmetricnum_threads)r   popr   ro   r   r   r8   r3   r0   r   r2   
ValueErrorr   rI   r9   randomRandomStaterandintiinfoint32max	Generatorintintegersr   r   strr   r   _process_n_jobs)rN   r   r   aliasobjr   original_metrics          r=   _process_paramszLGBMModel._process_params!  s    *****""

;%%%#'44 	* 	*Ejj''fufffgggE>>&)DOE>>&dM22 
@&2DOOn55 @***6*2j11 @&2DOO$%>???DO$$ 	2~~&?&P&P{##&,{##"&/F;

$d+++

>4(((

>4(((f^,bi.CDD 	b%+N%;%C%CBHRXDVDVDZ%[%[F>""~.	0CDD 	b%()?)H)HRTRZI[I[I_)`)`%a%aF>"?Q'+K88 ( (

5$''''"&/F;4$$ 	(mG'+I66 0 0F?? !h5!h!h!hiii$jj//G 'F9 .8-M-MW$//SW"$.. )"&D.11 )59_q5H5H//N^D*-- )"( %XvGG E>>(LLF$($8$89N$O$OF=!r?   c                     |t          d          }n*|dk     r$t          t          d          dz   |z   d          }|S )a  Convert special values of n_jobs to their actual values according to the formulas that apply.

        Parameters
        ----------
        n_jobs : int or None
            The original value of n_jobs, potentially having special values such as 'None' or
            negative integers.

        Returns
        -------
        n_jobs : int
            The value of n_jobs with special values converted to actual number of threads.
        NT)only_physical_coresr   Fr   )r&   r   )rN   r   s     r=   r   zLGBMModel._process_n_jobsw  sN     >"t<<<FFaZZ5AAAAENPQRRFr?   autoXysample_weight
init_scorer;   eval_set
eval_nameseval_sample_weighteval_class_weighteval_init_score
eval_groupeval_metricfeature_namecategorical_feature	callbacks
init_modelc           
         "                       d          "|g }n?t          |t                    rt          j        |          }nt          j        |          g}d |D             }d |D             }t          "d         t
          t          d          f          r	"d         gn"d         "d<   "fd|D             "d         z   "d<   d "d         D             "d<   t          |t          t          f          s,t           ||d	d	d
d          \  }}|t          ||          }n||}}|j        d          _         j         j         _         j        Bt           j        |          }|t!          |          dk    r|}nt#          j        ||          }t'          |||||||"          }g }|Ft          |t(                    r|g}t+          |          D ]\  }}|d         |u r|d         |u r|}nt-          |d|          }t-          |	d|          }|t          |t.                    r' j          fd|                                D             }t          ||d                   }|t!          |          dk    r|}nt#          j        ||          }t-          |
d|          }t-          |d|          } t'          |d         |d         || |d"          }|                    |           t          |t6                    r|j        }|g }nt          j        |          }i }!|                    t;          |!                     t=          "| j        |||||           _          j         !                                 _"        |! _#         j         j$         _%         j         j&         _'        d	 _(         j         )                                 ~~ S )4Docstring is set after definition, using a template.r   r   Nc                 J    g | ] }t          |          t          |          !S rc   )r   re   ).0fs     r=   
<listcomp>z!LGBMModel.fit.<locals>.<listcomp>  s0     b b bQV^_`VaVa b!5a!8!8 b b br?   c                 <    g | ]}t          |t                    |S rc   )r8   r   )r
  ms     r=   r  z!LGBMModel.fit.<locals>.<listcomp>  s'    RRRaz!S?Q?QRRRRr?   r   c                 (    g | ]}|d          v|S )r   rc   )r
  er   s     r=   r  z!LGBMModel.fit.<locals>.<listcomp>  s(    YYY!qxHX?X?XA?X?X?Xr?   c                     g | ]}||S Nrc   )r
  r   s     r=   r  z!LGBMModel.fit.<locals>.<listcomp>  s    XXXvVEWFEWEWEWr?   TFrR   resetaccept_sparseensure_all_finiteensure_min_samplesr   r   )datarB   rF   r;   r   r  r  r   r   rp   r   c                 2    i | ]\  }}j         |         |S rc   r   r
  kvrN   s      r=   
<dictcomp>z!LGBMModel.fit.<locals>.<dictcomp>  s&    1o1o1oDAq$/!2Da1o1o1or?   r   r   r   )r  rB   rF   r;   r   r  r   )r   	train_setnum_boost_round
valid_setsvalid_namesfevalr  r  )*r   r8   rm   r   deepcopyr   typer-   r,   r*   r#   shapen_features_in_r   r   r%   rV   r9   multiplyr   tuple	enumeraterq   rn   r   r   appendr1   booster_r   r.   r   r   num_featurer   r   best_iterationr   
best_scorer   r   free_dataset)#rN   r   r   r   r   r;   r   r   r   r   r   r   r  r  r  r  r  eval_metric_listeval_metrics_callableeval_metrics_builtin_X_yclass_sample_weightr  r!  rk   
valid_data	valid_setvalid_weightvalid_class_weightvalid_class_sample_weightvalid_init_scorevalid_groupevals_resultr   s#   `                                 @r=   r   zLGBMModel.fit  s   ( %%E%22
 !T** 	<#}[99 $k : :; !c bBR b b bRR+;RRR 2<F8<LsTXY]T^T^N_1`1`vF8,--flmufvxYYYY';YYY\bck\llxXX1AXXXx!lL9:: 	.&""'#$  FB ( 6}b I IB #%(1+D%!%!2D)":4;Mq"Q"Q$M(:(:a(?(? 3 "M;N O O ! 3%	
 	
 	
	 %'
(E** &$:!*8!4!4 +- +-:a=A%%*Q-1*<*< )II#@#51$ $ $L
 *G#40* * *&
 *5%&8$?? pDOD_1o1o1o1oTfTlTlTnTn1o1o1o.4LM_aklman4o4o1'/3|3D3D3I3I+DLL+-;|E^+_+_L'D#2.( ( ($
 #@#-)# # #K
 !('](m+)#3,2%! ! !I !!),,,,j),, 	-#,JII	),,I(**<88999 -!"'!	
 	
 	
   =4466)#};=3 	""$$$zr?   numpy array, pandas DataFrame, H2O DataTable's Frame (deprecated), scipy.sparse, list of lists of int or float of shape = [n_samples, n_features]zYnumpy array, pandas DataFrame, pandas Series, list of int or float of shape = [n_samples]zhnumpy array, pandas Series, list of int or float of shape = [n_samples] or None, optional (default=None)znumpy array, pandas DataFrame, pandas Series, list of int or float of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task) or shape = [n_samples, n_classes] (for multi-class task) or None, optional (default=None)zRnumpy array, pandas Series, list of int or float, or None, optional (default=None)zZlist of array (same types as ``sample_weight`` supports), or None, optional (default=None)zWlist of array (same types as ``init_score`` supports), or None, optional (default=None)zRlist of array (same types as ``group`` supports), 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_shapez

F	raw_scorestart_iterationnum_iteration	pred_leafpred_contribvalidate_featuresc           
      "   |                                  st          d          t          |t          t          f          st          | |dddd          }|                     d          }	t          j        dd	d
ddddg|	                                R  D ]}
|	
                    |
d           |	                    |           t          d|	| j                  }	|                     |	d                   |	d<    | j        j        |f||||||d|	S )r  z;Estimator not fitted, call fit before exploiting the model.FTr   r  r   r  r  r   rH  rI  rJ  rK  rL  Nr   )rH  rI  rJ  rK  rL  rM  )r   r    r8   r-   r,   r*   r   r   get_by_aliaskeysr   r   r   r   r   r   r   )rN   r   rH  rI  rJ  rK  rL  rM  r   predict_paramsr   s              r=   r   zLGBMModel.predictE  sj    ))++ 	d$%bccc!lL9:: 	!
 ""'#$  A" --I->>#0	
 [[]]	
 	
 	
 
	, 
	,E ud++++f%%% -]NDKXX(,(<(<^M=Z([([}%$t}$	
+'%/	
 	
 	
 	
 		
r?   z+Return the predicted value for each sample.predicted_resultCarray-like of shape = [n_samples] or shape = [n_samples, n_classes]Varray-like of shape = [n_samples, n_trees] or shape = [n_samples, n_trees * n_classes]array-like of shape = [n_samples, n_features + 1] or shape = [n_samples, (n_features + 1) * n_classes] or list with n_classes length of such objectsdescriptionr@  output_namepredicted_result_shapeX_leaves_shapeX_SHAP_values_shapec                 V    |                                  st          d          | j        S )3:obj:`int`: The number of features of fitted model.z1No n_features found. Need to call fit beforehand.)r   r    r   r   s    r=   n_features_zLGBMModel.n_features_  1     ))++ 	Z$%XYYYr?   c                 V    |                                  st          d          | j        S )r]  z4No n_features_in found. Need to call fit beforehand.)r   r    r   r   s    r=   r'  zLGBMModel.n_features_in_  s1     ))++ 	]$%[\\\""r?   r   c                     || _         dS )a  Set number of features found in passed-in dataset.

        Starting with ``scikit-learn`` 1.6, ``scikit-learn`` expects to be able to directly
        set this property in functions like ``validate_data()``.

        .. note::

            Do not call ``estimator.n_features_in_ = some_int`` or anything else that invokes
            this method. It is only here for compatibility with ``scikit-learn`` validation
            functions used internally in ``lightgbm``.
        N)r   )rN   r   s     r=   r'  zLGBMModel.n_features_in_  s     $r?   c                 V    |                                  st          d          | j        S )z,:obj:`dict`: The best score of fitted model.z1No best_score found. Need to call fit beforehand.)r   r    r   r   s    r=   best_score_zLGBMModel.best_score_  r_  r?   c                 V    |                                  st          d          | j        S )zc:obj:`int`: The best iteration of fitted model if ``early_stopping()`` callback has been specified.zRNo best_iteration found. Need to call fit with early_stopping callback beforehand.)r   r    r   r   s    r=   best_iteration_zLGBMModel.best_iteration_  s8     ))++ 	$d   ##r?   c                 V    |                                  st          d          | j        S )zT:obj:`str` or :obj:`callable`: The concrete objective used while fitting this model.z0No objective found. Need to call fit beforehand.)r   r    r   r   s    r=   
objective_zLGBMModel.objective_  s0     ))++ 	Y$%WXXXr?   c                 z    |                                  st          d          | j                                        S )  :obj:`int`: True number of boosting iterations performed.

        This might be less than parameter ``n_estimators`` if early stopping was enabled or
        if boosting stopped early due to limits on complexity like ``min_gain_to_split``.

        .. versionadded:: 4.0.0
        z3No n_estimators found. Need to call fit beforehand.r   r    r   current_iterationr   s    r=   n_estimators_zLGBMModel.n_estimators_  s<     ))++ 	\$%Z[[[}..000r?   c                 z    |                                  st          d          | j                                        S )ri  z-No n_iter found. Need to call fit beforehand.rj  r   s    r=   n_iter_zLGBMModel.n_iter_  s<     ))++ 	V$%TUUU}..000r?   c                 V    |                                  st          d          | j        S )z.Booster: The underlying Booster of this model.z.No booster found. Need to call fit beforehand.)r   r    r   r   s    r=   r,  zLGBMModel.booster_  0     ))++ 	W$%UVVV}r?   c                 V    |                                  st          d          | j        S )zK:obj:`dict`: The evaluation results if validation sets have been specified.z<No results found. Need to call fit with eval_set beforehand.)r   r    r   r   s    r=   evals_result_zLGBMModel.evals_result_  s1     ))++ 	e$%cddd!!r?   c                     |                                  st          d          | j                            | j                  S )a  :obj:`array` of shape = [n_features]: The feature importances (the higher, the more important).

        .. note::

            ``importance_type`` attribute is passed to the function
            to configure the type of importance values to be extracted.
        z:No feature_importances found. Need to call fit beforehand.)r   )r   r    r   feature_importancer   r   s    r=   feature_importances_zLGBMModel.feature_importances_  sD     ))++ 	c$%abbb}//@T/UUUr?   c                 z    |                                  st          d          | j                                        S )z:obj:`list` of shape = [n_features]: The names of features.

        .. note::

            If input does not contain feature names, they will be added during fitting in the format ``Column_0``, ``Column_1``, ..., ``Column_N``.
        z3No feature_name found. Need to call fit beforehand.)r   r    r   r  r   s    r=   feature_name_zLGBMModel.feature_name_  s<     ))++ 	\$%Z[[[}))+++r?   c                 z    |                                  st          d          t          j        | j                  S )z:obj:`array` of shape = [n_features]: scikit-learn compatible version of ``.feature_name_``.

        .. versionadded:: 4.5.0
        z8No feature_names_in_ found. Need to call fit beforehand.)r   r    r9   arrayrw  r   s    r=   feature_names_in_zLGBMModel.feature_names_in_  s;     ))++ 	a$%_```x*+++r?   c                     dS )a  Intercept calls to delete ``feature_names_in_``.

        Some code paths in ``scikit-learn`` try to delete the ``feature_names_in_`` attribute
        on estimators when a new training dataset that doesn't have features is passed.
        LightGBM automatically assigns feature names to such datasets
        (like ``Column_0``, ``Column_1``, etc.) and so does not want that behavior.

        However, that behavior is coupled to ``scikit-learn`` automatically updating
        ``n_features_in_`` in those same code paths, which is necessary for compliance
        with its API (via argument ``reset`` to functions like ``validate_data()`` and
        ``check_array()``).

        .. note::

            Do not call ``del estimator.feature_names_in_`` or anything else that invokes
            this method. It is only here for compatibility with ``scikit-learn`` validation
            functions used internally in ``lightgbm``.
        Nrc   r   s    r=   rz  zLGBMModel.feature_names_in_  s	    ( 	r?   )T)NNNNNNNNNNr   r   NNFr   NFFF)r5   N)Ar^   r_   r`   ra   r   r   floatr
   r   rb   r   r9   r   r   r   r   rO   r   staticmethodr   r   boolr   r   r   r   r   _LGBM_ScikitMatrixLiker   r   r   r   r	   _LGBM_ScikitValidSet_LGBM_ScikitEvalMetricTyper   r   r   r   r   r   _lgbmmodel_doc_fitformat_lgbmmodel_doc_custom_eval_noter   _lgbmmodel_doc_predictpropertyr^  r'  setterr   rc  re  rg  rl  rn  r,  r   rr  r:   ru  rw  rz  deleter__classcell__r   s   @r=   r1   r1     s       >>
 $"!'OS37 #"&!#"%Y] $&+s" s" s" s" 	s"
 s" s" s" s" E#'J"JKLs" uT3Y/0s" s"  s" s" s" s"   !s"" #s"$ %s"& uS")*?AT%TUV's"( )s"* +s", -s" s" s" s"r
DcN 
 
 
 
.  S> 
	   \"
(?"; 
 
 
 
 
 
"/t / / / /, ,t ,tCH~ , , , , , ,\3 ;    (TS TT#s(^ T T T Tlhsm     0 5948+/9=*.?C37?C6:<@7=EK.2GK#i i!i i   01	i
 01i (i 4 456i T#Y'i %T*:%;<i $DK0i "$':";<i T/23i 89i 5i Ci  DN+!i" U3g{#BCD#i$ 
%i i i iX 	!! ho !K Ml &B"{q 	" 		
 		
 
	 *	* K$   '+""'<
 <
!<
 <
 	<

  }<
 <
 <
  <
 <
 <
 <
 <
| -33A d&do s 4  GO  S       X  # # # # X# $C $D $ $ $ $  7       X  $ $ $ $ X$ E#'J"JK    X 
1s 
1 
1 
1 X
1 
1 
1 
1 
1 X
1 '    X " " " " X" 
Vbj 
V 
V 
V X
V 	,tCy 	, 	, 	, X	, ,2: , , , X,        r?   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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        ej        j        f                  d!ee         d"ed#ed$df* fd%Zej        j        e_        d$e
eef         fd&Zd@ fd(Z	 	 	 	 	 	 	 	 	 	 	 dAd*ed+ed,ee         d-ee         d.eee                  d/eee                  d0eee                  d1eee                  d2ee         d3ed4ed5eee                  d6eeeeeef                  d$d f fd7Z ej         j        !                    d8d9          Z"e"de"#                    d:                   e"e"#                    d;          d         z   Z"e"de"#                    d<                   e"e"#                    d=          d         z   Z"e"de"#                    d>                   e"e"#                    d?          d         z   e _         xZ$S )Br3   zLightGBM regressor.rs   rt   ru   rv   rw   rx   Nry   rz   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   r5   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 Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rc   r   rO   rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                        r=   rO   zLGBMRegressor.__init__'     0 	 	
 	
 	
'-	
!z	
  i	
 (-		

 &	
 0/	
  i	
 &	
 *>	
 .-	
 0/	
  i	
 *>	
 .-	
  i	
  "z!	
" &#	
$ 6%	
& ,O)	
 	
 	
 	
 	
r?   c                     t          t          t          dd                     rt          j        |           }ni }|                    t
                              |                      |S Nr   )r   r   r)   r   r   r1   rN   r   s     r=   r   zLGBMRegressor._more_tagsX  s[    G.dCCDD 	%066DDDI((..///r?   r/   c                 D    t                                                      S r  )r   r   )rN   r   s    r=   r   zLGBMRegressor.__sklearn_tags__b  s    ww'')))r?   r   r   r   r   r   r   r   r   r   r  r  r  r  r  c                 d    t                                          |||||||||	|
|||           | S )*Docstring is inherited from the LGBMModel.)r   r   r   r   r   r   r  r  r  r  r  )r   r   )rN   r   r   r   r   r   r   r   r   r  r  r  r  r  r   s                 r=   r   zLGBMRegressor.fite  sR    " 	'!!1+#% 3! 	 	
 	
 	
 r?   self : LGBMModelzself : LGBMRegressorgroup :
eval_set :eval_class_weight :eval_init_score :eval_group :eval_metric :r5   r/   )NNNNNNNr   r   NN)%r^   r_   r`   ra   r   r   r}  r
   r   rb   r   r9   r   r   r   r   rO   r1   r   r   r  r   r   r   r	   r  r  r   r   r   r   r   r   replace	_base_docfindr  r  s   @r=   r3   r3   "  s        $"!'OS37 #"&!#"%Y] $&+-
 -
 -
 -
 	-

 -
 -
 -
 -
 E#'J"JKL-
 uT3Y/0-
 -
  -
 -
 -
 -
   !-
" #-
$ %-
& uS")*?AT%TUV'-
( )-
* +-
, --
. 
/-
 -
 -
 -
 -
 -
^ !)1HDcN    * * * * * * 59489=*.?C?C<@7=EK.2EI   !      01	 
 01  4 456  T#Y'  %T*:%;<  "$':";<  89  5  C  DN+  U3gy#@AB  
           D %--.@BXYYI-INN9---.
INN<0022
3	4  AINN+@AAABYy~~^qOrOrOtOtEuuI<inn^<<<=	)..YhJiJiJkJk@llCKKKKKr?   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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        ej        j        f                  d!ee         d"ed#ed$df* fd%Zej        j        e_        d$e
eef         fd&ZdR fd(Z	 	 	 	 	 	 	 	 	 	 	 	 dSd*ed+ed,ee         d-ee         d.eee                  d/eee                  d0eee                  d1eee                  d2eee                  d3ee         d4ed5ed6eee                  d7eeeeeef                  d$d f fd8Z ej         j        !                    d9d:          Z"e"de"#                    d;                   e"e"#                    d<          d         z   Z"e"de"#                    d=                   e"e"#                    d>          d         z   e _        	 	 	 	 	 	 dTd*ed@e$dAedBee         dCe$dDe$dEe$d#efdFZ%ej%        j        e%_        	 	 	 	 	 	 dTd*ed@e$dAedBee         dCe$dDe$dEe$d#ef fdGZ&e'(                    dHdIdJdKdLdMN          e&_        e)d$ej*        fdO            Z+e)d$efdP            Z,e)d$e$fdQ            Z- xZ.S )Ur0   zLightGBM classifier.rs   rt   ru   rv   rw   rx   Nry   rz   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   r5   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 r  r  r  s                        r=   rO   zLGBMClassifier.__init__  r  r?   c                     t          t          t          dd                     rt          j        |           }ni }|                    t
                              |                      |S r  )r   r   r$   r   r   r1   r  s     r=   r   zLGBMClassifier._more_tags  s[    G/tDDEE 	&1$77DDDI((..///r?   r/   c                 x    t                                                      }d|j        _        d|j        _        |S )NTF)r   r   classifier_tagsmulti_classmulti_label)rN   r   r   s     r=   r   zLGBMClassifier.__sklearn_tags__  s3    ww''))+/(+0(r?   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  c                     t          |           t          |           t                                          |           _         j                            |          }t          t           j        j         j                             j        j                                       _	        t           j        t                    r* fd j                                        D              _         j        j         _        t           j                   _         j        d _        t'          |
          st          |
t(                    r|
}nt          |
t*                    r|
g}ng } j        r)t/          |          D ]\  }}|dv rd||<   |dv rd||<   n(t/          |          D ]\  }}|dv rd||<   |d	v rd
||<   |}
d}|qt          |t0                    r|g}g }|D ]T\  }}||u r||u r|                    ||f           %|                    | j                            |          f           Ut5                                          |||||||||	|
||||            S )r  c                 2    i | ]\  }}j         |         |S rc   r  r  s      r=   r  z&LGBMClassifier.fit.<locals>.<dictcomp>  s&    !^!^!^DAq$/!"4a!^!^!^r?   N>   loglossr   r   >   errorbinary_errormulti_error>   r  r   r   >   r  r  r  )r   r   r   r   r   r   r   r  r  r  r  r  )r!   r"   r'   r   _le	transformrn   zipclasses_r   r8   r   r   r   r   rV   r   r   r   r   rm   r   _LGBMClassifier__is_multiclassr*  r)  r+  r   )rN   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r5  r1  indexr   r!  valid_xvalid_yr   s   `                     r=   r   zLGBMClassifier.fit  s   $ 	Q'***$&&**1--X""s48#4dh6H6HIZ6[6[\\]]d'.. 	_!^!^!^!^DDUD[D[D]D]!^!^!^D)dm,,>!"DO $$ 	++t,, &#.  K-- &$/=  #% # A%./?%@%@ @ @ME6!>>>2A(//#<<<2?(/	@ &//?%@%@ A AME6!===2B(//#;;;2@(/*K <@
(E** &$:J$, N N a<<GqLL%%wm4444%%w0B0B70K0K&LMMMM'!!1/+#% 3! 	 	
 	
 	
  r?   r  zself : LGBMClassifierr  r  r  r  FrH  rI  rJ  rK  rL  rM  c                      | j         d|||||||d|}	t          | j                  s|s|s|r|	S t          j        |	d          }
| j                            |
          S )r  r   rH  rI  rJ  rK  rL  rM  r   )axisNrc   )predict_probar   r   r9   argmaxr  inverse_transform)rN   r   rH  rI  rJ  rK  rL  rM  r   resultclass_indexs              r=   r   zLGBMClassifier.predict1  s     $# 	
+'%/	
 	
 	
 	
 DO$$ 	;	 	;Y 	;, 	;M)F333K8--k:::r?   c                     t                      j        d|||||||d|}	t          | j                  r|s|s|st	          d           |	S | j        s|s|s|r|	S t          j        d|	z
  |	f                                          S )r  r  z}Cannot compute class probabilities or labels due to the usage of customized objective function.
Returning raw scores instead.r|   Nrc   )	r   r   r   r   r   r  r9   vstack	transpose)rN   r   rH  rI  rJ  rK  rL  rM  r   r  r   s             r=   r  zLGBMClassifier.predict_probaO  s     ! 	
+'%/	
 	
 	
 	
 DO$$ 
	Ai 
	A9 
	A 
	A0  
 M! 	AY 	A) 	A| 	AM9cFlF344>>@@@r?   z@Return the predicted probability for each class for each sample.r?  predicted_probabilityrS  rT  rU  rV  c                 V    |                                  st          d          | j        S )z;:obj:`array` of shape = [n_classes]: The class label array..No classes found. Need to call fit beforehand.)r   r    r   r   s    r=   r  zLGBMClassifier.classes_z  rp  r?   c                 V    |                                  st          d          | j        S )z":obj:`int`: The number of classes.r  )r   r    r   r   s    r=   
n_classes_zLGBMClassifier.n_classes_  s0     ))++ 	W$%UVVVr?   c                 h    | j         dk    p't          | j        t                    o| j        t          v S )zI:obj:`bool`:  Indicator of whether the classifier is used for multiclass.rR   )r   r8   r   r   r   r   s    r=   __is_multiclasszLGBMClassifier.__is_multiclass  s/     "vz$/3'G'G'uDO_uLuvr?   r  )NNNNNNNNr   r   NNr|  )/r^   r_   r`   ra   r   r   r}  r
   r   rb   r   r9   r   r   r   r   rO   r1   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  r  r  r  r  s   @r=   r0   r0     s        $"!'OS37 #"&!#"%Y] $&+-
 -
 -
 -
 	-

 -
 -
 -
 -
 E#'J"JKL-
 uT3Y/0-
 -
  -
 -
 -
 -
   !-
" #-
$ %-
& uS")*?AT%TUV'-
( )-
* +-
, --
. 
/-
 -
 -
 -
 -
 -
^ !)1HDcN          59489=*.?C37?C<@7=EK.2EIR R!R R   01	R
 01R 4 456R T#Y'R %T*:%;<R $DK0R "$':";<R 89R 5R CR DN+R U3gy#@ABR  
!R R R R R Rh %--.@BYZZI-INN9---.
INN<0022
3	4  <inn^<<<=	)..YhJiJiJkJk@llCK
   '+""'; ;!; ; 	;
  }; ; ;  ; ; ; ; ;8  '/GO
   '+""' A  A! A  A 	 A
  } A  A  A   A  A  A  A  A  A  AD 399V d+do s :  M "*    X C    X w w w w Xw w w w wr?   r0   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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        ej        j        f                  d!ee         d"ed#ed$df* fd%Zej        j        e_        	 	 	 	 	 	 	 	 	 	 	 	 	 	 d@d(ed)ed*ee         d+ee         d,ee         d-eee                  d.eee                  d/eee                  d0eee                  d1eee                  d2ee         d3eee         eed4f         f         d5ed6ed7eee                  d8eeeeeef                  d$d f" fd9Z ej         j        !                    d:d;          Z"e"de"#                    d<                   e"e"#                    d=          d         z   e _        e j        Z"e"$                    d>          \  Z%Z&Z'e% d?e& e' e _         xZ(S )Ar2   a!  LightGBM ranker.

    .. warning::

        scikit-learn doesn't support ranking applications yet,
        therefore this class is not really compatible with the sklearn ecosystem.
        Please use this class mainly for training and applying ranking models in common sklearnish way.
    rs   rt   ru   rv   rw   rx   Nry   rz   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   r5   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 r  r  r  s                        r=   rO   zLGBMRanker.__init__  r  r?   r   rR   rS   rT      r   r   r   r   r   r;   r   r   r   r   r   r  r   .r  r  r  r  c                 ,  
 |t          d          |ǉ
t          d          t          
          t          |          k    rt          d          t          
t                    r5t	          
fdt          t          
                    D                       s.t          
t                    r(t	          d 
D                       rt          d          || _        t                      	                    |||||||||	
|||||           | S )	r  Nz!Should set group for ranking taskz3Eval_group cannot be None when eval_set is not Nonez0Length of eval_group should be equal to eval_setc              3   4   K   | ]}|vp	|         d u V  d S r  rc   )r
  rk   r   s     r=   	<genexpr>z!LGBMRanker.fit.<locals>.<genexpr>  s6      ee+Dz!}/Deeeeeer?   c              3      K   | ]}|d u V  	d S r  rc   )r
  r;   s     r=   r  z!LGBMRanker.fit.<locals>.<genexpr>  s&      >>%>>>>>>r?   zgShould set group for all eval datasets for ranking task; if you use dict, the index should start from 0)r   r   r;   r   r   r   r   r   r  r  r  r  r  )
r   rV   r8   rn   anyrangerm   r   r   r   )rN   r   r   r   r   r;   r   r   r   r   r   r  r   r  r  r  r  r   s             `      r=   r   zLGBMRanker.fit  sO   * =@AAA! !VWWWZCMM11 !STTT:t,,	eeeeeTWXbTcTcNdNdeeeee	 j$//	 >>:>>>>>		 !E  
  '!!1+!#% 3! 	 	
 	
 	
" r?   r  zself : LGBMRankerr  r  zfeature_name :zeval_at : list or tuple of int, optional (default=(1, 2, 3, 4, 5))
        The evaluation positions of the specified metric.
    )NNNNNNNNNr  r   r   NN))r^   r_   r`   ra   r   r   r}  r
   r   rb   r   r9   r   r   r   r   rO   r1   r  r   r   r   r   r	   r  r  r   r   r   r   r   r   r   r  r  r  	partition_before_feature_name_feature_name_after_feature_namer  r  s   @r=   r2   r2     s         $"!'OS37 #"&!#"%Y] $&+-
 -
 -
 -
 	-

 -
 -
 -
 -
 E#'J"JKL-
 uT3Y/0-
 -
  -
 -
 -
 -
   !-
" #-
$ %-
& uS")*?AT%TUV'-
( )-
* +-
, --
. 
/-
 -
 -
 -
 -
 -
^ !)1H 5948+/9=*.?C?C6:<@5D7=EK.2EI#: :!: :   01	:
 01: (: 4 456: T#Y': %T*:%;<: "$':";<: T/23: 89: tCy%S/12: 5: C:  DN+!:" U3gy#@AB#:$ 
%: : : : : :x %--.@BUVVI9INN#8999:
INN#67799
:	; K I?H?R?RSc?d?d<-)<+ , ,,', ,CKKKKKr?   r2   )Rra   r   inspectr   pathlibr   typingr   r   r   r   r	   r
   r   r   numpyr9   scipy.sparsescipybasicr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   callbackr   r   compatr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   enginer.   r/   __all__r}  r   r:   r   spmatrixr  rb   rh   r   r  r  r>   rC   rG   rI   re   r  r  r  rq   r1   r3   r0   r2   rc   r?   r=   <module>r     s   2 2              S S S S S S S S S S S S S S S S S S S S                                         " 9 8 8 8 8 8 8 8                                 "       &%%%%%%   tE{DI%	&'J	L	  ',	"*	rz*bj"*$%	'
 	"*	rz8BJ+?@bj"*$%	'
 	"*	rz8BJ+?"*AUVbj"*$%	'' #" "'	"*	rz*$	& 	"*	rz*)*	,
 	"*	rz8BJ+?@$	& 	"*	rz8BJ+?@)*	,
 	"*	rz8BJ+?"*AUV$	& 	"*	rz8BJ+?"*AUV)*	,-" : #"s22	346 
 3_DE  Xbj=Q     RZ    ' hrz>R    Th Th Th Th Th Th Th ThnNc Nc Nc Nc Nc Nc Nc Nch< |# >, ^:tCH~tCy89:: : 	:
 c]: : : :0y y y y y y y yxkm km km km km&	 km km km\{w {w {w {w {w() {w {w {w|B, B, B, B, B, B, B, B, B, B,r?   