Time Series - jejjohnson/ml4eo GitHub Wiki
Analysis
Cross Validation
Software
Time Series Features
- Date-Decomposition -> Year, DOY, Season, Month, Day, Hour
- Min-Max Rescale -> [0,1], [-1,1]
- Cyclic Features (Sin, Cosine) - skforecast, Blog - General Pandas Function
- B-Splines - skforecast
- Radial Basis Functions - skforecast
- Fourier Decomposition - stribor
- Sinusoidal Positional Embeddings
- Kernels
PseudoCode
Validate Time Series
Create DateTime Series
Dates
dates = pd.date_range(start="2000/01/01", freq="D", periods=10, units=D, tz='Asia/Tokyo')
# change timezone
dates = dates.tz_localize("Europe/Berlin")
dates = xr.cftime_range("1990-01", "1992-01", freq="ME")
Times
# create time range
times = pd.date_range("11:00", "21:30", freq="30min").time
times = pd.timedelta_range("11:00:00", "21:30:00", freq="30min")
Create Temporal Features
df['year'] = df['datetime'].dt.year
df['month'] = df['datetime'].dt.month
df['day'] = df['datetime'].dt.day
df['day_of_week'] = df['datetime'].dt.day_of_week
df['day_of_year'] = df['datetime'].dt.day_of_year
df['minute_of_day'] = df['datetime'].dt.hour * 60 + df['datetime'].dt.minute
df['quarter'] = df['datetime'].dt.quarter
df['is_month_end'] = df['datetime'].dt.is_month_end
df['is_leap_year'] = df['datetime'].dt.is_leap_year
date_features = df[[
'year', 'month', 'day', 'day_of_week', 'day_of_year', 'minute_of_day',
'quarter', 'is_month_end', 'is_leap_year'
]].values
Create Cyclic Temporal Features
data['hour_sin'] = np.sin(2 * np.pi * data['hour']/24.0)
data['hour_cos'] = np.cos(2 * np.pi * data['hour']/24.0)
def encode(data, col, max_val) :
data [col + '_sin'] = np.sin(2 * np.pi * data[col]/max_val)
data [col + '_cos'] = np.cos(2 * np.pi * data[col]/max_val)
return data
data = encode(data, 'month', 12)
data = encode(data, 'day of week', 7)