Share EncyclopediaHome EncyclopediaCategories Switch Channel

Three python methods of comparing the two time series to the same graphic sharing

2026-06-18 07:09800NameNetworking

Three python methods of comparing the two time series to the same graphic sharing

Update: 23/03/03 08:53:03 by python practical monument

This article provides you with three methods of comparing the two time series in python with a graphic similarity. Down

Compares the graphic similarity of the two time series by:

Visual comparison: two time series are drawn on the same map and compared using the same scale and axis labels. They can be compared by observing characteristics such as trends, peaks and valleys。

3. Comparison of peaks and valleys: comparison by comparison of peaks and valleys in two time series. Their magnitude and location can be compared。

Method of measuring time series similarity

3. Relevance analysis: calculate relevant coefficients between time series to determine whether they have linear relationships. If their relevant coefficients are close to 1, their trends are similar。

Non-linear approach: a non-linear approach is used to compare two time series, such as dynamic time scheduling, small wave change, etc. These methods help capture similarities between the two time series。

It should be noted that similarity on graphics does not fully represent a similarity between the two time series, as the same graphic can correspond to different time series. Therefore, a combination of multiple information needs to be considered in the time series comparison。

1. Preparation

Before you start, make sure that python and pip are installed successfully on the computer, and if not, you can access the article: super-detailed python installation guide for installation。

If you use python for data analysis, you can install anaconda directly, which contains python and pip.

Method of measuring time series similarity

In addition, it is recommended that you use the vscode editor, which has many advantages

Please select either of the following ways to enter the command installation dependency:

Windows environment opens cmd (start-run-cmd)。

Macos environment open terminal (command+space input)。

If you're using a vscode editor or pycharm, you can use terminal directly below the interface.

Pip install matplotlib
pip install numpy

2. Comparison of two time series using matplotlib visualization

II'm sorry, mate.
# generate time series data
x = [1, 2, 3, 4, 5]
y1 = [10, 15, 13, 17, 20]
y2 = [8, 12, 14, 18, 22]
# draw a two-time line figure
plt. Plot(x, y1, label='y1')
plt. Plot(x, y2, label='y2')
# set graphic properties
plt. Xlabel ('time')
plt. Ylabel
plt. Itle. Plt. Legend()
# show graphics
plt. Show()

Method of measuring time series similarity

2. Factors relevant to the calculation of two time series

II'm sorry.
# generate time series data
x = [1, 2, 3, 4, 5]
y1 = [10, 15, 13, 17, 20]
y2 = [8, 12, 14, 18, 22]
# calculate relevant coefficients
corr = np. Corrcoef(y1, y2) [0, 1]
# output result
("correction coefficient: ', corr)

3. Use of python to achieve dynamic time adjustment algorithms (dtw)

II'm sorry.
# generate time series data
x = [1, 2, 3, 4, 5]
y1 = [10, 15, 13, 17, 20]
y2 = [8, 12, 14, 18, 22]
# dynamic time adjustment algorithm
df dtw disarmament (ts a, ts b, d=lambda x, y:abs(x-y)):
dttw =}
# initializing border conditions
for i in range (len(ts a):
dttw [(i, -1)] = float('inf')
for i in range (len(ts b):
dtw [(-1, i)] = float('inf')
dtw [(1, 1)] = 0
# compute the dtw matrix
for i in range (len(ts a):
for j in range (len(ts b):
cost = d (ts a[i], ts b[j])
dtw [(i, j)] = cost + min (dtw [(i-1, j)], dtw [(i, j-1)], dtw [(i-1, j-1)])
# return to dtw distance
return dttw [len(ts a)-1, llen(ts b)-1]
# calculating the dtw distance between two time series
dtw dislist =dtw distance(y1, y2)
# output result
right

This is where the article about three pythons sharing methods for comparing the two time series to the same graphics, and more about python comparing the time-series graphics to the same content. Please search for previous script home articles or continue to look at the following articles and ask for more support for the script house later

Like 0
Report
Favorite 0
Tip 0
Comment 0
Share 7
MoreRelated Comments
No comments yet, be the first to comment
2名男子射钉器改装成枪进保护区狩猎被刑拘
图为两名犯罪嫌疑人刚出保护区便被蹲守的民警抓获 解雄波 摄图为民警查获的二人由射钉器改装的射钉枪及野生松鼠死体 解雄波 摄中新网西双版纳4月16日电 (马骞 常宗波)正值云

0评论2026-08-02133

Coconut hymns, southland's name park, and the order of armaments
Spring south, five ridge south, coast coast. From the beginning of the palace of the south vietnamese kings, lun song flourished and became so clear and so great that the courtyards, waterstones and trees were the treasure of the chinese garden. In this way, it is a reminder of its geographical origin, the beauty of superstition, the dynasty of the pavilion, the depth of the flower wood, and its ancient legacy。I. Original language"ring sou

0评论2026-08-0168