'Clustering within a single time series (detecting process changes)

I have a single time series where you can clearly see a process change (denoted by the manually drawn lines). I am trying to detect and cluster these changes so that I can be notified when a new cluster is beginning. I have already attempted K-means clustering, agglomerative clustering and they do a decent job but do not seem to cluster based on time, only the value. I expect to have 6 clusters in the timeseries. You can see the algorithm typically ignores time. Manual clustering Clustering attempt

I have googled a lot and discovered DTW however every article I read is comparing multiple time series instead of detecting changes within a single time series.

Does anyone have any references I can read up on this or have any solutions?

I am unable to provide actual data however here is some example data that you can use:

library(tidyverse)
example_data <- tibble(
  date_seq = 1:300,
  value = c(
    rnorm(65, .1, .1), 
    rnorm(65, -.25, .1),
    rnorm(20, 4, .25),
    rnorm(80, -.25, .1),
    rnorm(20, 4, .25),
    rnorm(50, 0, .1)
  )
)

Thank you!



Solution 1:[1]

I needed to solve a problem similar to yours. However, I used Markov to identify regime change moments instead of opting for a clustering method.

Here are good articles about it:

[RPubs by Majeed Simaan] [https://rpubs.com/simaan84/regime_switching]

[R-bloggers by Andrej Pivcevic] [https://www.r-bloggers.com/2019/02/switching-regressions-cluster-time-series-data-and-understand-your-development/]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ciniro Nametala