{"id":21879,"library":"river","title":"River","description":"River is a Python library for online machine learning, stream processing, and incremental learning. It provides a comprehensive set of estimators, transformers, and metrics that process data one sample at a time, with built-in drift detection and model evaluation. Current version 0.24.2, released irregularly (several releases per year).","status":"active","version":"0.24.2","language":"python","source_language":"en","source_url":"https://github.com/online-ml/river","tags":["online-machine-learning","streaming","incremental-learning","drift-detection"],"install":[{"cmd":"pip install river","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Core numerical arrays","package":"numpy","optional":false},{"reason":"DataFrame conversion and utilities","package":"pandas","optional":true},{"reason":"Optimization and linear algebra","package":"scipy","optional":true}],"imports":[{"note":"The top-level 'river' submodules are lazy-loaded; accessing via dotted import may fail on first import.","wrong":"import river.metrics","symbol":"metrics","correct":"from river import metrics"},{"note":"While this works, the recommended pattern is to import the module and then access the class.","wrong":"from river.linear_model import LinearRegression","symbol":"linear_model.LinearRegression","correct":"from river import linear_model"}],"quickstart":{"code":"import os\nfrom river import stream, linear_model, metrics, preprocessing\n\n# Simulate a stream of data (dicts)\nX_y = [\n    ({'a': 1, 'b': 2}, 3.0),\n    ({'a': 4, 'b': 5}, 9.0),\n    ({'a': 7, 'b': 8}, 15.0),\n]\n\nmodel = preprocessing.StandardScaler() | linear_model.LinearRegression()\nmetric = metrics.MAE()\n\nfor x, y in stream.iter_array(X_y):  # stream.iter_array expects tuples (x_dict, y)\n    y_pred = model.predict_one(x)\n    if y_pred is not None:\n        metric.update(y, y_pred)\n    model.learn_one(x, y)\n\nprint(f'MAE: {metric.get():.4f}')","lang":"python","description":"Basic online learning with a pipeline and metric."},"warnings":[{"fix":"Upgrade Python to 3.11 or later.","message":"River 0.20.0 dropped Python 3.10 support; Python >=3.11 is required.","severity":"breaking","affected_versions":">=0.20.0"},{"fix":"Use estimator-specific SGD parameters or import `optim` from river if available (check docs).","message":"River 0.21.0 removed the `optim` module; optimizers are now part of individual estimators or the `optim` package was integrated.","severity":"breaking","affected_versions":">=0.21.0"},{"fix":"Replace `stream.iter_pandas(df, y)` with `stream.iter_array(df.to_dict('records'), df[y].values)`.","message":"`stream.iter_pandas` is deprecated in 0.24.0; use `stream.iter_array` or `stream.iter_dict` instead.","severity":"deprecated","affected_versions":">=0.24.0"},{"fix":"Always check `y_pred is not None` before using it, or use a warm-up sample.","message":"Many estimators require `predict_one` after `learn_one` before first predict, else return None. Forgetting this leads to missing predictions.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from river import metrics` instead of `import river.metrics`.","cause":"Trying to import a submodule before the parent module is fully loaded; lazy loading causes this.","error":"ModuleNotFoundError: No module named 'river.metrics'"},{"fix":"Ensure the model is a callable estimator; check pipeline composition.","cause":"Model not instantiated correctly, or pipeline returned None for step.","error":"AttributeError: 'NoneType' object has no attribute 'predict_one'"},{"fix":"Ensure each sample is a dict with matching keys and values are numeric.","cause":"Mismatched dimensions or data type in streaming examples.","error":"ValueError: could not broadcast input array from shape (X,) into shape (Y,)"},{"fix":"Always call `model.learn_one(x, y)` at least once before prediction.","cause":"Called `predict_one` before `learn_one` on models that require training first.","error":"RuntimeError: This model has not been trained yet"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}