quantlab.model.predefined.mlp.MLPRegressor#

class quantlab.model.predefined.mlp.MLPRegressor(config)[source]#

Bases: QlibSequenceHead

Qlib’s MLP benchmark model (DNNModelPytorch) on rows.

MLPNet on each cell’s latest bar. One epoch here is Qlib’s eval_steps steps: each step draws batch_size training rows at random with replacement, and after every epoch the validation loss is computed, ReduceLROnPlateau (factor 0.5, patience 10, relative threshold 1e-4, lower bound 1e-5) steps on it, the epoch with the lowest one is kept, and training stops after early_stop epochs without a strictly lower one. The training target is CSRankNorm of the label, the loss the MSE, the optimizer Adam with weight decay; gradients are not clipped, as in Qlib. Hyperparameters, with Qlib’s Alpha158 benchmark values (workflow_config_mlp_Alpha158.yaml) as defaults: layers ([256]), act ("LeakyReLU"), batch_size (8192), lr (2e-3), weight_decay (2e-4), eval_steps (20), epochs (400, Qlib’s 8000 max_steps over 20 steps an epoch) and early_stop (50). window_bars is 1.

Known differences from Qlib’s implementation:

  • the features are the model’s factors, and no RobustZScoreNorm is fitted on the training span: the default _transform_feature clips to ±3 and fills NaN with 0;

  • the validation loss is averaged per bar, where Qlib pools every row;

  • the output has one column per label instead of one.

Parameters:
configModelConfig

Factors, labels, dates and hyperparameters.

Examples

>>> MLPRegressor(config).collect().train().name
'MLPRegressor_total.pth'
DEFAULTS = {'act': 'LeakyReLU', 'batch_size': 8192, 'early_stop': 50, 'epochs': 400, 'eval_steps': 20, 'layers': [256], 'lr': 0.002, 'weight_decay': 0.0002, 'window_bars': 1}#

Every unset hyperparameter’s value; a head gives Qlib’s benchmark values.

grad_clip_value = None#

Gradient value clip of the default _train_one_batch; None disables.