Machine Learning/Dynamic Time Warping: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
(Created page with " sample script: <pre> import numpy as np import mlpy # Example sequences sequence1 = np.array([1, 3, 4, 9, 8, 2, 1]) sequence2 = np.array([1, 2, 4, 7, 8, 2, 1]) sequence3 = np.array([1, 2, 4, 7, 8, 2, 5]) # Compute DTW distances between sequences dist12, cost12, path12 = mlpy.dtw_std(sequence1, sequence2, dist_only=False) dist13, cost13, path13 = mlpy.dtw_std(sequence1, sequence3, dist_only=False) print("DTW distance between sequence1 and sequence2:", dist12) print("...")
 
No edit summary
Line 24: Line 24:
     print("Sequence 3 is predicted to be closer to sequence 1.")
     print("Sequence 3 is predicted to be closer to sequence 1.")
</pre>
</pre>
[[category:MachineLearning]]
[[category:Script]]

Revision as of 14:29, 24 July 2024

sample script:

import numpy as np
import mlpy

# Example sequences
sequence1 = np.array([1, 3, 4, 9, 8, 2, 1])
sequence2 = np.array([1, 2, 4, 7, 8, 2, 1])
sequence3 = np.array([1, 2, 4, 7, 8, 2, 5])

# Compute DTW distances between sequences
dist12, cost12, path12 = mlpy.dtw_std(sequence1, sequence2, dist_only=False)
dist13, cost13, path13 = mlpy.dtw_std(sequence1, sequence3, dist_only=False)

print("DTW distance between sequence1 and sequence2:", dist12)
print("DTW distance between sequence1 and sequence3:", dist13)

# Predict which sequence is closer based on DTW distance
if dist12 < dist13:
    print("Sequence 2 is predicted to be closer to sequence 1.")
else:
    print("Sequence 3 is predicted to be closer to sequence 1.")