LgbPredictConfig¶
LgbPredictConfig
¶
Configuration for LightGBM prediction parameters.
This class encapsulates all parameters that can be passed to the predict()
method of a LightGBM Booster, except for the data parameter itself.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_iteration
|
int
|
Start index of the iteration to predict. If <= 0, starts from the first iteration. |
0
|
num_iteration
|
int | 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. - If <= 0: all iterations from start_iteration are used (no limits). |
None
|
raw_score
|
bool
|
Whether to predict raw scores. - If False: returns transformed scores (e.g., probabilities for binary classification). - If True: returns raw scores before transformation (e.g., raw log-odds for binary classification). |
False
|
pred_leaf
|
bool
|
Whether to predict leaf indices. - If True: returns the index of the leaf that each sample ends up in for each tree. Output shape is [n_samples, n_trees] or [n_samples, n_trees * n_classes] for multiclass. - If False: returns predicted values. |
False
|
pred_contrib
|
bool
|
Whether to predict feature contributions (SHAP values). - If True: returns feature contributions for each prediction, including the base value (intercept) as the last column. Output shape is [n_samples, n_features + 1] or [n_samples, (n_features + 1) * n_classes] for multiclass. - If False: returns predicted values. |
False
|
data_has_header
|
bool
|
Whether the data file has a header when data is provided as a file path. Only used when prediction data is a string path to a text file (CSV, TSV, or LibSVM). |
False
|
validate_features
|
bool
|
Whether to validate that features in the prediction data match those used during training. Only applies when prediction data is a pandas DataFrame. |
False
|
See Also
lightgbm.Booster.predict : The underlying LightGBM prediction method.
Notes
- Only one of
pred_leaf
andpred_contrib
can be True at a time. - When using custom objective functions, raw_score=False still returns raw predictions since the transformation function is not known.
Examples:
>>> from factrainer.lightgbm import LgbPredictConfig
>>> # Standard prediction
>>> config = LgbPredictConfig()
>>> # Raw score prediction
>>> config = LgbPredictConfig(raw_score=True)
>>> # Get SHAP values
>>> config = LgbPredictConfig(pred_contrib=True)
>>> # Predict leaf indices
>>> config = LgbPredictConfig(pred_leaf=True)