lightgbm.DaskLGBMClassifier

class lightgbm.DaskLGBMClassifier(boosting_type='gbdt', num_leaves=31, max_depth=- 1, learning_rate=0.1, n_estimators=100, subsample_for_bin=200000, objective=None, class_weight=None, min_split_gain=0.0, min_child_weight=0.001, min_child_samples=20, subsample=1.0, subsample_freq=0, colsample_bytree=1.0, reg_alpha=0.0, reg_lambda=0.0, random_state=None, n_jobs=- 1, silent=True, importance_type='split', client=None, **kwargs)[source]

Bases: lightgbm.sklearn.LGBMClassifier, lightgbm.dask._DaskLGBMModel

Distributed version of lightgbm.LGBMClassifier.

__init__(boosting_type='gbdt', num_leaves=31, max_depth=- 1, learning_rate=0.1, n_estimators=100, subsample_for_bin=200000, objective=None, class_weight=None, min_split_gain=0.0, min_child_weight=0.001, min_child_samples=20, subsample=1.0, subsample_freq=0, colsample_bytree=1.0, reg_alpha=0.0, reg_lambda=0.0, random_state=None, n_jobs=- 1, silent=True, importance_type='split', client=None, **kwargs)[source]

Construct a gradient boosting model.

Parameters
  • boosting_type (string, optional (default='gbdt')) – ‘gbdt’, traditional Gradient Boosting Decision Tree. ‘dart’, Dropouts meet Multiple Additive Regression Trees. ‘goss’, Gradient-based One-Side Sampling. ‘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.

  • 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 (string, 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)) – Frequence 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 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, optional (default=-1)) – Number of parallel threads.

  • silent (bool, optional (default=True)) – Whether to print messages while running boosting.

  • importance_type (string, 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.

  • client (dask.distributed.Client or None, optional (default=None)) – Dask 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.

  • **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.

Methods

__init__([boosting_type, num_leaves, …])

Construct a gradient boosting model.

fit(X, y[, sample_weight, init_score])

Build a gradient boosting model from the training set (X, y).

get_params([deep])

Get parameters for this estimator.

predict(X, **kwargs)

Return the predicted value for each sample.

predict_proba(X, **kwargs)

Return the predicted probability for each class for each sample.

set_params(**params)

Set the parameters of this estimator.

to_local()

Create regular version of lightgbm.LGBMClassifier from the distributed version.

Attributes

best_iteration_

The best iteration of fitted model if early_stopping_rounds has been specified.

best_score_

The best score of fitted model.

booster_

The underlying Booster of this model.

classes_

The class label array.

client_

Dask client.

evals_result_

The evaluation results if early_stopping_rounds has been specified.

feature_importances_

The feature importances (the higher, the more important).

feature_name_

The names of features.

n_classes_

The number of classes.

n_features_

The number of features of fitted model.

n_features_in_

The number of features of fitted model.

objective_

The concrete objective used while fitting this model.

property best_iteration_

The best iteration of fitted model if early_stopping_rounds has been specified.

Type

int or None

property best_score_

The best score of fitted model.

Type

dict or None

property booster_

The underlying Booster of this model.

Type

Booster

property classes_

The class label array.

Type

array of shape = [n_classes]

property client_

Dask client.

This property can be passed in the constructor or updated with model.set_params(client=client).

Type

dask.distributed.Client

property evals_result_

The evaluation results if early_stopping_rounds has been specified.

Type

dict or None

property feature_importances_

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.

Type

array of shape = [n_features]

property feature_name_

The names of features.

Type

array of shape = [n_features]

fit(X, y, sample_weight=None, init_score=None, **kwargs)[source]

Build a gradient boosting model from the training set (X, y).

Parameters
  • X (Dask Array or Dask DataFrame of shape = [n_samples, n_features]) – Input feature matrix.

  • y (Dask Array, Dask DataFrame or Dask Series of shape = [n_samples]) – The target values (class labels in classification, real numbers in regression).

  • sample_weight (Dask Array, Dask DataFrame, Dask Series of shape = [n_samples] or None, optional (default=None)) – Weights of training data.

  • init_score (Dask Array, Dask DataFrame, Dask Series of shape = [n_samples] or None, optional (default=None)) – Init score of training data.

  • verbose (bool or int, optional (default=True)) –

    Requires at least one evaluation data. If True, the eval metric on the eval set is printed at each boosting stage. If int, the eval metric on the eval set is printed at every verbose boosting stage. The last boosting stage or the boosting stage found by using early_stopping_rounds is also printed.

    Example

    With verbose = 4 and at least one item in eval_set, an evaluation metric is printed every 4 (instead of 1) boosting stages.

  • feature_name (list of strings or 'auto', optional (default='auto')) – Feature names. If ‘auto’ and data is pandas DataFrame, data columns names are used.

  • categorical_feature (list of strings or int, or 'auto', optional (default='auto')) – Categorical features. If list of int, interpreted as indices. If list of strings, 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 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.

  • **kwargs – Other parameters passed through to LGBMClassifier.fit().

get_params(deep=True)

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 – Parameter names mapped to their values.

Return type

dict

property n_classes_

The number of classes.

Type

int

property n_features_

The number of features of fitted model.

Type

int

property n_features_in_

The number of features of fitted model.

Type

int

property objective_

The concrete objective used while fitting this model.

Type

string or callable

predict(X, **kwargs)[source]

Return the predicted value for each sample.

Parameters
  • X (Dask Array or Dask DataFrame of shape = [n_samples, n_features]) – 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.

  • **kwargs – Other parameters for the prediction.

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]) – If pred_contrib=True, the feature contributions for each sample.

predict_proba(X, **kwargs)[source]

Return the predicted probability for each class for each sample.

Parameters
  • X (Dask Array or Dask DataFrame of shape = [n_samples, n_features]) – 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.

  • **kwargs – Other parameters for the prediction.

Returns

  • predicted_probability (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]) – If pred_contrib=True, the feature contributions for each sample.

set_params(**params)

Set the parameters of this estimator.

Parameters

**params – Parameter names with their new values.

Returns

self – Returns self.

Return type

object

to_local()[source]

Create regular version of lightgbm.LGBMClassifier from the distributed version.

Returns

model – Local underlying model.

Return type

lightgbm.LGBMClassifier