macrosynergy.learning.forecasting.linear_model.ls_regressors#

class SignWeightedLinearRegression(fit_intercept=True, positive=False, alpha=0, shrinkage_type='l1')[source]#

Bases: SignWeightedRegressor

set_params(**params)[source]#

Setter method to update the parameters of the SignWeightedLinearRegression.

Parameters:

**params (dict) – Dictionary of parameters to update.

Returns:

The SignWeightedLinearRegression instance with updated parameters.

Return type:

self

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

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

class TimeWeightedLinearRegression(fit_intercept=True, positive=False, half_life=252, alpha=0, shrinkage_type='l1')[source]#

Bases: TimeWeightedRegressor

set_params(**params)[source]#

Setter method to update the parameters of the TimeWeightedLinearRegression.

Parameters:

**params (dict) – Dictionary of parameters to update.

Returns:

The TimeWeightedLinearRegression instance with updated parameters.

Return type:

self

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

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

class ModifiedLinearRegression(method, fit_intercept=True, positive=False, error_offset=0.01, bootstrap_method='panel', bootstrap_iters=1000, resample_ratio=1, analytic_method=None)[source]#

Bases: BaseModifiedRegressor

adjust_analytical_se(model, X, y, analytic_method=None)[source]#

Adjust the coefficients of the OLS linear regression model by an analytical standard error formula.

Parameters:
  • model (LinearRegression) – The underlying OLS linear regression model to be modified.

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

  • y (pd.DataFrame or pd.Series) – Target vector associated with each sample in X.

  • analytic_method (str, default = None) – The analytic method used to calculate standard errors.

Returns:

  • intercept (float) – Adjusted intercept.

  • coef (np.ndarray) – Adjusted coefficients.

Notes

By default, the calculated standard errors use the usual standard error expression for OLS linear regression models under the assumption of multivariate normality, homoskedasticity and zero mean of the model errors. If analytic_method = “White”, the HC3 White estimator is used.

References

[1] https://online.stat.psu.edu/stat462/node/131/ [2] https://en.wikipedia.org/wiki/Heteroskedasticity-consistent_standard_errors

set_params(**params)[source]#

Setter method to update the parameters of the ModifiedLinearRegression

Parameters:

**params (dict) – Dictionary of parameters to update.

Returns:

The ModifiedLinearRegression instance with updated parameters.

Return type:

self

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

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

class ModifiedSignWeightedLinearRegression(method, fit_intercept=True, positive=False, error_offset=0.01, bootstrap_method='panel', bootstrap_iters=1000, resample_ratio=1, analytic_method=None)[source]#

Bases: BaseModifiedRegressor

adjust_analytical_se(model, X, y, analytic_method=None)[source]#

Adjust the coefficients of the SWLS linear regression model by an analytical standard error formula.

Parameters:
  • model (SignWeightedLinearRegression) – The underlying SWLS linear regression model to be modified.

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

  • y (pd.DataFrame or pd.Series) – Target vector associated with each sample in X.

  • analytic_method (str, default = None) – The analytic method used to calculate standard errors.

Returns:

  • intercept (float) – Adjusted intercept.

  • coef (np.ndarray) – Adjusted coefficients.

Notes

The analytical parameter estimates for WLS are:

\[\hat{\beta}^{\text{WLS}} = (X^{\intercal}WX)^{-1}X^{\intercal}y\]
where:
  • X is the input feature matrix, possibly with a column of ones representing the choice of an intercept.

  • W is the positive-definite, symmetric weight matrix, a diagonal matrix with sample weights along the main diagonal.

  • y is the dependent variable vector.

Since W is a positive-definite, symmetric matrix, it has a square root equal to the diagonal matrix with square roots of the sample weights along the diagonal. Hence, the WLS estimator can be rewritten as:

\[\hat{\beta}^{\text{WLS}} = ((({W^{1/2}X})^{\intercal}(W^{1/2}X))^{-1}(W^{1/2}X)^{\intercal}(W^{1/2}y))\]

This is precisely the OLS estimator for a rescaled matrix

\[\tilde {X} = W^{1/2}X\]

and a rescaled dependent variable

\[\tilde {y} = W^{1/2}y\]

Hence, the usual standard error estimate and White’s estimator can be applied based on a rescaling of the design matrix and associated target vector.

set_params(**params)[source]#

Setter method to update the parameters of the ModifiedSignWeightedLinearRegression.

Parameters:

**params (dict) – Dictionary of parameters to update.

Returns:

The ModifiedSignWeightedLinearRegression instance with updated parameters.

Return type:

self

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

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

class ModifiedTimeWeightedLinearRegression(method, fit_intercept=True, positive=False, half_life=252, error_offset=0.01, bootstrap_method='panel', bootstrap_iters=1000, resample_ratio=1, analytic_method=None)[source]#

Bases: BaseModifiedRegressor

adjust_analytical_se(model, X, y, analytic_method)[source]#

Adjust the coefficients of the TWLS linear regression model by an analytical standard error formula.

Parameters:
  • model (TimeWeightedLinearRegression) – The underlying TWLS linear regression model to be modified.

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

  • y (pd.DataFrame or pd.Series) – Target vector associated with each sample in X.

  • analytic_method (str, default = None) – The analytic method used to calculate standard errors.

Returns:

  • intercept (float) – Adjusted intercept.

  • coef (np.ndarray) – Adjusted coefficients.

Notes

The analytical parameter estimates for WLS are:

\[\hat{\beta}^{\text{WLS}} = (X^{\intercal}WX)^{-1}X^{\intercal}y\]
where:
  • X is the input feature matrix, possibly with a column of ones representing the choice of an intercept.

  • W is the positive-definite, symmetric weight matrix, a diagonal matrix with sample weights along the main diagonal.

  • y is the dependent variable vector.

Since W is a positive-definite, symmetric matrix, it has a square root equal to the diagonal matrix with square roots of the sample weights along the diagonal. Hence, the WLS estimator can be rewritten as:

\[\hat{\beta}^{\text{WLS}} = (({W^{1/2}X})^{\intercal}(W^{1/2}X))^{-1}(W^{1/2}X)^{\intercal}(W^{1/2}y))\]

This is precisely the OLS estimator for a rescaled matrix

\[\tilde {X} = W^{1/2}X\]

and a rescaled dependent variable

\[\tilde {y} = W^{1/2}y\]

Hence, the usual standard error estimate and White’s estimator can be applied based on a rescaling of the design matrix and associated target vector.

set_params(**params)[source]#

Setter method to update the parameters of the ModifiedTimeWeightedLinearRegression.

Parameters:

**params (dict) – Dictionary of parameters to update.

Returns:

The ModifiedTimeWeightedLinearRegression instance with updated parameters.

Return type:

self

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

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

Submodules#