I have real time data source that emits numeric values every 5 seconds. I wanted to raise alert whenever, for example the last 5 consecutive values, deviate more than a certain level. As you can see the figure below, values oscillates between max and min and the peak (max) gradually increases. Ideally when it is at peak, it should remain constant or small up and down is also acceptable. However, sudden or slow consecutive increase or decrease is when I want to raise alert.
I played with different models like AR (autoregressive model) and ARIMA but the sample is below recommended in a given period. On top of that it usually takes long time to predict.
I appreciate greatly if you guide me to any model or approach that is more suitable for this task. I don't want to predict the next value given the current value, I want to check at the peak the past few values are increasing or decreasing in a given period.
X = data['weight'].values size = int(len(X) * 0.02) train, test = X[0:size], X[size:len(X)] history = [x for x in train] predictions = list() for t in range(len(test)): model = ARIMA(history, order=(5,1,0)) model_fit = model.fit(disp=0) output = model_fit.forecast() yhat = output predictions.append(yhat) obs = test[t] history.append(obs) print('predicted=%f, expected=%f' % (yhat, obs)) error = mean_squared_error(test, predictions) print('Test MSE: %.3f' % error) # plot print('plotting')