Linear trend of time series.
Test with Dummy Data¶
N = 700
t = np.arange(N)
trend = 0.05*t + 0.1
trend[t>350] = -0.1*(t[t>350] - 350) + trend[t==350]
noise = np.random.randn(*trend.shape)
y = trend + noise
# y = np.clip(y, 1, 20)
plt.plot(t, y)
plt.plot(t, trend)
plt.show()
breakpoints = torch.Tensor([250, 500])
model = Trend(breakpoints)
learner = Learner(db, model, loss_func=F.mse_loss)
wd = 0
learner.lr_find(wd=wd)
learner.recorder.plot(skip_end=0)
epochs = 10
learner.fit_one_cycle(epochs, 1e-1, wd=wd)
y2 = learner.model(torch.Tensor(t)[:,None])
plt.plot(t, y, label='actual')
plt.plot(t[:train_len], y[:train_len], label='train set')
plt.plot(t, y2, label='prediction')
plt.legend()
plt.show()