preprocessing.checking.check_predict_input(
forecaster_name,
steps,
is_fitted,
exog_in_,
index_type_,
index_freq_,
window_size,
last_window,
last_window_exog= None ,
exog= None ,
exog_names_in_= None ,
interval= None ,
alpha= None ,
max_step= None ,
levels= None ,
levels_forecaster= None ,
series_names_in_= None ,
encoding= None ,
)
Check all inputs of predict method. This is a helper function to validate that inputs used in predict method match attributes of a forecaster already trained.
Parameters
forecaster_name
str
str Forecaster name.
required
steps
Union [int , List [int ]]
int, list Number of future steps predicted.
required
is_fitted
bool
bool Tag to identify if the estimator has been fitted (trained).
required
exog_in_
bool
bool If the forecaster has been trained using exogenous variable/s.
required
index_type_
type
type Type of index of the input used in training.
required
index_freq_
str
str Frequency of Index of the input used in training.
required
window_size
int
int Size of the window needed to create the predictors. It is equal to max_lag.
required
last_window
Optional [Union [pd .Series , pd .DataFrame ]]
pandas Series, pandas DataFrame, None Values of the series used to create the predictors (lags) need in the first iteration of prediction (t + 1).
required
last_window_exog
Optional [Union [pd .Series , pd .DataFrame ]]
pandas Series, pandas DataFrame, default None Values of the exogenous variables aligned with last_window in ForecasterStats predictions.
None
exog
Optional [Union [pd .Series , pd .DataFrame , Dict [str , Union [pd .Series , pd .DataFrame ]]]]
pandas Series, pandas DataFrame, dict, default None Exogenous variable/s included as predictor/s.
None
exog_names_in_
Optional [List [str ]]
list, default None Names of the exogenous variables used during training.
None
interval
Optional [List [float ]]
list, tuple, default None Confidence of the prediction interval estimated. Sequence of percentiles to compute, which must be between 0 and 100 inclusive. For example, interval of 95% should be as interval = [2.5, 97.5].
None
alpha
Optional [float ]
float, default None The confidence intervals used in ForecasterStats are (1 - alpha) %.
None
max_step
Optional [int ]
int, default None Maximum number of steps allowed (ForecasterDirect and ForecasterDirectMultiVariate).
None
levels
Optional [Union [str , List [str ]]]
str, list, default None Time series to be predicted (ForecasterRecursiveMultiSeries and ForecasterRnn). |None| | levels_forecaster | [Optional](typing.Optional)\[[Union](typing.Union)\[[str](str), [List](typing.List)\[[str](str)\]\]\] | str, list, default None Time series used as output data of a multiseries problem in a RNN problem (ForecasterRnn). |None| | series_names_in_ | [Optional](typing.Optional)\[[List](typing.List)\[[str](str)\]\] | list, default None Names of the columns used during fit (ForecasterRecursiveMultiSeries,ForecasterDirectMultiVariateandForecasterRnn). |None| | encoding | [Optional](typing.Optional)\[[str](str)\] | str, default None Encoding used to identify the different series (ForecasterRecursiveMultiSeries). |None`
Examples
import pandas as pd
import numpy as np
from spotforecast2_safe.preprocessing.checking import check_predict_input
last_window = pd.Series(
[1.0 , 2.0 , 3.0 ],
index= pd.date_range("2020-01-01" , periods= 3 , freq= "h" ),
)
# Success path: fitted forecaster, no exog
check_predict_input(
forecaster_name= "ForecasterRecursive" ,
steps= 2 ,
is_fitted= True ,
exog_in_= False ,
index_type_= pd.DatetimeIndex,
index_freq_= "h" ,
window_size= 3 ,
last_window= last_window,
)
print ("Success: valid predict inputs accepted." )
# Failure path: not fitted
try :
check_predict_input(
forecaster_name= "ForecasterRecursive" ,
steps= 2 ,
is_fitted= False ,
exog_in_= False ,
index_type_= pd.DatetimeIndex,
index_freq_= "h" ,
window_size= 3 ,
last_window= last_window,
)
except RuntimeError as e:
print (f"RuntimeError (not fitted): { type (e). __name__ } " )
# Failure path: steps < 1
try :
check_predict_input(
forecaster_name= "ForecasterRecursive" ,
steps= 0 ,
is_fitted= True ,
exog_in_= False ,
index_type_= pd.DatetimeIndex,
index_freq_= "h" ,
window_size= 3 ,
last_window= last_window,
)
except ValueError as e:
print (f"ValueError (steps=0): { type (e). __name__ } " )
# Failure path: exog required but not provided
try :
check_predict_input(
forecaster_name= "ForecasterRecursive" ,
steps= 2 ,
is_fitted= True ,
exog_in_= True ,
index_type_= pd.DatetimeIndex,
index_freq_= "h" ,
window_size= 3 ,
last_window= last_window,
exog= None ,
)
except ValueError as e:
print (f"ValueError (missing exog): { type (e). __name__ } " )
Success: valid predict inputs accepted.
RuntimeError (not fitted): RuntimeError
ValueError (steps=0): ValueError
ValueError (missing exog): ValueError