macrosynergy.learning.forecasting.meta_estimators.country_by_country_regressions#

class CountryByCountryRegression(estimator, min_xs_samples=32)[source]#

Bases: BaseEstimator, MetaEstimatorMixin, RegressorMixin

MetaEstimator to fit a scikit-learn-compatible regressor on each country’s data slice in a panel. If a country has fewer samples than min_xs_samples, a global model is used for the sake of prediction.

Parameters:
  • estimator (object) – A scikit-learn compatible regressor that will be cloned for each country.

  • min_xs_samples (int, default=32) – Minimum number of samples required for fitting a country-specific model. If a country has fewer samples, the global model will be used for predictions.

Notes

Country by country regressions model a panel through a “bottoms-up” approach, treating each country as a separate regression problem. This is useful when a panel is particularly heterogeneous or each time series in the panel is long. Short time series results in a low-bias, high-variance model that tends to underperform a global forecasting model. Regularization on each country-specific model can help improve performance.

fit(X, y)[source]#
predict(X)[source]#

Predict the target values for the given input data.

Parameters:

X (pd.DataFrame) – Input features for prediction.

Returns:

Predicted target values.

Return type:

np.ndarray

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

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