π-features for ML
Physics is scale-free. A model built on dimensionless features generalises across scales it never saw in training; a model on raw dimensional features has to relearn the scaling and fails to extrapolate. pifeatures turns dimensional analysis into a one-line, scikit-learn-compatible preprocessing step. It is a standalone, deliberately public library (standard dimensional analysis) that installs on its own.
The value: cross-scale extrapolation
| Approach | Out-of-scale relative error |
|---|---|
| raw dimensional features | ~58% |
| PiRegressor (dimensionless) | ~0% |
Same model, same split — the raw-feature model never saw those magnitudes and can't rescale; the dimensionless model doesn't need to.
Quickstart
pip install pifeatures
from pifeatures import PiRegressor, U from sklearn.ensemble import RandomForestRegressor feature_units = [U(L=1), U(L=1, T=-2), U()] # length, gravity, dimensionless amplitude target_units = U(T=1) # period (time) model = PiRegressor(RandomForestRegressor(), feature_units, target_units).fit(X, y) model.predict(X_new_scales) # extrapolates across scales
Honest scope
- Inputs must be strictly positive (power-law groups use fractional exponents).
- The π reduction is exact and depends only on the units, not the data — it never overfits and adds no train-time cost. It captures scale structure; it does not replace learning the residual form.
- The same machinery is a data-quality check: mislabelling a column's units breaks the dimensionless groups, which surfaces the error.