quantlab.model.predefined.linear.LinearRegressor#
- class quantlab.model.predefined.linear.LinearRegressor(config)[source]#
Bases:
QlibLibraryHeadQlib’s linear model on the rows of the cross-sectional rank target.
Features are clipped to ±3 and NaN becomes 0, as Qlib’s
RobustZScoreNorm(clip_outlier=True)andFillnaleave them; the training target isCSRankNorm(training_target"cs_rank"). Hyperparameters, with Qlib’s defaults:estimator("ols")"ols":min |y - Xw|^2;"ridge": plusalpha |w|^2;"lasso":|y - Xw|^2 / (2n) + alpha |w|_1(scikit-learn’s scaling);"nnls": least squares withw >= 0.alpha(0.0)The penalty of ridge and lasso; must be 0 for the others.
fit_intercept(False)Whether to fit an intercept: by centring
Xandy, and for nnls by a column of ones, constrained like the other coefficients, as in Qlib.include_valid(False)Whether the validation rows are fitted too.
Early stopping does not apply. The model is
{"coef": [F], "intercept": float}.Known difference from Qlib’s implementation: no
RobustZScoreNormis fitted on the training span (the features are expected standardised already); every estimator is solved fromX'Xrather than by scikit-learn on the rows, which gives the same coefficients up to floating point.- Parameters:
- configModelConfig
Factors, one label, dates and hyperparameters.
- Raises:
- ValueError
At training, if the model has more than one label,
estimatoris unknown, oralphais set for an estimator without a penalty.
Examples
>>> head = LinearRegressor(ModelConfig( ... factors=[factor], labels=[label], model_save_dir="checkpoints", ... factor_data_strategy="read", label_data_strategy="read", ... train_start="2024-01-01", train_end="2024-05-31", ... test_start="2024-06-01", test_end="2024-07-18", ... )).collect() >>> head.train().name 'LinearRegressor_total.joblib'
- DEFAULTS = {'alpha': 0.0, 'estimator': 'ols', 'fit_intercept': False, 'include_valid': False}#
The library’s parameters, Qlib’s benchmark values.
- LIBRARY_DEFAULTS = {'early_stopping': False, 'early_stopping_patience': 50, 'training_target': 'cs_rank'}#
Defaults of the reserved keys this variant reads itself.