What is the right algorithm to detect segmentations of a line chart? To be concrete, given 2D numerical data as is shown as line plots below. There are peaks on a background average movement (with small vibrations). We want to find the values of pairs (x1, x2) if those peaks drops down to normal; or (x1) only if the line doesn't back to the normal.


There are thousands of such 2D data.
What is the right statistic or machine learning algorithm to find x1 and x2 above without plotting?
 A: The problem that you have in hand is called outlier detection in time series in analysis. There are three three major forms of outliers:


*

*Level Shifts (permanent shift in the level of series)

*Additive Outliers (temporary outlier pulse)

*Temporary Changes.


There are several methods and tools that will be able to do this. Two classic approaches within ARIMA framework are:


*

*Tsay's Approach 

*Chen and Liu's Approach
Chen and Liu's approach is implemented in tsoutliers package in R. Other software packages such as SPSS/SAS/Autobox have automatic outlier detection algorithms. 
Below is an example in R and tsoutliers package using a dummy data similar to your example and the sample data plot is from expsmooth package:

library(expsmooth)
library(tsoutliers)

data <- hospital[,20]
plot(data)

identify.outliers <- tso(data,  types = c("AO", "LS", "TC"))
identify.outliers
plot(identify.outliers)

Running the above code, the tsoutlier package was able to identify inflection point at 13 and 37. See below for the results and plots.

Series: data 
ARIMA(1,0,0) with non-zero mean 

Coefficients:
          ar1  intercept     LS13      LS37
      -0.2834   266.9890  52.0028  -75.9691
s.e.   0.1044     4.5006   5.5221    3.8625

sigma^2 estimated as 386.3:  log likelihood=-369.41
AIC=748.83   AICc=749.6   BIC=760.98

Outliers:
  type ind    time coefhat   tstat
1   LS  13 2001:01   52.00   9.417
2   LS  37 2003:01  -75.97 -19.668

You could also try structural time series analysis such as Unobserved Components Model, which can detect outliers and level shifts in data.
