-
Notifications
You must be signed in to change notification settings - Fork 22
Fitted Values and Forecasts
This page documents methods for extracting fitted values and generating forecasts from smooth models.
Generates point forecasts and optionally prediction intervals for h steps ahead.
In R, the standard method is forecast(), although predict() is also available, but with a limited functionality and focusing on the in-sample prediction.
In Python, use predict() method.
model <- adam(AirPassengers, "MMM", lags=12)
# Out-of-sample prediction
pred <- forecast(model, h=12, interval="prediction")
# In-sample confidence intervals
pred <- predict(model, interval="confidence")from smooth import ADAM
# Fit model
model = ADAM(model="ZZZ", lags=12)
model.fit(y)
# Basic point forecast (no intervals by default, matching R)
fc = model.predict(h=12)
fc.mean # pd.Series of point forecasts
fc.lower # None (no intervals requested)
# With prediction intervals (auto-selects method)
fc = model.predict(h=12, interval="prediction", level=0.95)
fc.mean # pd.Series of point forecasts
fc.lower # pd.DataFrame, columns=[0.025]
fc.upper # pd.DataFrame, columns=[0.975]
# Approximate (parametric) intervals
fc = model.predict(h=12, interval="approximate", level=0.95)
# Simulation-based intervals
fc = model.predict(
h=12, interval="simulated",
level=0.95, nsim=1000
)
# Multiple confidence levels at once
fc = model.predict(h=12, interval="prediction", level=[0.8, 0.95, 0.99])
fc.lower # pd.DataFrame, columns=[0.1, 0.025, 0.005]
fc.upper # pd.DataFrame, columns=[0.9, 0.975, 0.995]
# One-sided intervals
fc = model.predict(h=12, interval="prediction", level=0.95, side="upper")
fc.lower # None
fc.upper # pd.DataFrame, columns=[0.975]
fc = model.predict(h=12, interval="prediction", level=0.95, side="lower")
fc.lower # pd.DataFrame, columns=[0.025]
fc.upper # None
# Convert to flat DataFrame (backward compatibility)
df = fc.to_dataframe() # columns: "mean", "lower_0.025", "upper_0.975", ...| Parameter | Type (R) | Type (Python) | Default (R / Python) | Description |
|---|---|---|---|---|
object |
adam | ADAM | - | Fitted model |
h |
integer | int | 10 / required | Forecast horizon |
newdata / X
|
matrix/data.frame | NDArray | NULL / None | Exogenous variables for forecast period |
occurrence |
numeric vector | NDArray | NULL / None | Future occurrence probabilities (values in [0,1]) if known |
interval |
character | str | "none" / "none" | Interval type (see table below) |
level |
numeric | float or list | 0.95 / 0.95 | Confidence level(s); see Level parameter below |
side |
character | str | "both" / "both" | Interval side: "both", "upper", or "lower"; see Side parameter below |
cumulative |
logical | bool | FALSE / False | Produce cumulative forecasts (useful for inventory control) |
nsim |
integer | int | NULL / 10000 | Number of simulations for simulation-based intervals |
scenarios |
logical | bool | FALSE / False | Return simulated scenarios (only for interval="simulated") |
... |
- | - | - | Other parameters passed to underlying functions |
| Type | Description | Best For | R | Python |
|---|---|---|---|---|
"none" |
No intervals | Point forecasts only | Yes | Yes |
"prediction" |
Analytical for additive, simulated for others | General use (recommended) | Yes | Yes |
"approximate" |
Analytical formulae for conditional variance | Fast, additive models | Yes | Yes |
"simulated" |
Monte Carlo simulation | Multiplicative models | Yes | Yes |
"semiparametric" |
Based on multi-step forecast errors and assumed distribution | When residuals are not i.i.d. | Yes | TBA |
"nonparametric" |
Quantile regression (Taylor & Bunn, 1999) | Distribution-free | Yes | TBA |
"empirical" |
Empirical quantiles of multi-step forecast errors | Distribution and model free | Yes | TBA |
"confidence" |
Confidence intervals for point forecast via reforecast()
|
Uncertainty in the forecast line | Yes | TBA |
"complete" |
Accounts for parameter uncertainty via reforecast()
|
Full uncertainty quantification | Yes | TBA |
Note: "semiparametric", "nonparametric" and "empirical" use the
rmultistep()method to extract multistep in-sample forecast errors. See more in Residuals-and-Errors.
The level parameter specifies the confidence level(s) for prediction intervals. It can be a single value or (in both R and Python) a vector/list of values for producing multiple interval bands simultaneously.
Values above 1 are treated as percentages and automatically divided by 100 (e.g. level=95 becomes level=0.95).
Single level (scalar):
| Language | Code | Output |
|---|---|---|
| R | forecast(model, h=12, level=0.95) |
$lower and $upper (single-column matrices) |
| Python | model.predict(h=12, interval="prediction", level=0.95) |
fc.lower DataFrame with column 0.025, fc.upper with column 0.975
|
Multiple levels (vector/list):
| Language | Code | Output |
|---|---|---|
| R | forecast(model, h=12, level=c(0.8, 0.95, 0.99)) |
$lower and $upper (3-column matrices) |
| Python | model.predict(h=12, interval="prediction", level=[0.8, 0.95, 0.99]) |
fc.lower DataFrame with columns [0.1, 0.025, 0.005], fc.upper with columns [0.9, 0.975, 0.995]
|
In Python, lower and upper are separate DataFrames whose column names are the quantile values (floats). For side="both" and level=X, the lower column is (1-X)/2 and the upper column is (1+X)/2.
The side parameter controls which bounds of the prediction interval are returned.
| Value | Description | Python output (level=0.9) |
|---|---|---|
"both" |
Both lower and upper bounds (default) |
fc.lower columns=[0.05], fc.upper columns=[0.95]
|
"upper" |
Upper bound only |
fc.lower is None, fc.upper columns=[0.9]
|
"lower" |
Lower bound only |
fc.lower columns=[0.1], fc.upper is None
|
When side="upper", the upper quantile equals the level directly (e.g. 90th percentile for level=0.9). When side="lower", the lower quantile equals 1 - level (e.g. 10th percentile for level=0.9). Both side options work with single or multiple levels.
R: Returns an object of class "adam.forecast" / "smooth.forecast".
Python: predict() returns a ForecastResult object with structured access to forecasts and intervals. The result also supports DataFrame-style access (result["mean"], result.shape, result.columns) for backward compatibility.
| Attribute | Type (R) | Type (Python) | Description |
|---|---|---|---|
mean |
numeric vector | pd.Series |
Point forecasts (conditional mean) |
lower |
matrix (h × n_levels) |
pd.DataFrame or None
|
Lower prediction bounds; columns are quantile values. None when interval="none" or side="upper"
|
upper |
matrix (h × n_levels) |
pd.DataFrame or None
|
Upper prediction bounds; columns are quantile values. None when interval="none" or side="lower"
|
level |
numeric |
float or list
|
Confidence level(s) used |
side |
character | str |
Which side of intervals was requested |
interval |
logical | str |
Resolved interval type ("none", "approximate", "simulated") |
model |
adam object | - | The estimated model object (R only) |
scenarios |
matrix (h × nsim) | stored in model._general["_scenarios_matrix"]
|
Simulated scenarios |
Accessing interval columns (with multiple levels):
| Language | By name | By position |
|---|---|---|
| R | fc$upper[, "Upper bound (95%)"] |
fc$upper[, 1:2] |
| Python | fc.upper[0.95] |
fc.upper.iloc[:, 0:1] |
fc = model.predict(h=12, interval="prediction", level=[0.8, 0.95, 0.99])
# By quantile name (float)
fc.upper[0.975] # 97.5th percentile (from level=0.95)
fc.lower[0.025] # 2.5th percentile (from level=0.95)
# By position (like R's [,1:2])
fc.upper.iloc[:, 0] # first upper column
fc.upper.iloc[:, 0:2] # first two upper columns
fc.lower.iloc[:, -1] # last lower column
# List available quantiles
fc.upper.columns # Float64Index([0.9, 0.975, 0.995])Notes:
- In R, access elements via
$(e.g.,fc$mean,fc$lower) - In Python, access via attributes (e.g.,
fc.mean,fc.lower,fc.upper) or DataFrame-style (fc["mean"]) - Use
fc.to_dataframe()to convert to a flatpd.DataFramewith prefixed column names ("mean","lower_0.025","upper_0.975", ...) - In both R and Python,
scenariosis only populated wheninterval="simulated"andscenarios=TRUE/True
Extracts fitted (in-sample predicted) values from the model.
model <- adam(AirPassengers, "MMM", lags=12)
# Get fitted values
fitted(model)from smooth import ADAM
model = ADAM(model="MMM", lags=12)
model.fit(y)
# Get fitted values
fitted_values = model.fittedR: Returns a time series with fitted values for each in-sample observation.
Python: Returns an NDArray with fitted values for each in-sample observation.
Extracts the actual (observed) values used in model estimation.
model <- adam(AirPassengers, "MMM", lags=12, h=12, holdout=TRUE)
# Get actuals
y <- actuals(model)from smooth import ADAM
model = ADAM(model="MMM", lags=12)
model.fit(y)
# Get actuals (the data used for fitting)
actuals = model.actualsR: Returns a time series with the actual in-sample observations.
Python: Returns an NDArray with the actual in-sample observations.
- ADAM - Main ADAM function
- Coefficients-and-Parameters - Extracting model parameters
- Simulation-Functions - simulate() and sim.* functions
- Refitting-and-Reforecasting - Parameter uncertainty analysis
- Visualisation-and-Output - Plotting forecasts