preprocessing.checking.check_residuals_input

preprocessing.checking.check_residuals_input(
    forecaster_name,
    use_in_sample_residuals,
    in_sample_residuals_,
    out_sample_residuals_,
    use_binned_residuals,
    in_sample_residuals_by_bin_,
    out_sample_residuals_by_bin_,
    levels=None,
    encoding=None,
)

Check residuals input arguments in Forecasters.

Parameters

Name Type Description Default
forecaster_name str Forecaster name. required
use_in_sample_residuals bool Indicates if in-sample or out-of-sample residuals are used. required
in_sample_residuals_ np.ndarray | dict[str, np.ndarray] | None Residuals of the model when predicting training data. required
out_sample_residuals_ np.ndarray | dict[str, np.ndarray] | None Residuals of the model when predicting non-training data. required
use_binned_residuals bool Indicates if residuals are binned. required
in_sample_residuals_by_bin_ dict[str | int, np.ndarray | dict[int, np.ndarray]] | None In-sample residuals binned according to the predicted value each residual is associated with. required
out_sample_residuals_by_bin_ dict[str | int, np.ndarray | dict[int, np.ndarray]] | None Out-of-sample residuals binned according to the predicted value each residual is associated with. required
levels list[str] | None Names of the series (levels) to be predicted (multiseries forecasters). Defaults to None. None
encoding str | None Encoding used to identify the different series (ForecasterRecursiveMultiSeries). Defaults to None. None

Returns

Name Type Description
None None

Raises

Name Type Description
ValueError If the requested residuals store is None or empty.

Examples

import numpy as np

from spotforecast2_safe.preprocessing.checking import check_residuals_input

residuals = np.array([0.1, -0.2, 0.3, -0.1, 0.2])

# Success path: in-sample residuals present
check_residuals_input(
    forecaster_name="ForecasterRecursive",
    use_in_sample_residuals=True,
    in_sample_residuals_=residuals,
    out_sample_residuals_=None,
    use_binned_residuals=False,
    in_sample_residuals_by_bin_=None,
    out_sample_residuals_by_bin_=None,
)
print("Success: residuals accepted.")

# Failure path: in-sample residuals are None
try:
    check_residuals_input(
        forecaster_name="ForecasterRecursive",
        use_in_sample_residuals=True,
        in_sample_residuals_=None,
        out_sample_residuals_=None,
        use_binned_residuals=False,
        in_sample_residuals_by_bin_=None,
        out_sample_residuals_by_bin_=None,
    )
except ValueError as e:
    print(f"ValueError (no residuals): {type(e).__name__}")

# Failure path: out-of-sample residuals not set
try:
    check_residuals_input(
        forecaster_name="ForecasterRecursive",
        use_in_sample_residuals=False,
        in_sample_residuals_=residuals,
        out_sample_residuals_=None,
        use_binned_residuals=False,
        in_sample_residuals_by_bin_=None,
        out_sample_residuals_by_bin_=None,
    )
except ValueError as e:
    print(f"ValueError (out-sample missing): {type(e).__name__}")
Success: residuals accepted.
ValueError (no residuals): ValueError
ValueError (out-sample missing): ValueError