Back to models
Forecaster

CurveFitForecaster

Categorical in XInsamplePred int insample

The CurveFitForecaster takes a function and fits it by using scipy curve_fit.

The CurveFitForecaster uses the scipy curve_fit method to determine the optimal parameters for a given function.

If the index is an integer index, it directly uses the index values. If the index is a pd.DatetimeIndex or a pd.PeriodIndex, the index values are transformed into floats using two distinct approaches:

  1. For a pd.DatetimeIndex, it calculates the number of days since 1970-01-01. For a pd.PeriodIndex, it computes the number of (full) periods since

    1970-01-01.

  2. For a pd.DatetimeIndex, it calculates the number of days since the first index value. For a pd.PeriodIndex, it calculates or the number of (dull) periods since the first index value.

Furthermore, the difference between the index values can be normalised by setting the difference between the first and the second index value to one.

In fit 1. The index of the input time series is transformed to a list of floats. 2. The scipy curve_fit is called using the list of floats as x values,

and the time series values as y values.

In predict 1. The ForecastingHorizon is transformed to a list of floats. 2. The list of floats is passed together with the fitted parameters to the

function to provide the forecast.

Quickstart

python
from sktime.forecasting.trend import CurveFitForecaster

estimator = CurveFitForecaster(function, curve_fit_params=None, origin='unix_zero', normalise_index=False)

Parameters(4)

function: Callable[[Iterable[float], …], Iterable[float]]

The function that should be fitted and used to make forecasts. The signature of the functions is function(x, ...). It takes the independent variables as first argument and the parameters to fit as separate remaining arguments. See scipy.optimize.curve_fit for more information.

curve_fit_params: dict, default=None
Additional parameters that should be passed to the curve_fit method. See scipy.optimize.curve_fit for more information.
origin: {“unix_zero”, “first_index”}, default=”unix_zero”
The origin of the time series index.
normalise_index: bool, default=False
If True, the differences between the index values are normalised by setting the difference between the first and second index value to one.

Examples

>>> from sktime.forecasting.trend import CurveFitForecaster
>>> from sktime.datasets import load_airline
>>> y = load_airline ()
>>> def linear_function (x, a, b):
... return a * x + b
>>> forecaster = CurveFitForecaster (function = linear_function,
... curve_fit_params = { "p0":[- 1, 1 ]})
>>> forecaster. fit (y) CurveFitForecaster(
... )
>>> y_pred = forecaster. predict (fh = [1, 2, 3 ])