jony
jony

Reputation: 934

time series correlation using dynamic time warping(DTW) in python

here is my three time series:

t1  t2  t3
3   8   17
1   8   18
0   8   17
0   8   18
2   8   17
3   8   17
0   8   18
0   8   17
2   8   17
3   8   18
1   8   17
0   8   17
0   8   17
1   8   17
2   8   16
2   8   16
3   8   16
0   8   16
2   8   16
2   8   16
3   8   16
1   8   17
1   8   16
2   8   16
3   8   16
1   8   17
2   8   16
4   8   17
0   8   16
1   8   17
3   8   16
0   8   16
3   8   16
2   8   16
2   8   17
0   8   16
2   8   16
2   8   17
3   8   16
3   8   16
3   8   16
2   8   16
4   8   16
1   8   16
0   8   17
0   8   17
2   8   17
1   8   17
2   8   17
2   8   18
0   8   18
1   8   18
0   8   17
0   8   17
2   8   17
1   8   17
2   8   17
0   8   17
0   8   17
0   8   17

as i have seen , DTW can give us output , which can tell us a similarity between time- series

but i don't know how can we do that?

how can we say that with the output of DTW?

which distance is good ?? high or low?

help me to solve this problem

Thanks

Upvotes: 1

Views: 2626

Answers (1)

Zaraki Kenpachi
Zaraki Kenpachi

Reputation: 5740

With use of DTW:

import pandas as pd
from io import StringIO
from dtaidistance import dtw

data = StringIO("""
t1   t2   t3
3   8   17
1   8   18
.   .   .
.   .   .
0   8   17
0   8   17
""")

# load data into data frame
df = pd.read_csv(data, sep='   ', engine='python', dtype=float)
# transpose data
transposed_matrix = df.values.transpose()
# calculate series cost
results = dtw.distance_matrix_fast(transposed_matrix, compact=True)

Output:

Cost results for comparing 3 time series. Lower cost is better.

[ 51.4392846  118.73078792  67.71262807]

Upvotes: 1

Related Questions