sktime.forecasting.base

class sktime.forecasting.base.BaseForecaster[source]

Bases: sktime.base._base.BaseEstimator

Base forecaster

The base forecaster specifies the methods and method signatures that all forecasters have to implement.

Specific implementations of these methods is deferred to concrete forecasters.

compute_pred_int(y_pred, alpha=0.05)[source]

Get the prediction intervals for a forecast.

If alpha is iterable, multiple intervals will be calculated.

Parameters
  • y_pred (pd.Series) – Point predictions.

  • alpha (float or list, optional (default=0.95)) – A significance level or list of significance levels.

Returns

intervals – A table of upper and lower bounds for each point prediction in y_pred. If alpha was iterable, then intervals will be a list of such tables.

Return type

pd.DataFrame

fit(y, X=None, fh=None)[source]

Fit to training data.

Parameters
  • y (pd.Series) – Target time series to which to fit the forecaster.

  • fh (int, list or np.array, optional (default=None)) – The forecasters horizon with the steps ahead to to predict.

  • X (pd.DataFrame, optional (default=None)) – Exogenous variables are ignored

Returns

self

Return type

returns an instance of self.

get_fitted_params()[source]

Get fitted parameters

Returns

fitted_params

Return type

dict

predict(fh=None, X=None, return_pred_int=False, alpha=0.05)[source]

Make forecasts

Parameters
  • fh (int, list or np.array) –

  • X (pd.DataFrame, optional (default=None)) –

  • return_pred_int (bool, optional (default=False)) –

  • alpha (float or list, optional (default=0.95)) – A significance level or list of significance levels.

Returns

  • y_pred (pd.Series) – Point predictions

  • y_pred_int (pd.DataFrame) – Prediction intervals

score(y, X=None, fh=None)[source]

Compute the sMAPE loss for the given forecasting horizon.

Parameters
  • y (pd.Series) – Target time series to which to compare the forecasts.

  • fh (int, list or array-like, optional (default=None)) – The forecasters horizon with the steps ahead to to predict.

  • X (pd.DataFrame, shape=[n_obs, n_vars], optional (default=None)) – An optional 2-d dataframe of exogenous variables.

Returns

score – sMAPE loss of self.predict(fh, X) with respect to y_test.

Return type

float

update(y, X=None, update_params=True)[source]

Update fitted parameters

Parameters
  • y (pd.Series) –

  • X (pd.DataFrame) –

  • update_params (bool, optional (default=True)) –

Returns

self

Return type

an instance of self

update_predict(y, cv=None, X=None, update_params=True, return_pred_int=False, alpha=0.05)[source]

Make and update predictions iteratively over the test set.

Parameters
  • y (pd.Series) –

  • cv (cross-validation generator, optional (default=None)) –

  • X (pd.DataFrame, optional (default=None)) –

  • update_params (bool, optional (default=True)) –

  • return_pred_int (bool, optional (default=False)) –

  • alpha (int or list of ints, optional (default=None)) –

Returns

  • y_pred (pd.Series) – Point predictions

  • y_pred_int (pd.DataFrame) – Prediction intervals

update_predict_single(y_new, fh=None, X=None, update_params=True, return_pred_int=False, alpha=0.05)[source]
class sktime.forecasting.base.ForecastingHorizon(values=None, is_relative=True)[source]

Bases: object

Forecasting horizon

Parameters
  • values (pd.Index, np.array, list or int) – Values of forecasting horizon

  • is_relative (bool, optional (default=True)) –

    • If True, values are relative to end of training series.

    • If False, values are absolute.

is_all_in_sample(cutoff=None)[source]

Whether or not the forecasting horizon is purely in-sample for given cutoff.

Parameters

cutoff (pd.Period, pd.Timestamp, int, optional (default=None)) – Cutoff value is required to convert a relative forecasting horizon to an absolute one and vice versa.

Returns

ret – True if the forecasting horizon is purely in-sample for given cutoff.

Return type

bool

is_all_out_of_sample(cutoff=None)[source]

Whether or not the forecasting horizon is purely out-of-sample for given cutoff.

Parameters

cutoff (pd.Period, pd.Timestamp, int, optional (default=None)) – Cutoff value is required to convert a relative forecasting horizon to an absolute one and vice versa.

Returns

ret – True if the forecasting horizon is purely out-of-sample for given cutoff.

Return type

bool

property is_relative[source]

Whether forecasting horizon is relative to the end of the training series.

Returns

is_relative

Return type

bool

to_absolute(cutoff)[source]

Return absolute values :param cutoff: Cutoff value is required to convert a relative forecasting

horizon to an absolute one and vice versa.

Returns

fh – Absolute representation of forecasting horizon

Return type

ForecastingHorizon

to_absolute_int(start, cutoff=None)[source]

Return absolute values as zero-based integer index starting from start.

Parameters
  • start (pd.Period, pd.Timestamp, int) – Start value returned as zero.

  • cutoff (pd.Period, pd.Timestamp, int, optional (default=None)) – Cutoff value is required to convert a relative forecasting horizon to an absolute one and vice versa.

Returns

fh – Absolute representation of forecasting horizon as zero-based integer index

Return type

ForecastingHorizon

to_in_sample(cutoff=None)[source]

Return in-sample values

Parameters

cutoff (pd.Period, pd.Timestamp, int, optional (default=None)) – Cutoff value is required to convert a relative forecasting horizon to an absolute one and vice versa.

Returns

fh – In-sample values of forecasting horizon

Return type

ForecastingHorizon

to_indexer(cutoff=None, from_cutoff=True)[source]

Return zero-based indexer values for easy indexing into arrays.

Parameters
  • cutoff (pd.Period, pd.Timestamp, int, optional (default=None)) – Cutoff value is required to convert a relative forecasting horizon to an absolute one and vice versa.

  • from_cutoff (bool, optional (default=True)) –

    • If True, zero-based relative to cutoff.

    • If False, zero-based relative to first value in forecasting

    horizon.

Returns

fh – Indexer

Return type

pd.Index

to_numpy(**kwargs)[source]

Returns underlying values as np.array

Parameters

**kwargs (dict of kwargs) – kwargs passed to to_numpy() of wrapped pandas index.

Returns

fh

Return type

np.ndarray

to_out_of_sample(cutoff=None)[source]

Return out-of-sample values :param cutoff: Cutoff value is required to convert a relative forecasting

horizon to an absolute one and vice versa.

Returns

fh – Out-of-sample values of forecasting horizon

Return type

ForecastingHorizon

to_pandas()[source]

Returns underlying values as pd.Index

Returns

fh

Return type

pd.Index

to_relative(cutoff=None)[source]

Return relative values :param cutoff: Cutoff value is required to convert a relative forecasting

horizon to an absolute one and vice versa.

Returns

fh – Relative representation of forecasting horizon

Return type

ForecastingHorizon