Fourier Features: Generating Time Series Features for Machine Learning
import numpy as np import pandas as pd
def fourier_features(index, freq, order): time = np.arange(len(index), dtype=np.float32) k = 2 * np.pi * (1 / freq) * time features = {} for i in range(1, order + 1): features.update({ f'sin_{freq}{i}': np.sin(i * k), f'cos{freq}_{i}': np.cos(i * k), }) return pd.DataFrame(features, index=index)
Compute Fourier features to the 4th order (8 new features) for a
series y with daily observations and annual seasonality:
fourier_features(y, freq=365.25, order=4)
Input Example
y = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
freq = 365.25
order = 4
Output Example
features = fourier_features(np.arange(len(y)), freq, order) print(features)
原文地址: http://www.cveoy.top/t/topic/nUYl 著作权归作者所有。请勿转载和采集!