fit¶
Train a model.
Method call format¶
Parameters¶
The training parameters are set in the constructor of the TBoostRegressor class.
X¶
Description¶
The input training dataset in the form of a two-dimensional feature matrix.
The description is different for each group of possible types.
Possible types
polars.DataFrame, polars.LazyFrame
The column names become the feature names (feature_names_in_). String, Categorical
and Enum columns are treated as categorical features,
and numeric columns are converted to float32, with nulls treated as missing values. A
LazyFrame is collected at the start of the fit.
The columns named by the y, sample_weight, exposure, groups and offset parameters
are not used as features.
numpy.ndarray, other array-like data
Every feature is numerical unless it is listed in the
categorical_features
parameter. For a pandas DataFrame the column names become the feature names, but at
prediction time the features are matched by position. A Fortran-ordered (column-major)
float32 array is the cheapest input: its columns are copied without a transpose.
Default value
Required parameter
y¶
Description¶
The target variables (in other words, the objects' label values) for the training dataset, on
the natural scale (not the link scale). A string names a column of a polars X, which is then
not used as a feature.
Possible types
- numpy.ndarray of shape
(object_count,) - polars.Series
- list
- string
Default value
Required parameter
sample_weight¶
Description¶
The weight of each object in the input data in the form of a one-dimensional array-like data.
A string names a column of a polars X.
By default, it is set to 1 for all objects.
Possible types
- numpy.ndarray of shape
(object_count,) - polars.Series
- list
- string
Default value
None
exposure¶
Description¶
The exposure of each object (for example, the duration of a policy), for the poisson, gamma
and tweedie objectives. The predicted rate is multiplied by the exposure before it is compared
with the target: \(\log(exposure)\) is added to the raw score as an offset. A string names a column
of a polars X.
By default, it is set to 1 for all objects. Not supported for the squared_error objective.
Possible types
- numpy.ndarray of shape
(object_count,) - polars.Series
- list
- string
Default value
None
groups¶
Description¶
The entity each object belongs to, for panel data where the same entity (for example, a policy
renewed each year) contributes several similar objects. A string names a column of a polars X.
When it is given, whole groups are assigned to one side of every internal split instead of single objects: the validation objects of early stopping, the bag samples and the pruning folds. Otherwise near-duplicate objects of the same entity leak across these splits, early stopping does not trigger, and pruning is biased. A grouping in which every group has one object is the same as no grouping.
Possible types
- numpy.ndarray of shape
(object_count,) - polars.Series
- list
- string
Default value
None (every object is its own group)
offset¶
Description¶
A link-scale offset added to the raw score of each object and never learned (the equivalent of
XGBoost's base_margin and LightGBM's init_score). A string names a column of a polars X.
For the squared_error objective, the fit is exactly the fit of y - offset. For the log and
logit links it is added to the exposure offset, \(\log(exposure) + offset\).
Prediction methods add it only when it is passed to them again (their offset parameter);
otherwise objects are scored with a zero offset.
Possible types
- numpy.ndarray of shape
(object_count,) - polars.Series
- list
- string
Default value
None
callbacks¶
Description¶
Functions called after every iteration of the training of the deployed model, each with a dictionary:
phase—"fit".bag,n_bags— The bag and the number of bags.round— The iteration, starting at 1.n_trees— The maximum number of trees (then_treesparameter).train_deviance,eval_deviance— The mean deviance on the bag's training objects and on its validation objects (Nonewithout validation objects).
The bags are trained in parallel, so calls for different bags interleave. Each bag's iterations
arrive in order, all on the calling thread. A true return value stops that bag (bag in the
dictionary) after the iteration, just as early stopping stops each bag at its own iteration
(stopping_reason_per_bag_ is then "callback"). To stop the whole training, return a true
value for every bag. A function that decides from the dictionary alone stops the same bags at the
same iterations on every run. An exception stops the training and is raised from fit. Both
deviances of every iteration are kept in evals_result_. The deviance on the training objects
takes an extra pass per iteration, 5–11% of the training time.
Possible types
- callable
- list of callables
Default value
None
Return value¶
The estimator itself, trained.
The attributes n_trees_per_bag_, stopping_reason_per_bag_, n_trees_, stopping_reason_ and
evals_result_ describe the boosting (see Attributes).