sss
import numpy as np import pandas as pd import matplotlib.pyplot as plt import pywt # Load the AirPassengers dataset url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv' data = pd.read_csv(url, parse_dates=['Month'], index_col='Month') time_series = data['Passengers'].values # Apply Wavelet Decomposition wavelet = 'db4' coeffs = pywt.wavedec(time_series, wavelet, level=4) # Extract Approximation Coefficients (Stable Component) cA = coeffs[0] # Reconstruct the Stable Signal stable_signal = pywt.waverec([cA] + [None] * (len(coeffs) - 1), wavelet) # Align the length of the stable signal with the original time series stable_signal = stable_signal[:len(time_series)] # Plot the Original Time Series and the Stable Signal plt.figure(figsize=(14, 7)) plt.plot(data.index, time_series, label='Original Time Series', color='blue') plt.plot(data.index, stable_signal, label='Stable Signal (Approximation)...