资源简介
用于轴承大数据的故障诊断和数据挖掘,可将轴承的振动信息进行数组分析,获得预测模型,准确率较高
代码片段和文件信息
# -*- coding:utf-8-*-
def DTW(s1 s2):
“““
计算s1和s2两个向量之间的距离
使用曼哈顿距离,如果时间序列输入是二维的那么建议使用欧几里得距离
“““
import numpy as np
from numpy import array zeros argmin inf equal ndim
from sklearn.metrics.pairwise import manhattan_distances
r c = len(s1) len(s2)
D0 = zeros((r+1c+1))
D0[01:] = inf
D0[1:0] = inf
D1 = D0[1:1:]
for i in range(r):
for j in range(c):
D1[ij] = manhattan_distances(np.array(s1[i]).reshape(-11)np.array(s2[j]).reshape(-11))
M = D1.copy()
for i in range(r):
for j in range(c):
D1[ij] += min(D0[ij]D0[ij+1]D0[i+1j])
ij = array(D0.shape) - 2
pq = [i][j]
while(i>0 or j>0):
tb = argmin((D0[ij]D0[ij+1]D0[i+1j]))
if tb==0 :
i-=1
j-=1
elif tb==1 :
i-=1
else:
j-=1
p.insert(0i)
q.insert(0j)
return D1[-1-1]
if __name__ == “__main__“:
# 测试DTW计算结果
import numpy as np
s1 = np.array([1 2 3 4 5 5 5 4])
s2 = np.array([3 4 5 5 5 4])
print(DTW(s1s2))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 19 2019-03-31 01:08 DataMiningProject-Bearing\.gitignore
....... 7958 2019-03-31 01:08 DataMiningProject-Bearing\.ipynb_checkpoints\train-checkpoint.ipynb
....... 3069 2019-03-31 01:08 DataMiningProject-Bearing\data\result.csv
....... 64411404 2019-03-31 01:08 DataMiningProject-Bearing\data\test_data.csv
....... 96539633 2019-03-31 01:08 DataMiningProject-Bearing\data\train.csv
....... 1239 2019-03-31 01:08 DataMiningProject-Bearing\DTW.py
....... 5033 2019-03-31 01:08 DataMiningProject-Bearing\README.md
文件 17779 2020-04-11 23:06 DataMiningProject-Bearing\train.ipynb
目录 0 2019-03-31 01:08 DataMiningProject-Bearing\.ipynb_checkpoints
目录 0 2019-03-31 01:08 DataMiningProject-Bearing\data
目录 0 2020-04-11 23:06 DataMiningProject-Bearing
----------- --------- ---------- ----- ----
160986134 11
评论
共有 条评论