Skip to content

innovate.fit

All current Python definitions

View source · Source file SHA-256: 522871fe0b61b840b5f85b8f278beb2b79c7afd68645265ae3a68983d56d74e4

def fit(
model: str,
data: pl.DataFrame | pl.LazyFrame,
*,
model_options: dict[str, Any] | None = None,
observed_columns: list[str] | None = None,
fit_options: dict[str, Any] | None = None,
) -> FitResult: ...

Estimate native model parameters from an ordered observation table.

A LazyFrame is collected when fitting begins. The frame is serialized to Arrow IPC, so this interface copies buffers. Numeric time, observations and parameters must use consistent caller-specified units. Inspect diagnostics and model assumptions before interpreting a returned fit. Observations must represent the selected model’s fitted quantity; this wrapper does not integrate interval counts or difference cumulative totals to make them fit a different observation contract.

  • model: Native model key supported for fitting.
  • data: Polars frame with a nonempty, finite, strictly increasing numeric time column, finite numeric observation columns without nulls, and any covariates declared in model_options.
  • model_options: Native constructor options; None becomes an empty mapping. These options are retained in the returned fitted state.
  • observed_columns: Distinct observation column names in model output order. None uses ["observed"]; an empty list is invalid. One column becomes a vector and multiple columns become time-by-series rows.
  • fit_options: Native fitting controls for the chosen model, such as supported initial parameters or iteration limits. None supplies an empty mapping and uses the kernel’s model-specific defaults.

FitResult containing the complete native fit envelope, parameter estimates, diagnostics and state for later prediction. A fit does not by itself certify calibrated uncertainty or adequate model specification.

  • NativeError: If scientific fitting fails or a feature is unsupported.
  • ValueError: If tabular inputs, options or finite JSON values are invalid.
  • TypeError: If data is not a supported frame or options cannot be serialized.
  • polars.exceptions.PolarsError: If collection or IPC serialization fails.
import math
import innovate
import polars as pl
time = [float(t) for t in range(20)]
observed = [100.0 / (1.0 + math.exp(-0.6 * (t - 8))) for t in time]
fitted = innovate.fit("logistic", pl.DataFrame({"time": time, "observed": observed}))
predictions = fitted.predict(pl.DataFrame({"time": time}))
assert max(abs(a - b) for a, b in zip(predictions["prediction"], observed)) < 0.01