Pipeline
The ForecastPipeline chains preprocessing transformers with a forecasting model. Transformations are automatically inverted when generating predictions, so your forecasts come back in the original data scale.
Basic Pipeline
from vectrix.pipeline import ForecastPipeline, Scaler, OutlierClipper
pipe = ForecastPipeline([
('clip', OutlierClipper()),
('scale', Scaler()),
('forecast', MyForecaster()),
])
pipe.fit(y)
predictions, lower, upper = pipe.predict(12) The pipeline
- fit — sequentially
fitTransformeach transformer, thenfitthe forecaster on transformed data - predict — get predictions from the forecaster, then
inverseTransformthrough all transformers in reverse order
Built-in Transformers
| Transformer | What it does | Inverse? |
|---|---|---|
Scaler(method='zscore') | Z-score standardization or MinMax normalization | Yes |
LogTransformer() | log(1 + y) with automatic shift for negative values | Yes |
BoxCoxTransformer() | Optimal Box-Cox lambda estimation via MLE | Yes |
Differencer(d=1) | d-th order differencing for stationarity | Yes |
Deseasonalizer(period=7) | Remove seasonal component by period averaging | Yes |
Detrend() | Remove linear trend | Yes |
OutlierClipper(factor=3.0) | IQR-based outlier clipping | No |
MissingValueImputer(method='linear') | Fill NaN via linear interpolation, mean, or forward fill | No |
Multi-step Preprocessing
Chain multiple transformers for complex data preparation
from vectrix.pipeline import (
ForecastPipeline, MissingValueImputer, OutlierClipper,
LogTransformer, Deseasonalizer, Scaler
)
pipe = ForecastPipeline([
('impute', MissingValueImputer(method='linear')),
('clip', OutlierClipper(factor=3.0)),
('log', LogTransformer()),
('deseason', Deseasonalizer(period=7)),
('scale', Scaler(method='zscore')),
('forecast', MyForecaster()),
]) Transform Without Forecasting
Use the pipeline as a pure preprocessing tool
pipe.fit(train_data)
transformed = pipe.transform(test_data)
original = pipe.inverseTransform(transformed) Inspecting the Pipeline
pipe.listSteps()
# ['impute', 'clip', 'log', 'deseason', 'scale', 'forecast']
scaler = pipe.getStep('scale')
print(scaler._mean, scaler._std)
pipe.getParams()
# {'clip__factor': 3.0, 'scale__method': 'zscore', ...} Scaler Options
Z-score (default)
Scaler(method='zscore') Centers to mean=0, std=1. Best for general-purpose standardization.
MinMax
Scaler(method='minmax') Scales to [0, 1] range. Best when bounded output is needed.
Box-Cox Transform
Automatically finds the optimal lambda to normalize your data distribution
from vectrix.pipeline import BoxCoxTransformer
bc = BoxCoxTransformer() # auto-estimate lambda
bc = BoxCoxTransformer(lmbda=0.5) # fixed lambda (square root) Missing Value Strategies
MissingValueImputer(method='linear') # Linear interpolation (default)
MissingValueImputer(method='mean') # Replace with series mean
MissingValueImputer(method='ffill') # Forward fill