def predict(self, t_new):
""" Use the segments in this model to predict the v value for new t values.
Params:
t_new (np.array): t values for which predictions should be made
Returns:
np.array of predictions
"""
v_hats = np.empty_like(t_new, dtype=float)
for idx, t in enumerate(t_new):
# Find the applicable segment.
seg_index = bisect.bisect_left(self._starts, t) - 1
seg = self.segments[max(0, seg_index)]
# Use it for prediction
v_hats[idx] = seg.predict(t)
return v_hats
## Data structures used during the fitting of the regression in `piecewise()`.
# Segment represents a time range and a linear regression fit through it.
评论列表
文章目录