stemflow.calibration
Composable calibration maps, OOF estimators and spatial-temporal diagnostics. See local calibration and tuning.
Public choices
| Component | Purpose |
|---|---|
BetaCalibrator |
Fit an increasing binary probability map with an identity-centered ridge penalty. |
AffineCalibrator |
Calibrate regression point means. |
CrossValidatedCalibratedClassifier / Regressor |
Fit the map from out-of-fold scores and retain fold estimators. |
SpatioTemporalKFold |
Block by space/time and audit fold support, retries and fallback status. |
calibration_scores, calibration_bins |
Summarize held-out scores and bin counts/uncertainty references. |
calibration_by_group, stixel_calibration_diagnostics |
Diagnose supplied groups or actual fitted planar stixel geometry. |
plot_calibration_diagnostics |
Save multi-level diagnostics and stixel overlays from those tables. |
For SpatioTemporalKFold, n_splits controls folds independently of spatial/temporal block counts. min_pos/min_neg are feasibility thresholds for each training and validation fold, not statistical reliability guarantees. rare_policy="allow" reports a fallback; "raise" rejects insufficient support. Inspect fold_support_, support_sufficient_, status_ and trials_.
Generic wrappers use shuffled folds when cv is omitted. Supply the spatial-temporal splitter explicitly for blocked calibration. Intentional all-zero/all-one AdaSTEM stixels keep their dummy behavior. Local calibration and relative ECE do not establish exact conditional probabilities or copula accuracy; examine support, coverage, proper losses and floor sensitivity together.
Standalone probability and point-prediction calibration maps.
AffineCalibrator
Bases: BaseEstimator
Ridge correction of a regression point mean; not interval calibration.
Source code in stemflow/calibration/maps.py
BetaCalibrator
Bases: BaseEstimator
Increasing beta map, regularized toward the identity probability map.
Minimizes SUM weighted binary log loss plus
ridge / 2 * ((a - 1)**2 + (b - 1)**2 + c**2) for
sigmoid(a*log(p) - b*log(1-p) + c). Ridge strength therefore depends
on sample size and weight scale. The default matches the supplied pilot.
Source code in stemflow/calibration/maps.py
Composable OOF calibration estimators, usable inside or outside AdaSTEM.
ConstantBinaryClassifier
Bases: ClassifierMixin, BaseEstimator
Smoothed fold fallback, distinct from AdaSTEM's intentional dummy zeros.
Source code in stemflow/calibration/estimators.py
CrossValidatedCalibratedClassifier
Bases: ClassifierMixin, _CrossValidatedCalibration, BaseEstimator
Fit retained fold models and one map on pooled OOF probabilities.
Each fold probability is calibrated before averaging, matching the supplied
local-beta strategy. Inside AdaSTEM this is a separate map per stixel.
Calibrators follow fit(probability, y) / predict(probability).
Use an explicit SpatioTemporalKFold for within-stixel blocked calibration.
A fixed estimator requires no tuning; wrap it in SelfTuningClassifier only
when nested hyperparameter selection is wanted.
Source code in stemflow/calibration/estimators.py
CrossValidatedCalibratedRegressor
Bases: RegressorMixin, _CrossValidatedCalibration, BaseEstimator
OOF calibration of point means; supplies no prediction-interval guarantee.
Source code in stemflow/calibration/estimators.py
Audited spatial-temporal folds for local calibration and nested tuning.
InsufficientSplitError
SpatioTemporalKFold
Bases: BaseEstimator
Retry blocked folds, recording event support rather than hiding scarcity.
rare_policy='allow' retains the first nonempty blocked split when the
requested class support cannot be met. No random row split is substituted.
period folds circular-year copies onto their original seasonal day.
Spatial and temporal block counts are configurable, independently of
n_splits. They retain ST_KFold's linspace-cutpoint semantics and use
the observed range of the data passed to each split, without a buffer.
Source code in stemflow/calibration/cross_validation.py
Held-out diagnostics for final probabilities inside actual fitted stixels.
calibration_by_group(y, p, groups, n_bins=8, include_bins=True, common_bin_edges=None)
Score overlapping positional groups; units are not assumed independent.
Source code in stemflow/calibration/diagnostics.py
plot_calibration_diagnostics(diagnostics, output_path, max_curves=200)
Save overall/stixel diagnostics and transparent log-scale overlays.
Source code in stemflow/calibration/diagnostics.py
stixel_calibration_diagnostics(model, X, y, pred=None, n_bins=8, spatial_bin_width=5.0, temporal_bin_width=40.0, include_bins=True, support_min_events=20, support_min_samples=200)
Evaluate on caller-supplied held-out rows, using the fitted partition.
Returns overall, spatial, temporal, space-time and overlapping stixel scores. Group accuracy uses final ensemble probabilities, not in-sample fold scores. Relative ECE is floor-sensitive and accompanied by zero-event bin mass.