|
| 1 | +# API Reference |
| 2 | + |
| 3 | +Complete reference for all public classes and functions. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Models |
| 8 | + |
| 9 | +All models follow the same interface: |
| 10 | + |
| 11 | +```python |
| 12 | +model = ModelClass(**params) # configure |
| 13 | +model.fit(y, m=1, X=None) # fit to data → returns self |
| 14 | +fc = model.forecast(h=10, level=None) # forecast → ForecastResult |
| 15 | +``` |
| 16 | + |
| 17 | +### Properties (after fitting) |
| 18 | + |
| 19 | +| Property | Type | Description | |
| 20 | +|----------|------|-------------| |
| 21 | +| `fitted_values` | `np.ndarray` | In-sample fitted values | |
| 22 | +| `residuals` | `np.ndarray` | In-sample residuals | |
| 23 | +| `summary` | `str` | Model summary string | |
| 24 | +| `coefficients` | `dict` | Model coefficients | |
| 25 | + |
| 26 | +### Methods |
| 27 | + |
| 28 | +| Method | Returns | Description | |
| 29 | +|--------|---------|-------------| |
| 30 | +| `.fit(y, m=1, X=None)` | `self` | Fit model to data | |
| 31 | +| `.forecast(h=10, level=None)` | `ForecastResult` | Generate forecasts | |
| 32 | +| `.predict(h=10, **kw)` | `ForecastResult` | Alias for `.forecast()` | |
| 33 | +| `.get_params()` | `dict` | Return model parameters | |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +### Exponential Smoothing |
| 38 | + |
| 39 | +#### `SES(initial="optimal", alpha=None, lambda_=None, biasadj=False)` |
| 40 | + |
| 41 | +Simple Exponential Smoothing. [User Guide](user-guide/exponential-smoothing.md#ses-simple-exponential-smoothing) |
| 42 | + |
| 43 | +#### `Holt(damped=False, initial="optimal", exponential=False, alpha=None, beta=None, phi=None, lambda_=None, biasadj=False)` |
| 44 | + |
| 45 | +Holt's linear trend method. [User Guide](user-guide/exponential-smoothing.md#holt-linear-trend-method) |
| 46 | + |
| 47 | +#### `HoltWinters(seasonal="additive", damped=False, initial="optimal", exponential=False, alpha=None, beta=None, gamma=None, phi=None, lambda_=None, biasadj=False)` |
| 48 | + |
| 49 | +Holt-Winters triple exponential smoothing. [User Guide](user-guide/exponential-smoothing.md#holtwinters-triple-exponential-smoothing) |
| 50 | + |
| 51 | +#### `ETS(model="ZZZ", damped=None, alpha=None, beta=None, gamma=None, phi=None, additive_only=False, lambda_=None, biasadj=False, opt_crit="lik", ic="aicc", bounds="both", restrict=True, allow_multiplicative_trend=False)` |
| 52 | + |
| 53 | +Error-Trend-Seasonal state space model. [User Guide](user-guide/exponential-smoothing.md#ets-error-trend-seasonal-state-space) |
| 54 | + |
| 55 | +#### `Croston()` |
| 56 | + |
| 57 | +Simple Croston method for intermittent demand. [User Guide](user-guide/exponential-smoothing.md#croston-intermittent-demand-simple) |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### ARIMA |
| 62 | + |
| 63 | +#### `ARIMA(order=(0,0,0), seasonal_order=None, include_mean=True, method="CSS-ML", transform_pars=True, lambda_=None, biasadj=None)` |
| 64 | + |
| 65 | +ARIMA/SARIMA model. [User Guide](user-guide/arima.md#arima-manual-specification) |
| 66 | + |
| 67 | +#### `AutoARIMA(d=None, D=None, max_p=5, max_q=5, max_P=2, max_Q=2, max_order=5, max_d=2, max_D=1, stationary=False, seasonal=True, stepwise=True, trace=False, approximation=True, ic="aicc", test="adf", seasonal_test="ocsb", allowmean=True, allowdrift=True, lambda_=None, biasadj=None)` |
| 68 | + |
| 69 | +Automatic ARIMA selection. [User Guide](user-guide/arima.md#autoarima-automatic-selection) |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### Naive Methods |
| 74 | + |
| 75 | +#### `Naive(lambda_=None, biasadj=False)` |
| 76 | + |
| 77 | +Naive forecast (last value). [User Guide](user-guide/naive.md#naive) |
| 78 | + |
| 79 | +#### `SeasonalNaive(lambda_=None, biasadj=False)` |
| 80 | + |
| 81 | +Seasonal naive forecast. [User Guide](user-guide/naive.md#seasonalnaive) |
| 82 | + |
| 83 | +#### `RandomWalk(drift=False, lambda_=None, biasadj=False)` |
| 84 | + |
| 85 | +Random walk with optional drift. [User Guide](user-guide/naive.md#randomwalk) |
| 86 | + |
| 87 | +#### `MeanForecast(lambda_=None, biasadj=False)` |
| 88 | + |
| 89 | +Mean forecast. [User Guide](user-guide/naive.md#meanforecast) |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +### BATS / TBATS |
| 94 | + |
| 95 | +#### `BATS(use_box_cox=None, use_trend=None, use_damped_trend=None, use_arma_errors=True, bc_lower=0.0, bc_upper=1.0, biasadj=False)` |
| 96 | + |
| 97 | +BATS model for complex seasonality. [User Guide](user-guide/bats.md#bats) |
| 98 | + |
| 99 | +#### `TBATS(use_box_cox=None, use_trend=None, use_damped_trend=None, use_arma_errors=True, bc_lower=0.0, bc_upper=1.0, biasadj=False)` |
| 100 | + |
| 101 | +Trigonometric BATS for non-integer periods. [User Guide](user-guide/bats.md#tbats) |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +### Theta |
| 106 | + |
| 107 | +#### `Theta(model_type="OTM", alpha=None, theta_param=None, initial_level=None, nmse=3)` |
| 108 | + |
| 109 | +Theta method. [User Guide](user-guide/theta.md#theta) |
| 110 | + |
| 111 | +#### `AutoTheta(model=None, decomposition_type="multiplicative", alpha=None, theta_param=None, initial_level=None, nmse=3)` |
| 112 | + |
| 113 | +Automatic Theta selection. [User Guide](user-guide/theta.md#autotheta) |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +### Diffusion |
| 118 | + |
| 119 | +#### `Diffusion(model_type="Bass", cleanlead=True, loss=2, cumulative=True)` |
| 120 | + |
| 121 | +Innovation diffusion model. [User Guide](user-guide/diffusion.md) |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +### ARAR / ARARMA |
| 126 | + |
| 127 | +#### `ARAR(max_ar_depth=None, max_lag=None)` |
| 128 | + |
| 129 | +ARAR model. [User Guide](user-guide/ararma.md#arar) |
| 130 | + |
| 131 | +#### `ARARMA(max_ar_depth=26, max_lag=40, p=4, q=1)` |
| 132 | + |
| 133 | +ARARMA model. [User Guide](user-guide/ararma.md#ararma) |
| 134 | + |
| 135 | +#### `AutoARARMA(min_p=0, max_p=4, min_q=0, max_q=2, max_ar_depth=26, max_lag=40)` |
| 136 | + |
| 137 | +Automatic ARARMA selection. [User Guide](user-guide/ararma.md#autoararma) |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +### Intermittent Demand |
| 142 | + |
| 143 | +#### `CrostonClassic(init_strategy="mean", number_of_params=2, cost_metric="mar", optimize_init=True, rm_missing=False)` |
| 144 | + |
| 145 | +Croston's classic method. [User Guide](user-guide/intermittent.md#crostonclassic) |
| 146 | + |
| 147 | +#### `CrostonSBA(...)` |
| 148 | + |
| 149 | +Syntetos-Boylan Approximation. Same parameters as `CrostonClassic`. [User Guide](user-guide/intermittent.md#crostonsba) |
| 150 | + |
| 151 | +#### `CrostonSBJ(...)` |
| 152 | + |
| 153 | +Shale-Boylan-Johnston variant. Same parameters as `CrostonClassic`. [User Guide](user-guide/intermittent.md#crostonsbj) |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## ForecastResult |
| 158 | + |
| 159 | +```python |
| 160 | +@dataclass |
| 161 | +class ForecastResult: |
| 162 | + mean: np.ndarray # point forecasts |
| 163 | + lower: dict[int, np.ndarray] # {80: [...], 95: [...]} |
| 164 | + upper: dict[int, np.ndarray] # {80: [...], 95: [...]} |
| 165 | + level: list[int] # [80, 95] |
| 166 | + fitted_values: np.ndarray # in-sample fitted |
| 167 | + residuals: np.ndarray # in-sample residuals |
| 168 | + method: str # model description |
| 169 | + x: np.ndarray # original data |
| 170 | +``` |
| 171 | + |
| 172 | +### Methods |
| 173 | + |
| 174 | +| Method | Returns | Description | |
| 175 | +|--------|---------|-------------| |
| 176 | +| `.to_dataframe()` | `pd.DataFrame` | Columns: step, mean, lower_80, upper_80, ... | |
| 177 | +| `.plot(ax=None, show_history=True)` | matplotlib `Axes` | Plot forecast with intervals | |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## compare() |
| 182 | + |
| 183 | +```python |
| 184 | +compare( |
| 185 | + models: dict[str, BaseForecaster], |
| 186 | + y_train: array-like, |
| 187 | + y_test: array-like, |
| 188 | + m: int = 1, |
| 189 | + h: int | None = None, |
| 190 | + level: list[int] | None = None, |
| 191 | +) -> ComparisonResult |
| 192 | +``` |
| 193 | + |
| 194 | +[User Guide](user-guide/compare.md) |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## ComparisonResult |
| 199 | + |
| 200 | +| Attribute | Type | Description | |
| 201 | +|-----------|------|-------------| |
| 202 | +| `model_names` | `list[str]` | Model names | |
| 203 | +| `forecasts` | `dict[str, ForecastResult]` | Forecasts per model | |
| 204 | +| `metrics` | `dict[str, dict[str, float]]` | Metrics per model | |
| 205 | + |
| 206 | +| Method | Returns | Description | |
| 207 | +|--------|---------|-------------| |
| 208 | +| `.to_dataframe()` | `pd.DataFrame` | One row per model, metric columns | |
| 209 | +| `.plot(ax=None)` | matplotlib `Axes` | Overlay all forecasts | |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## PanelForecaster |
| 214 | + |
| 215 | +```python |
| 216 | +PanelForecaster(model: BaseForecaster, groupby: str | list[str]) |
| 217 | +``` |
| 218 | + |
| 219 | +| Method | Returns | Description | |
| 220 | +|--------|---------|-------------| |
| 221 | +| `.fit(data, y_col="y", m=1, date_col=None)` | `self` | Fit per group | |
| 222 | +| `.forecast(h=10, level=None)` | `PanelForecastResult` | Forecast all groups | |
| 223 | + |
| 224 | +[User Guide](user-guide/panel.md) |
| 225 | + |
| 226 | +--- |
| 227 | + |
| 228 | +## PanelForecastResult |
| 229 | + |
| 230 | +| Attribute | Type | Description | |
| 231 | +|-----------|------|-------------| |
| 232 | +| `groups` | `dict[Any, ForecastResult]` | Results per group | |
| 233 | + |
| 234 | +| Method | Returns | Description | |
| 235 | +|--------|---------|-------------| |
| 236 | +| `.to_dataframe()` | `pd.DataFrame` | Long-format with group column | |
| 237 | + |
| 238 | +--- |
| 239 | + |
| 240 | +## Metrics |
| 241 | + |
| 242 | +```python |
| 243 | +from durbyn.metrics import me, rmse, mae, mpe, mape, mase, acf1, accuracy |
| 244 | +``` |
| 245 | + |
| 246 | +| Function | Signature | Description | |
| 247 | +|----------|-----------|-------------| |
| 248 | +| `me(actual, predicted)` | `→ float` | Mean Error | |
| 249 | +| `rmse(actual, predicted)` | `→ float` | Root Mean Squared Error | |
| 250 | +| `mae(actual, predicted)` | `→ float` | Mean Absolute Error | |
| 251 | +| `mpe(actual, predicted)` | `→ float` | Mean Percentage Error (%) | |
| 252 | +| `mape(actual, predicted)` | `→ float` | Mean Absolute Percentage Error (%) | |
| 253 | +| `mase(actual, predicted, training_data)` | `→ float` | Mean Absolute Scaled Error | |
| 254 | +| `acf1(actual, predicted)` | `→ float` | Lag-1 autocorrelation of errors | |
| 255 | +| `accuracy(actual, predicted, training_data=None)` | `→ dict` | All metrics combined | |
| 256 | + |
| 257 | +[User Guide](user-guide/metrics.md) |
| 258 | + |
| 259 | +--- |
| 260 | + |
| 261 | +## Exceptions |
| 262 | + |
| 263 | +```python |
| 264 | +from durbyn.exceptions import DurbynError, NotFittedError, JuliaNotAvailableError, DurbynNotInstalledError |
| 265 | +``` |
| 266 | + |
| 267 | +| Exception | Parent | Description | |
| 268 | +|-----------|--------|-------------| |
| 269 | +| `DurbynError` | `Exception` | Base exception | |
| 270 | +| `JuliaNotAvailableError` | `DurbynError, ImportError` | Julia runtime not found | |
| 271 | +| `DurbynNotInstalledError` | `DurbynError, ImportError` | Durbyn.jl not installed | |
| 272 | +| `NotFittedError` | `DurbynError, RuntimeError` | Model not fitted yet | |
0 commit comments