macrosynergy.learning.forecasting.model_systems.base_regression_system#

class BaseRegressionSystem(roll='full', min_xs_samples=2, data_freq=None)[source]#

Bases: BaseEstimator, RegressorMixin, ABC

fit(X, y)[source]#

Fit a regression on each cross-section of a panel, subject to availability.

Parameters:
  • X (pd.DataFrame) – Input feature matrix.

  • y (pd.Series, pd.DataFrame or np.ndarray) – Target variable.

Returns:

self – Fitted regression system object.

Return type:

BaseRegressionSystem

predict(X)[source]#

Make predictions over a panel dataset based on trained observation-specific models.

Parameters:

X (pd.DataFrame) – Input feature matrix.

Returns:

predictions – Pandas series of predictions, multi-indexed by cross-section and date.

Return type:

pd.Series

roll_dates(roll, X_section, y_section, unique_dates)[source]#

Adjust dataset to be contained within a rolling window.

Parameters:
  • roll (int) – The lookback of the rolling window.

  • X_section (pd.DataFrame) – Input feature matrix for the cross-section.

  • y_section (pd.Series) – Target variable for the cross-section.

  • unique_dates (list) – List of unique dates in the cross-section.

Returns:

  • X_section (pd.DataFrame) – Input feature matrix for the cross-section, adjusted for the rolling window.

  • y_section (pd.Series) – Target variable for the cross-section, adjusted for the rolling window.

abstract store_model_info(section, model)[source]#

Store necessary model information for explainability.

Parameters:
  • section (str) – The identifier of the cross-section.

  • model (RegressorMixin) – The fitted regression model.

Notes

Must be overridden.

abstract create_model()[source]#

Instantiate a regression model for a given cross-section.

Notes

Must be overridden.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BaseRegressionSystem#

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object