Bases: LGBMClassifier
, _DaskLGBMModel
Distributed version of lightgbm.LGBMClassifier.
Construct a gradient boosting model.
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).
Changed in version 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.
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.
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_truenumpy 1-D array of shape = [n_samples]
The target values.
- y_prednumpy 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.
- weightnumpy 1-D array of shape = [n_samples]
The weight of samples. Weights should be non-negative.
- groupnumpy 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.- gradnumpy 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.
- hessnumpy 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.
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 metadata routing of this object.
get_params
([deep])
Get parameters for this estimator.
predict
(X[, raw_score, start_iteration, ...])
Return the predicted value for each sample.
predict_proba
(X[, raw_score, ...])
Return the predicted probability for each class for each sample.
score
(X, y[, sample_weight])
Return accuracy on provided data and labels.
set_fit_request
(*[, eval_class_weight, ...])
Request metadata passed to the fit
method.
set_params
(**params)
Set the parameters of this estimator.
set_predict_proba_request
(*[, ...])
Request metadata passed to the predict_proba
method.
set_predict_request
(*[, num_iteration, ...])
Request metadata passed to the predict
method.
set_score_request
(*[, sample_weight])
Request metadata passed to the score
method.
to_local
()
Create regular version of lightgbm.LGBMClassifier from the distributed version.
Attributes
The best iteration of fitted model if early_stopping()
callback has been specified.
int
The best score of fitted model.
dict
The underlying Booster of this model.
The class label array.
array
of shape = [n_classes]
Dask client.
This property can be passed in the constructor or updated with model.set_params(client=client)
.
dask.distributed.Client
The evaluation results if validation sets have been specified.
dict
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.
array
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
.
list
of shape = [n_features]
scikit-learn compatible version of .feature_name_
.
Added in version 4.5.0.
array
of shape = [n_features]
Build a gradient boosting model from the training set (X, y).
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 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.
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 (list of Dask Array or Dask Series, or None, optional (default=None)) – 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 (list of Dask Array, Dask Series or Dask DataFrame (for multi-class task), or None, optional (default=None)) – Init score 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.
**kwargs – Other parameters passed through to LGBMClassifier.fit()
.
self – Returns self.
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_truenumpy 1-D array of shape = [n_samples]
The target values.
- y_prednumpy 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.- weightnumpy 1-D array of shape = [n_samples]
The weight of samples. Weights should be non-negative.
- groupnumpy 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_namestr
The name of evaluation function (without whitespace).
- eval_resultfloat
The eval result.
- is_higher_betterbool
Is eval result higher better, e.g. AUC is
is_higher_better
.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
routing – A MetadataRequest
encapsulating routing information.
MetadataRequest
Get parameters for this estimator.
deep (bool, optional (default=True)) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
params – Parameter names mapped to their values.
dict
The number of classes.
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
.
Added in version 4.0.0.
int
The number of features of fitted model.
int
The number of features of fitted model.
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
.
Added in version 4.0.0.
int
The concrete objective used while fitting this model.
str
or callable
Return the predicted value for each sample.
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.
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.
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.
Return the predicted probability for each class for each sample.
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.
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.
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] 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.
Return accuracy on provided data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.
score – Mean accuracy of self.predict(X)
w.r.t. y.
float
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config()
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
True
: metadata is requested, and passed to fit
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it to fit
.
None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline
. Otherwise it has no effect.
eval_class_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_class_weight
parameter in fit
.
eval_init_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_init_score
parameter in fit
.
eval_metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_metric
parameter in fit
.
eval_names (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_names
parameter in fit
.
eval_sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_sample_weight
parameter in fit
.
eval_set (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for eval_set
parameter in fit
.
init_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for init_score
parameter in fit
.
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight
parameter in fit
.
self – The updated object.
object
Set the parameters of this estimator.
**params – Parameter names with their new values.
self – Returns self.
object
Request metadata passed to the predict_proba
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config()
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
True
: metadata is requested, and passed to predict_proba
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it to predict_proba
.
None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline
. Otherwise it has no effect.
num_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for num_iteration
parameter in predict_proba
.
pred_contrib (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for pred_contrib
parameter in predict_proba
.
pred_leaf (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for pred_leaf
parameter in predict_proba
.
raw_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for raw_score
parameter in predict_proba
.
start_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for start_iteration
parameter in predict_proba
.
validate_features (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for validate_features
parameter in predict_proba
.
self – The updated object.
object
Request metadata passed to the predict
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config()
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
True
: metadata is requested, and passed to predict
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it to predict
.
None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline
. Otherwise it has no effect.
num_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for num_iteration
parameter in predict
.
pred_contrib (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for pred_contrib
parameter in predict
.
pred_leaf (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for pred_leaf
parameter in predict
.
raw_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for raw_score
parameter in predict
.
start_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for start_iteration
parameter in predict
.
validate_features (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for validate_features
parameter in predict
.
self – The updated object.
object
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config()
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
True
: metadata is requested, and passed to score
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it to score
.
None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline
. Otherwise it has no effect.
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight
parameter in score
.
self – The updated object.
object
Create regular version of lightgbm.LGBMClassifier from the distributed version.
model – Local underlying model.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4