{"id":8612,"library":"runstats","title":"runstats","description":"RunStats is an Apache2 licensed Python module for computing online statistics and linear regression in a single pass. It is designed for efficiently processing large data streams or generators where previous values are not retained, making it suitable for long-running systems. The library, currently at version 2.0.0, is actively maintained and provides numerically stable calculations for various statistical measures and regression coefficients. [1, 2, 3]","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/grantjenks/python-runstats","tags":["statistics","online algorithms","regression","stream processing","numerical stability","data science"],"install":[{"cmd":"pip install runstats","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"symbol":"Statistics","correct":"from runstats import Statistics"},{"symbol":"Regression","correct":"from runstats import Regression"},{"symbol":"ExponentialStatistics","correct":"from runstats import ExponentialStatistics"}],"quickstart":{"code":"import random\nfrom runstats import Statistics, Regression\n\n# --- Statistics Example ---\nstats = Statistics()\nfor _ in range(100):\n    stats.push(random.random() * 100)\n\nprint(f\"Statistics Count: {len(stats)}\")\nprint(f\"Statistics Mean: {stats.mean():.2f}\")\nprint(f\"Statistics Std Dev: {stats.stddev():.2f}\")\nprint(f\"Statistics Min: {stats.minimum():.2f}\")\nprint(f\"Statistics Max: {stats.maximum():.2f}\")\n\n# --- Regression Example ---\nregr = Regression()\ndef linear_noisy_func(x_coord):\n    alpha, beta = 1.5, 5.0\n    noise = (2 * (random.random() - 0.5))\n    return alpha * x_coord + beta + noise\n\nfor i in range(100):\n    x_val = i * 0.1\n    y_val = linear_noisy_func(x_val)\n    regr.push(x_val, y_val)\n\nprint(f\"\\nRegression Count: {len(regr)}\")\nprint(f\"Regression Slope: {regr.slope():.2f}\")\nprint(f\"Regression Intercept: {regr.intercept():.2f}\")\nprint(f\"Regression Correlation: {regr.correlation():.2f}\")","lang":"python","description":"This quickstart demonstrates how to use the `Statistics` class to compute running statistics like mean, standard deviation, min, and max, and the `Regression` class to calculate slope, intercept, and correlation for a stream of (x, y) pairs. Values are added one by one using the `push` method. [2]"},"warnings":[{"fix":"Ensure Cython is installed (`pip install Cython`) before installing `runstats`, or check the installation logs for Cython compilation success.","message":"The `runstats` library includes an optional Cython-optimized extension for significant performance improvements (20-40x faster) over the pure-Python version. If Cython is not installed or the extension fails to build, the library will silently fall back to the slower pure-Python implementation. Users should verify installation to ensure optimal performance. [1, 3, 4]","severity":"gotcha","affected_versions":"2.0.0 and earlier"},{"fix":"Do not use `len()` on `ExponentialStatistics` objects. If you need to track the number of pushes, maintain a separate counter.","message":"The `ExponentialStatistics` class does not support the `len()` method, unlike `Statistics` and `Regression` objects. Attempting to call `len()` on an `ExponentialStatistics` instance will raise a `TypeError`. This is by design, as exponential statistics decay older values and do not represent a fixed count. [4]","severity":"gotcha","affected_versions":"All versions supporting ExponentialStatistics"},{"fix":"Be mindful of the order of `ExponentialStatistics` objects during combination to control the resulting decay rate. If specific weighting or a new decay rate is desired, consider creating a new `ExponentialStatistics` object and manually pushing combined values or explicitly setting the decay rate if the API allows.","message":"When combining `ExponentialStatistics` objects using the `+` operator, the resulting object's decay rate will be inherited from the leftmost `ExponentialStatistics` object in the operation. This behavior can be unexpected if different decay rates are involved. [4]","severity":"gotcha","affected_versions":"All versions supporting ExponentialStatistics"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install runstats`.","cause":"The `runstats` library has not been installed or is not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'runstats'"},{"fix":"Ensure you are using the correct class for the desired calculation. Use `Regression` for linear regression attributes (`slope`, `intercept`, `correlation`) and `Statistics` for basic descriptive statistics (`mean`, `stddev`, `minimum`, etc.).","cause":"Attempting to access a method or attribute specific to the `Regression` class (e.g., `slope`, `intercept`, `correlation`) on a `Statistics` object, or vice-versa.","error":"AttributeError: 'Statistics' object has no attribute 'slope'"},{"fix":"The `ExponentialStatistics` class does not track a fixed count due to its decaying nature. If a count of operations is needed, implement a manual counter alongside the `ExponentialStatistics` object.","cause":"Attempting to retrieve the count of items in an `ExponentialStatistics` object using `len()`, which is not supported.","error":"TypeError: object of type 'ExponentialStatistics' has no len()"}]}