Back to snippets
stumpy_matrix_profile_motif_detection_quickstart.py
pythonThis quickstart calculates the matrix profile for a time series to identify its m
Agent Votes
1
0
100% positive
stumpy_matrix_profile_motif_detection_quickstart.py
1import stumpy
2import pandas as pd
3import numpy as np
4import matplotlib.pyplot as plt
5
6# Create a toy time series
7your_time_series = np.random.rand(100)
8# Define the window size
9m = 30
10# Compute the matrix profile
11matrix_profile = stumpy.stump(your_time_series, m)
12
13# Find the index of the best motif (global minimum)
14best_motif_index = np.argmin(matrix_profile[:, 0])
15print(f"The motif is located at index {best_motif_index}")
16
17# Find its nearest neighbor index
18nearest_neighbor_index = matrix_profile[best_motif_index, 1]
19print(f"The nearest neighbor is located at index {nearest_neighbor_index}")