pretab.transformers.RollingStatsTransformer
- class pretab.transformers.RollingStatsTransformer(window_size=5, stats=('mean', 'std'))[source]
Bases:
BasePreTabTransformerCompute rolling-window statistics over time-series inputs.
A sliding window of fixed size is moved across each feature and the requested summary statistics are computed within each window.
- Parameters:
window_size (int, default=5) – Number of consecutive observations in each rolling window.
stats (tuple of str, default=("mean", "std")) – Statistics to compute. Any of
"mean","std","min","max".
Notes
Using a sliding window of size
window_sizeyieldsn_samples - window_size + 1output rows. Each requested statistic adds one column per input feature.This is a standalone time-series utility. It intentionally changes the row count and assumes the rows are ordered in time, so it does not satisfy the row-count-preserving contract that
ColumnTransformer(and thereforePreprocessor) require. Apply it directly to an ordered array rather than routing it through the preprocessing pipeline.Examples
>>> import numpy as np >>> from pretab.transformers import RollingStatsTransformer >>> X = np.arange(10).reshape(-1, 1).astype(float) >>> transformer = RollingStatsTransformer(window_size=3, stats=("mean", "std")) >>> transformer.fit_transform(X).shape (8, 2)- __init__(window_size=5, stats=('mean', 'std'))[source]
Methods
__init__([window_size, stats])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