quantlab.model.predefined.xgb_td.XGBTDRegressor#
- class quantlab.model.predefined.xgb_td.XGBTDRegressor(config)[source]#
Bases:
TabkitRegressorPredict future returns with pytabkit’s tuned-default XGBoost.
self.modelis a list with one fitted estimator per label, inget_label_names()order, because pytabkit’s XGBoost estimator does not support multi-output regression. Every estimator is trained on the same rows: the cells whose training target is valid in every label. Headline metrics are computed on the primary label, index 0. NaN imputation and the hyperparameter record are inherited fromTabkitRegressor.Hyperparameters are the constructor arguments of
XGB_TD_Regressor(n_estimators,max_depth,lr,subsample,n_threads,device, …). Unlessdeviceis given, training runs on"cuda"when xgboost can train on CUDA here and on"cpu"otherwise, never on Apple MPS (the rule ofXGBoostRegressor). pytabkit forwards no device to xgboost, so the head injects it into pytabkit’s innerxgboost.traincall; the device is recorded inresolved_hyperparameters. The Boosters stay on that device in memory; the checkpoint is written withdevice="cpu"so it loads without CUDA, and a loaded model is placed on the default device by the same rule. pytabkit’s tuned defaults fill in whatever is not given: 1000 rounds, depth 9, learning rate 0.05, subsample 0.7.With validation rows, pytabkit always selects the round with the lowest validation error, so the
.joblibcheckpoint predicts with the best round, and that round count is written to the run summary asbest_n_estimators(primary label) andbest_n_estimators/{label}(every label). Withhyperparameters["early_stopping"]set, training additionally halts afterhyperparameters["early_stopping_patience"]rounds without improvement; the value is recorded asearly_stopping_roundsinresolved_hyperparameters(Nonewhen off). Without a usable validation segment a warning is logged, all rounds are trained and the estimator is pinned to predict with all of them (see_pin_all_rounds). No per-round curve is logged.train_cv(rolling walk-forward cross-validation) is inherited. Each fold selects its own best round and writes its own.joblib. The folds train one after another.Every tracking run gets, per label, the validation curve of each boosting round (
val-rmse, orval-rmse/<label>with several labels, atstep=round), the selected round (best_n_estimators), the rounds trained (num_boosted_rounds) and the per-factor importance with its tables, exactly asXGBoostRegressorrecords them. The callback is injected into pytabkit’s innerxgboost.traincall (seequantlab.model.predefined._support.tabkit.active_callbacks).- Parameters:
- configModelConfig
Factors, labels, date ranges, early-stopping settings and hyperparameters. See
ModelConfig.
Examples
>>> config = ModelConfig( ... factors=[alpha], # factor objects ... labels=[fwd_return], # label objects ... model_save_dir="checkpoints", ... factor_data_strategy="read", ... label_data_strategy="read", ... train_start="2024-01-01", train_end="2024-02-09", ... test_start="2024-02-10", test_end="2024-02-29", ... hyperparameters={ ... "early_stopping": True, "early_stopping_patience": 50, ... "n_estimators": 500, "n_threads": 4, ... }, ... ) >>> model = XGBTDRegressor(config) >>> checkpoint = model.collect().train() >>> checkpoint.name 'XGBTDRegressor_total.joblib' >>> model.predict(np.zeros((5, 2, 3), dtype="float32")).shape (5, 2, 1) >>> model.train_cv(train_periods=500)
- DEFAULT_PARAMS = {'val_fraction': 0.0, 'verbosity': 0}#
Estimator constructor arguments applied before the config seed, the early-stopping keys and the user’s hyperparameters.