quantlab.model.predefined.realmlp.RealMLPRegressor#
- class quantlab.model.predefined.realmlp.RealMLPRegressor(config)[source]#
Bases:
TabkitRegressorPredict future returns with a pytabkit RealMLP (tuned defaults).
One
RealMLP_TD_Regressoris fitted on the flattened rows. Each label is one output of a multi-output regression, and 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
RealMLP_TD_Regressor(n_epochs,hidden_sizes,lr,device,n_threads, …). Withoutdevicethe head trains on"cuda"when torch sees a CUDA device and on"cpu"otherwise; Apple MPS is used only when asked for (device="mps"). The device chosen is recorded inresolved_hyperparameters. The network stays on it for evaluation and prediction; the checkpoint is written from the CPU so it loads without CUDA, and a loaded model is moved to the default device by the same rule.With
hyperparameters["early_stopping"]set and validation rows, pytabkit’s early stopping watches the validation loss withearly_stopping_additive_patience = hyperparameters["early_stopping_patience"]and a multiplicative patience of1.0, so patience counts epochs without improvement. The fitted model is already rolled back to the best epoch, so the.joblibcheckpoint is the best model. The stopping epoch is written to the run summary asstop_epoch. Without a usable validation segment a warning is logged and alln_epochsare trained. Every tracking run also gets a per-epoch curve: the mean training loss (train-loss) and the validation error pytabkit stops on (val-rmse), atstep=epoch, plusbest_val_rmseandepochs_trainedin the summary, through a Lightning callback injected into pytabkit’s trainer (seequantlab.model.predefined._support.tabkit.active_callbacks).train_cv(rolling walk-forward cross-validation) is inherited. Each fold does its own early stopping and writes its own.joblib. The folds train one after another.- 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": 5, ... "n_epochs": 50, "n_threads": 4, ... }, ... ) >>> model = RealMLPRegressor(config) >>> checkpoint = model.collect().train() >>> checkpoint.name 'RealMLPRegressor_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.