Generate code for training a model that detects anomaly in quasi periodic stream of time series. The code should be in python and use tensorflow framework.  Write your response with at least 100 words.
user