Advertisement
Guest User

normalized code

a guest
Sep 13th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. import stumpy
  5. import numpy as np
  6.  
  7. data = pd.read_csv('https://docs.google.com/spreadsheets/d/1SQfhz7_FLaA7aADKdMrf2SL1p2TgQQfnH-earg1eOCY/export?gid=0&format=csv')
  8.  
  9. def min_max_scaling(column):
  10. min_val = column.min()
  11. max_val = column.max()
  12. normalized_column = (column - min_val) / (max_val - min_val)
  13. return normalized_column
  14.  
  15. data['price'] = min_max_scaling(data['price'])
  16. data['Market Cap'] = min_max_scaling(data['Market Cap'])
  17.  
  18.  
  19.  
  20. first_data = data["price"]
  21. second_data = data["Market Cap"]
  22.  
  23. m = 30
  24. Q = first_data.tail(30)
  25. T = second_data
  26.  
  27. distance_profile = stumpy.mass(Q, T, normalize=True)
  28. idx = np.argmin(distance_profile)
  29.  
  30.  
  31. time_series = first_data
  32.  
  33. # Number of latest points to highlight
  34. highlight_points = 30
  35.  
  36. # Range to mark
  37. start_range = idx
  38. end_range = idx + m
  39.  
  40. # Create the first plot with the gray rectangle for the latest 30 values
  41. plt.figure(figsize=(10, 6))
  42. plt.subplot(2, 1, 1)
  43. plt.plot(time_series, label='Time Series')
  44. latest_data = time_series[-highlight_points:]
  45. x_coordinates = np.arange(len(time_series) - highlight_points, len(time_series))
  46. y_min = np.min(time_series)
  47. y_max = np.max(time_series)
  48. rect = plt.Rectangle(
  49. (x_coordinates[0], y_min),
  50. highlight_points,
  51. y_max - y_min,
  52. fill=True,
  53. color='gray',
  54. alpha=0.5,
  55. )
  56. plt.gca().add_patch(rect)
  57. plt.xlabel('Time')
  58. plt.ylabel('Value')
  59. plt.title('Time Series with Gray Rectangle for Latest 30 Values (first_data)')
  60. plt.legend()
  61.  
  62. # Create the second plot with the gray rectangle for the specified range
  63. plt.subplot(2, 1, 2)
  64. plt.plot(second_data, label='Time Series')
  65. plt.axvspan(start_range, end_range, color='gray', alpha=0.5)
  66. plt.xlabel('Time')
  67. plt.ylabel('Value')
  68. plt.title('The other graph in which I have to find the similar pattern (second_data)')
  69. plt.legend()
  70.  
  71. # Adjust layout
  72. plt.tight_layout()
  73.  
  74. # Show the plots
  75. plt.show()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement