Skip to content

curvefit.core.residual_model.SmoothResidualModel

A local smoother for the coefficient of variation in forecasts

This is a residual model (see _ResidualModel for a description). This particular residual model creates a smoothed standard deviation over the residual data. It calculates the standard deviation of the residuals with a moving window over neighboring covariate values.

The specific covariates for this residual model are num_data and far_out: how much data did the prediction model have and how far out into the future was it predicting. To extrapolate to unobserved values of the covariates in order to predict the residuals for those observations, it prioritizes num_data and then far_out in a simple "carry forward" extrapolation.

Syntax

d = SmoothResidualModel(
    cv_bounds, covariates, exclude_groups,
    num_smooth_iterations, smooth_radius, robust
)

Arguments

  • cv_bounds (List[float]): a 2-element list of bounds on the coefficient of variation. The first element is the lower bound and the second is the upper bound
  • covariates (Dict[str: None, str]): a dictionary of covariates to use in the model. The keys of the dictionary are the names of covariates to include in the residual model fitting and the optional values for each key are the subsets of the covariates to use (e.g. only use the subset of data where covariate1 > 10. in the fitting). NOTE: this residual model requires that only two covariates, "far_out" and "num_data" are used.
  • exclude_groups (optional, List[str]): a list of groups to exclude from the fitting process (not excluded from making predictions)
  • num_smooth_iterations (int): how many times should the model smooth over the residual matrix. If 1, then only calculates the standard deviation over a moving window. If > 1, then runs a local smoother over the standard deviation surface num_smooth_iterations - 1 times.
  • smooth_radius (List[int]): the size of the moving window in each of the covariate directions. Since for this residual model only two covariates are used, this needs to be a 2-element list of integers specifying how many units of each covariate to consider for the neighborhood. For example, if covariates is a dictionary with ['far_out', 'num_data'] as the keys, and smooth_radius=[2, 2], then the standard deviation for the residual with far_out == 4 and num_data == 3 will be calculated over the window 2 < far_out < 6 and 1 < num_data < 5.
  • robust (bool): whether or not to use a robust estimator for the standard deviation (1.4826 * median absolute deviation).

Attributes

  • self.smoothed_residual_data (np.array): a smooth surface of residual standard deviations across the covariate axes, only populated after fit_residuals() is called
  • self.covariate_names (List[str]): list of covariate names (keys of self.covariates)

Methods

See _ResidualModel for descriptions of the class methods for a _ResidualModel.

Usage

SmoothResidualModel(
    cv_bounds=[0., np.inf],
    covariates={'far_out': 'far_out >= 10', 'num_data': None},
    exclude_groups=None,
    num_smooth_iterations=1,
    smooth_radius=[1, 1],
    robust=True
)