Prediction and forecasting
A native prediction evaluates a specified model at the times you provide.
A forecast additionally interprets predictions beyond an observed information
window. This tutorial checks the first task explicitly, then explains what is
needed before making the second claim. The current API uses an explicit time
table rather than the earlier predict_model(..., horizon=...) interface.
Learning outcomes
Section titled “Learning outcomes”You will verify a Logistic prediction against its closed form, retain row identifiers, understand eager and lazy input behavior, and explain why a conditional curve does not provide a calibrated forecast interval. You will also confirm that duplicate times fail the documented input contract.
Prerequisites
Section titled “Prerequisites”Use the development installation and an interpreter containing the built native package. The fixture uses Python 3.15.2, Rust 1.99.1 and three synthetic rows. It needs no downloaded data or network service. Read core concepts if levels, rates and interval counts are unfamiliar.
The parameters are L = 100, k = 1 and x0 = 1. If time is in years, k
has units of inverse years, x0 is one year, and L is measured in the chosen
adoption units. The same values must not be reused with a month-based time
coordinate without the corresponding parameter conversion.
Run the maintained source from the repository root:
.venv-native/bin/python -I examples/native_forecast.py"""Check native Logistic prediction against an independent analytic reference.
Synthetic values have arbitrary adoption units; no empirical fit or calibratedforecast uncertainty is implied. Run with the installed development package."""
import jsonimport math
import polars as pl
from innovate import predict
def main() -> None: """Validate predictions, preserved identity, LazyFrames and invalid grids.""" times = [0.0, 1.0, 2.0] parameters = {"L": 100.0, "k": 1.0, "x0": 1.0} frame = pl.DataFrame({"time": times, "id": ["a", "b", "c"]}) forecast = predict("logistic", frame, parameters)
# This independent closed form is a test oracle, not a production fallback. expected = [100.0 / (1.0 + math.exp(-(time - 1.0))) for time in times] actual = forecast["prediction"].to_list() assert all( math.isclose(value, reference, rel_tol=1e-12, abs_tol=1e-12) for value, reference in zip(actual, expected, strict=True) ) assert forecast["id"].to_list() == ["a", "b", "c"] assert forecast["time"].to_list() == times assert frame.columns == ["time", "id"] assert predict("logistic", frame.lazy(), parameters).equals(forecast)
try: predict("logistic", pl.DataFrame({"time": [0.0, 0.0]}), parameters) except ValueError: duplicate_time_rejected = True else: duplicate_time_rejected = False assert duplicate_time_rejected, "The native contract must reject duplicate times."
print( json.dumps( { "duplicate_time_rejected": duplicate_time_rejected, "ids": forecast["id"].to_list(), "predictions": [round(value, 6) for value in actual], }, sort_keys=True, ) )
if __name__ == "__main__": main()The script first calculates the expected curve independently in Python and compares each result with the native output. It then checks identifiers, time order and unchanged input columns. Finally it compares eager and lazy input and requires a duplicate-time request to raise an error. The Python closed form is the test oracle; production scientific execution remains in Rust.
Expected results
Section titled “Expected results”Successful assertions produce exactly this contract output:
{"duplicate_time_rejected": true, "ids": ["a", "b", "c"], "predictions": [26.894142, 50.0, 73.105858]}There are three returned predictions, in the order of a, b and c. A
nonzero exit or an unexpected value is a discrepancy to investigate. An import
failure for innovate._native means that this interpreter does not have the
required native package; return to installation before interpreting the result.
Interpretation
Section titled “Interpretation”The checked equation is L / (1 + exp(-k * (t - x0))). At the midpoint
t = x0, the exponential equals one, so the prediction is L / 2 = 50.
The other two outputs are approximately 26.894142 and 73.105858. These are levels
at specific times. They are not counts of new adopters in the previous interval.
For supported models, predict also accepts
quantity="rate"; that requests a native derivative and can produce signed rates
for declining series. The three-row fixture here tests levels only. The
Norton–Bass tutorial separately checks held-out
levels and signed derivatives after fitting.
Reader task: if the same time coordinate is changed from years to months,
what parameter changes preserve the curve? Use t_months = 12 * t_years,
x0_months = 12 * x0_years and k_per_month = k_per_year / 12; L keeps its
adoption unit. Substitution into the equation leaves the exponent unchanged.
This is a dimensional check, not evidence about a real population.
Limitations
Section titled “Limitations”The example supplies parameters and does not fit observations. It contains no observed training window, forecast-error assessment, interval calibration, causal identification or empirical validation. To make a forecast, specify the information available at the forecasting date, the future time grid and the assumptions that continue beyond the observed window. Evaluate appropriate held-out outcomes and uncertainty separately.
A LazyFrame is collected at execution, and the current Arrow IPC boundary
copies buffers. Keep a result’s model state when forecasting after estimation;
see fitting and
FitResult.predict.