Skip to content

SplineTrendForecaster

SplineTrendForecaster

class SplineTrendForecaster(regressor=None, n_knots=5, degree=1, knots='uniform', extrapolation='constant', with_intercept=True)[source]

Forecast time series data with a spline trend.

Uses an sklearn regressor specified by the regressor parameter to perform regression on time series values against their corresponding indices, after transformation of the indices with SplineTransformer.

Parameters:
regressorsklearn regressor estimator object, default=None

Define the regression model type. If not set, defaults to sklearn.linear_model.LinearRegression.

n_knotsint, default=5

Number of knots of the splines if knots is one of {‘uniform’, ‘quantile’}. Must be at least 2. Ignored if knots is array-like.

degreeint, default=1

Degree of the splines (1 for linear, 2 for quadratic, etc.).

n_knotsint, default=4

Number of knots for the spline transformation.

knots{‘uniform’, ‘quantile’}or array-like of shape (n_knots, n_features),

default=’uniform’ Determines knot positions such that first knot <= features <= last knot.

  • ‘uniform’: n_knots are distributed uniformly between the

min and max values of the features. - ‘quantile’: n_knots are distributed uniformly along the quantiles of the features. - array-like: Specifies sorted knot positions, including the boundary knots. Internally, additional knots are added before the first knot and after the last knot based on the spline degree.

extrapolation{‘error’, ‘constant’, ‘linear’, ‘continue’, ‘periodic’},

default=’constant’ Determines how to handle values outside the min and max values of the training features:

  • ‘error’: Raises a ValueError.

  • ‘constant’: Uses the spline value at the minimum or maximum feature as

constant extrapolation. - ‘linear’: Applies linear extrapolation. - ‘continue’: Extrapolates as is (equivalent to extrapolate=True in scipy.interpolate.BSpline). - ‘periodic’: Uses periodic splines with a periodicity equal to the distance between the first and last knot, enforcing equal function values and derivatives at these knots.

with_interceptbool, default=True

If True, includes a feature in which all polynomial powers are zero (i.e., a column of ones, acting as an intercept term in a linear model).

Attributes:
cutoff

Cut-off = “present time” state of forecaster.

fh

Forecasting horizon that was passed.

is_fitted

Whether fit has been called.

state

State of the estimator.

Examples

>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.trend import SplineTrendForecaster
>>> y = load_airline()
>>> forecaster = SplineTrendForecaster(
...     n_knots=5,
...     degree=2,
...     knots="uniform",
...     extrapolation="constant"
... )
>>> forecaster.fit(y)
SplineTrendForecaster(...)
>>> y_pred = forecaster.predict(fh=[1, 2, 3])

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(y[, X, fh])

Fit forecaster to training data.

fit_predict(y[, X, fh, X_pred])

Fit and forecast time series at future horizon.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_pretrained_params([deep])

Get pretrained parameters of this estimator.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

predict([fh, X])

Forecast time series at future horizon.

predict_interval([fh, X, coverage])

Compute/return prediction interval forecasts.

predict_proba([fh, X, marginal])

Compute/return fully probabilistic forecasts.

predict_quantiles([fh, X, alpha])

Compute/return quantile forecasts.

predict_residuals([y, X])

Return residuals of time series forecasts.

predict_var([fh, X, cov])

Compute/return variance forecasts.

pretrain(y[, X, fh])

Pre-train forecaster on panel (global) data.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

score(y[, X, fh])

Scores forecast against ground truth, using MAPE (non-symmetric).

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

update(y[, X, update_params])

Update cutoff value and, optionally, fitted parameters.

update_predict(y[, cv, X, update_params, ...])

Make predictions and update model iteratively over the test set.

update_predict_single([y, fh, X, update_params])

Update model with new data and make forecasts.