TARNNResult.predict#
- TARNNResult.predict(features, threshold_values)[source]#
Conditional means, routing each row to its regime’s learner.
Takes the threshold variable explicitly rather than deriving it from
features. For a self-exciting model withdelay <= orderit could be read off a column, but not when the delay exceeds the order and not at all when the threshold variable is external – so requiring it keeps one code path that is correct in every configuration.- Parameters:
- Return type:
- Returns:
An array of length
n.- Raises:
DimensionError – If the feature matrix has the wrong shape, or
threshold_valuesdoes not match its row count.
Example
The in-sample fit reproduced from the lag matrix and the stored threshold variable:
>>> import numpy as np >>> from cultivars.engine._core._matrices import _lag_matrix >>> rng = np.random.default_rng(0) >>> y = rng.standard_normal(300) >>> res = TARNN(y, order=1).fit() >>> means = res.predict(_lag_matrix(y, 1), res.threshold_values) >>> bool(np.allclose(means, res.fittedvalues)) True >>> res.predict(_lag_matrix(y, 1), res.threshold_values[:5]) Traceback (most recent call last): ... cultivars.exceptions.DimensionError: threshold_values must have shape (299,); got (5,).