# Features to represent peaks in time series

I have a dataset of time series that present popularity of words (or phrases). Each words is a list of frequencies according to a timestamp. My purpose is to detect a specific type of spike that leads to an event A. For example in my data I know that some spikes in the words lead to an event A while other spikes of similar frequency did not. Currently I am using a custom method measuring the height of the peak, the increase ratio relative to the baseline activity, and existence of some symbols in the words (or phrases). I am using custom thresholds in order to make decisions. I know that this is not the right way to do that, for example I could use an optimizer to find the best thresholds apart from trial and error.

So I decided to model only the peaks of the time series and create a dataset of peaks that lead to event A and peaks that lead to event B. Using the visualizations it is very difficult to understand the difference in the peaks between the two types.

Now my question is:

• Is this procedure the right one for such a problem?
• How can I represent a peak? What kind of features can I use? I am thinking of using my current thresholds as features (frequency,growth ratio,decay ratio) but I am not sure if this is appropriate.
• I am thinking of using these features to train a logistic regression classifier or a neural network. Is this straitforward?

My dataset creation is based on Grubbs test for outliers. When ever I see an outlying word this means that there is a peak. I store the peak with the above information and its class label (A or B).

Since using the visualizations I cant understand the difference between the type of peaks means that my features are not informative. What relevant problems can I look for to have an idea?

• You are focusing on the frequency of a specific word, and how its usage could predict events? Is this Twitter-trading (i.e. doing sentiment-analysis to predict market movements)? Or do you have a corpus of words you are following, in which case have you classified them in any way? Oct 7, 2013 at 6:03
• I have only the Twitter topics and a count of tweets referring it. Currently I can predict events using the Grubbs test and frequency thresholds. But.... the thresholds are set but hand. So my main problem is how to use ML for such a problem. Oct 7, 2013 at 9:11

## 2 Answers

If you want to use machine learning instead of outlier detection methods, then you are on the right track.

How can I represent a peak? What kind of features can I use? I am thinking of using my current thresholds as features (frequency,growth ratio,decay ratio) but I am not sure if this is appropriate.

Yes. Frequency, growth ratio, decay ratio are good features. Of course, it remains to be seen how well they perform in your dataset. You could also consider the following features that are routinely used in this kind of problems:

• Mean
• Median
• Standard deviation
• Power spectrum
• Magnitude
• Kurtosis
• Percentil
• Principal frequency
• Magnitude of first five components of FFT
• Skewness
• Entropy
• Mean absolute difference
• Autoregressive coefficients
• Wavelet coefficients
• Crest factor

Now, you have to think carefully about which features are likely to provide good separation between event A and B. For example, I don't think entropy or autoregressive coefficients are going to give much of a separation, but kurtosis, standard deviation and crest factor look more promising.

I am thinking of using these features to train a logistic regression classifier or a neural network. Is this straitforward?

Sure. You may want to try decision trees or even kNN. I have found good results with decision trees.

If all else fails, I suggest looking at SAX, Symbolic Polynomials or Shapelets.

• Hi, the can the Shapelets you mention be used for different length time series? Jun 9, 2015 at 4:21

Here is an idea. Suppose your words/phrases are arranged in columns, and for every timestamp you have a row of phrase-counts:

         Gas prices          Fertilizer         Lady Gaga
10:00:05     97                  105               23
10:10:23     89                   80               65
...


By considering a single column at a time, you can compute a mean & standard deviation, and thereby through your Grubbs measure get your outliers.

Keep in mind that you will have to use a moving average and moving standard deviation, to keep current with new trends.

Now imagine this table looks like a grid of colored tiles. Outliers are colored red, and the others are green.

Make sure the rows are evenly spaced - your input data is not likely to be so clean, so you will need to do this yourself. Maybe one grid-row for every 10 minutes? You will need to figure out how to color missing rows - maybe make a square red if and only if the squares above and below are red.

Now when an event comes in, say at a time $T$, choose a "history window" leading up to that time. You will have to experiment and decide how long that windows is, but basically that will give you an "image" of red and green squares which correspond to that event.

Now you can train an SVM to attach that image to that event.