How to get periodicity from timeseries data?

I would like to create a recommendation system for a smart home application. I gather the data in a time-series database. The app monitors the on/off state of a smart lamp and can create daily routines. I would like to create notifications to the user like "It looks like you are usually use your lamp from 8:00 to 10:00. Would you like to create a routine for that?".

I am beginner to data science and machine learning and I would like to ask what kind of machine learning algorithm or method should I use for this problem. Someone recommended me Facebook Prophet, but as I can see that library can only predict future occurences not the periodicity of time-series data. Do you know any library or algorithm?

In the image below you can see my problem detailed. There is hourly on/off state of the lamp daily in green and in blue the result that I would like to get: the periods that the lamp is usually on.

Looking at your data - the easiest way is to create a Last-N Days hourly average of the binary indicator - and then use a threshold (based on experimentation) to binarize it.

e.g. if your Last 10 Day hourly average looks like this:

0, 0, 0.6, 0.8, 0.9, 1, 0.9, 0.7, 0, 1, 1, 1, 0

Then, a threshold of 0.8 to binarize would result in the following:

0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0

and - then you could use the time slices associated with the 1's for the recommendation.

This might be the simplest thing you could do - There could however be more sophisticated algorithms out there.

• It probably be better to calculate the standard deviation as well as base the threshold on that instead of the mean directly. Feb 25, 2023 at 15:26

I don't think you need machine learning for this. Firstly, lets assume each pattern repeats daily. Extract the lamp feature and then reshape it to be shape (n,24), where n is the number of days you have data. To add a recency bias you could take the m most recent of the n days. From here you can apply the same process as Jayaram suggests.

However, what if you don't know the period of the pattern in a feature? To find this out you could use a Fast Fourier Transform. Look for the peaks in your FFT graph, those are the periods. Be careful, as its common for a feature to have multiple periods, so multiple peaks on the graph.