mlforecast. We train a model on one domain (M4 Monthly
Macro series) and then generate calibrated prediction intervals for
a different domain (M4 Monthly Finance series) ā without retraining
the model.
Why transfer?
Standard conformal prediction intervals are calibrated on the same distribution as training data. When you apply a pretrained model to new, unseen series from a potentially different domain, the source conformity scores may be miscalibrated for the target domain. Transfer conformal methods attempt to correct for this shift using different strategies:| Method | Strategy | Needs CV on target? |
|---|---|---|
recalibrate | Re-run cross-validation on target data | Yes |
scale_aligned | Rescale source errors by target/source scale ratio (from y history) | No |
error_scaled | Rescale source errors by target/source prediction error ratio | Yes |
weighted_conformal | Reweight source errors via density-ratio estimation (covariate shift) | No |
scale_aligned_weighted | Combine scale alignment with density-ratio weighting | No |
Setup
Load M4 Monthly Data
The M4 Monthly dataset contains 48,000 monthly time series across 6 categories. We use it to create a cross-domain transfer scenario:- Source domain:
Macrocategory ā macroeconomic time series - Target domain:
Financecategory ā financial time series
Create Source and Target Domains
Explore the Domains
Letās visualize a few series from each domain to get a sense of the distribution shift.
Fit MLForecast on Source Domain
Feature engineering for cross-domain transfer
Because the model is trained on one domain and applied to another, the features must be scale-invariant. Tree models cannot extrapolate: if a Finance series has level changes larger than anything seen in the Macro training data, its predictions get clamped to the training range, producing large, skewed errors that no conformal correction can fully repair. We therefore model log-returns instead of raw differences:GlobalSklearnTransformer(FunctionTransformer(np.log1p, np.expm1))followed byDifferences([1])ā the model sees relative changes, which live on a comparable scale in both domains. Back-transformed intervals scale multiplicatively with each seriesā level.- Volatility and trend features (
RollingStd,ExponentiallyWeightedMean,SeasonalRollingMean) ā these sharpen the point forecasts and, importantly, give the density-ratio estimator meaningful covariates: on the raw scale, lag features mostly encode the scale difference between domains rather than the dynamics.
Prediction interval configuration
We fit on Macro series usingPredictionIntervals with: -
method='weighted_conformal_error' ā stores lag features in the
conformity score dataframe, enabling density-ratio estimation (DRE) for
the weighted_conformal and scale_aligned_weighted transfer
methods. - scale_estimator='mad' ā stores per-series scale estimates
(MAD of first differences), enabling the scale_aligned and
scale_aligned_weighted transfer methods.
Using this single fit configuration unlocks all five transfer
methods.
Evaluate Transfer Methods
For each transfer method, we callmlf.predict() with: -
new_df=target_train ā the target domain training history (Finance
series) - level=[80, 90, 95] ā the requested coverage levels -
transfer_conformal=method ā which transfer strategy to use
We then merge predictions with target_test and compute the empirical
coverage at each level.
Results: Nominal vs Empirical Coverage
A well-calibrated method should have empirical coverage close to nominal. We show the results as a summary table and a bar chart.
Coverage Gap Analysis
Interval Width Analysis
Beyond coverage, we also care about interval sharpness. Narrower intervals (lower width) are better, as long as coverage is maintained.
Visual Inspection: Interval Examples
Letās visually inspect the intervals produced by each method for a few target-domain series.
Summary
The table and charts above show how each transfer method calibrates prediction intervals when moving from a Macro source domain to a Finance target domain in M4 Monthly data. Key takeaways:- Feature engineering matters as much as the transfer method.
Modeling log-returns (
log1p+Differences([1])) instead of raw differences makes the features scale-invariant across domains, removes the systematic point-forecast bias, and is what allows the weighted methods to reach near-nominal coverage. With raw differences, every method under-covers by several percentage points. recalibrateruns cross-validation on the target data ā it tends to be the most directly calibrated but requires running CV (computationally equivalent to retraining).scale_aligneduses the scale of the y signal (MAD of differences) to align source residuals ā zero-shot, no CV needed.error_scaledruns CV on the target data to estimate prediction error magnitude ā a middle ground between full recalibration and scale alignment.weighted_conformaluses density-ratio estimation to reweight source conformity scores ā handles covariate shift without needing target labels during calibration.scale_aligned_weightedcombines scale alignment with DRE weighting ā the most sophisticated zero-shot method.- The residual under-coverage of the non-weighted methods comes from pooling conformity scores across heterogeneous series: pooled intervals are too wide for calm series and too narrow for volatile ones. This is precisely the failure mode the weighted/scale-aligned variants are designed to mitigate.
recalibrate or error_scaled - If you need zero-shot
transfer: scale_aligned or scale_aligned_weighted - If covariate
shift is the main concern: weighted_conformal or
scale_aligned_weighted
