I would like to detect a time series regime change (or anomaly). By regime change, I mean that the linear trend is changed / broken (see plot below).
import numpy as np
import matplotlib.pyplot as plt
x = range(50)
y = [1.28, 1.28, 1.26, 1.32, 1.34, 1.33, 1.38, 1.39, 1.37, 1.42,
1.42, 1.41, 1.39, 1.41, 1.45, 1.45, 1.46, 1.5, 1.49, 1.53, 1.53,
1.54, 1.61, 1.59, 1.62, 1.66, 1.63, 1.66, 1.66, 1.7, 1.76, 1.84,
1.88, 1.97, 1.94, 1.98, 2.01, 2.02, 0.73, 0.72, 0.76, 0.87, 0.97,
1.01, 0.98, 1.16, 1.22, 1.3, 1.27, 1.33]
plt.scatter(x, y)
plt.show()
I have been searching for a while but cannot find a way to detect the big change in this time series.
Detecting a diff is not enough for me because I need to be able to detect that the rough linear trend is changed. The data can have a diff from one observation to the next that is large but the trend (linear trend) is still correct.
To explain why I abandoned the diff method:
The observation in x-axis around 45-46 shows a jump in the value but is actually in the linear trend, therefore not a "regime change" for me. This is exactly why I abandoned the diff method and I am looking for a "trend" method. I have been thinking of looping on observations, fit a linear regression and predict the next point, calculate an error, etc. But I would rather use a library made for this if it exists.