pretab.transformers.CyclicalTimeTransformer
- class pretab.transformers.CyclicalTimeTransformer(period)[source]
Bases:
BasePreTabTransformerEncode a cyclical time variable using sine and cosine components.
Maps a periodic integer feature (such as hour of day or day of week) onto two continuous features so that the cyclic boundary is continuous.
- Parameters:
period (int) – The full cycle length (e.g., 24 for hours, 7 for weekdays).
Notes
For a value \(x\) with period \(p\), the encoding is
\[\left(\sin\!\left(\frac{2\pi x}{p}\right),\; \cos\!\left(\frac{2\pi x}{p}\right)\right).\]Each input feature therefore expands into two output columns.
This is a standalone time-series utility. Although it preserves the row count, it takes a required per-feature
periodand constrains inputs to[0, period], so it is not wired intoPreprocessor(which applies one method uniformly across columns). Apply it directly to the relevant cyclical column instead.Examples
>>> import numpy as np >>> from pretab.transformers import CyclicalTimeTransformer >>> X = np.array([[0], [6], [12], [18]]) >>> transformer = CyclicalTimeTransformer(period=24) >>> transformer.fit_transform(X).shape (4, 2)- __init__(period)[source]
Methods
__init__(period)fit(X[, y])fit_transform(X[, y])Fit to data, then transform it.
get_feature_names_out([input_features])Return output feature names of the form
{feature}_{suffix}{j}.get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
transform(X)Attributes
total_output_dim_Total number of output columns produced across all input features.
n_features_in_adaptive