当前位置:   article > 正文

LGBMRegressor拟合函数官方文档_lgb.lgbmregressor

lgb.lgbmregressor

Signature:
lgb.LGBMRegressor.fit(
self,
X,
y,
sample_weight=None,
init_score=None,
eval_set=None,
eval_names=None,
eval_sample_weight=None,
eval_init_score=None,
eval_metric=None,
early_stopping_rounds=None,
verbose=‘warn’,
feature_name=‘auto’,
categorical_feature=‘auto’,
callbacks=None,
init_model=None,
)
Docstring:
Build a gradient boosting model from the training set (X, y).

Parameters

X : array-like or sparse matrix of shape = [n_samples, n_features]
Input feature matrix.
y : array-like of shape = [n_samples]
The target values (class labels in classification, real numbers in regression).
sample_weight : array-like of shape = [n_samples] or None, optional (default=None)
Weights of training data.
init_score : array-like 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)
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 array, or None, optional (default=None)
Weights of eval data.
eval_init_score : list of array, 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.
early_stopping_rounds : int or None, optional (default=None)
Activates early stopping. The model will train until the validation score stops improving.
Validation score needs to improve at least every early_stopping_rounds round(s)
to continue training.
Requires at least one validation data and one metric.
If there’s more than one, will check all of them. But the training data is ignored anyway.
To check only the first metric, set the first_metric_only parameter to True
in additional parameters **kwargs of the model constructor.
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.

.. rubric:: Example

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

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 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.
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 : object
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_true : array-like of shape = [n_samples]
    The target values.
y_pred : array-like of shape = [n_samples] or 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 : array-like of shape = [n_samples]
    The weight of samples.
group : array-like
    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``.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

For multi-class task, the y_pred is group by class_id first, then group by row_id.
If you want to get i-th row y_pred in j-th class, the access way is y_pred[j * num_data + i].
File: e:\anaconda3\lib\site-packages\lightgbm\sklearn.py
Type: function

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/801591
推荐阅读
相关标签
  

闽ICP备14008679号