Properscoring

raw JSON →
0.1 verified Fri May 01 auth: no python maintenance

A Python library for evaluating probabilistic forecasts using proper scoring rules. Version 0.1 is the only release; the project is in maintenance mode with no recent updates. It provides implementations of the Continuous Ranked Probability Score (CRPS), Brier score, and related metrics for forecast verification.

pip install properscoring
error ImportError: cannot import name 'crps_ensemble'
cause Older version or mis-installation. The import name is correct; ensure properscoring is installed.
fix
Run pip install properscoring and verify import with import properscoring.
error ValueError: operands could not be broadcast together with shapes ...
cause Input arrays of incompatible shapes to `crps_ensemble`.
fix
Reshape: observations should be (n,) or (1, n), ensemble should be (m, n). Use np.atleast_2d(obs) and check ensemble shape.
error TypeError: 'numpy.float64' object is not callable
cause Accidentally shadowed the `crps_ensemble` function with a variable (e.g., `crps_ensemble = ...`).
fix
Restart the interpreter and avoid using the function name as a variable.
gotcha Input arrays for `crps_ensemble` must be 1D or 2D with observations as first argument and ensemble as second. If dimensions are mismatched (e.g., shapes (n,) vs (m, n) transposed), you may get incorrect results or broadcasting issues.
fix Ensure observations have shape (n,) or (1, n) and ensemble has shape (n_ens, n); use `ensemble.T` if needed.
gotcha The library has no official support for Python 3.10+ (no wheels for recent Python versions). Installing on Python 3.10 or 3.11 requires building from source, which may fail if compilation tools are missing.
fix Use Python 3.8 or 3.9 for guaranteed compatibility, or install via conda-forge: `conda install -c conda-forge properscoring`.
breaking In v0.1, `crps_ensemble` does not handle NaN values; passing arrays with NaN can cause silent errors or incorrect results.
fix Manually remove or impute NaN values before calling the function.

Compute the Continuous Ranked Probability Score (CRPS) for ensemble forecasts against observations.

import numpy as np
from properscoring import crps_ensemble

# Ensemble forecasts (10 members)
ensemble = np.random.randn(10, 100)
# Observations
observations = np.random.randn(100)

# Calculate CRPS for each observation
crps = crps_ensemble(observations, ensemble)
print(crps.mean())