Skip to main content

RetrainOpt

Cost-aware retraining schedules for machine learning.

RetrainOpt helps you choose when to retrain and how much data to use, balancing model quality against training cost. Plan a schedule from historical data, or make retraining decisions as new data arrives.

Try the interactive demo to see how changing training costs and data drift changes a retraining schedule.

Demo preview on a synthetic timeline: cost comparison and an optimized schedule with two retraining steps using 100% and 75% of available data.

Based on Automated Retraining for Cost-Optimal ML by Jun Yang and Michael Mathioudakis (ECML PKDD 2026).

Install

Requires Python 3.10 or later. The core package has no external dependencies.

python -m pip install retrainopt

Optional integrations:

python -m pip install 'retrainopt[sklearn]'
python -m pip install 'retrainopt[torch]'
python -m pip install 'retrainopt[botorch]'

Offline quick start

from retrainopt import PlannerConfig, RetrainingPlanner
from retrainopt.adapters import ArrayTimelineAdapter, PrototypeModelAdapter

timeline = ArrayTimelineAdapter(
    train_blocks=[
        [((0.0,), 0), ((1.0,), 1)],
        [((0.0,), 1), ((1.0,), 0)],
    ],
    eval_blocks=[
        [((0.1,), 0), ((0.9,), 1)],
        [((0.1,), 1), ((0.9,), 0)],
    ],
)
config = PlannerConfig(
    n_choices=(1.0,),       # Full block; integer 1 would mean one sample.
    initial_loss=1.0,      # Explicit initial baseline; no bootstrap fit.
    time_cost_weight=0.0,  # Ignore wall-clock noise in this small example.
    loss_cost_weight=1.0,
)
result = RetrainingPlanner(timeline, PrototypeModelAdapter(), config).plan("exact")
print([decision.action.value for decision in result.decisions])
print(result.total_cost)
# ['retrain', 'retrain']
# 0.0

Each train block is the complete available dataset at that time; blocks are not accumulated automatically. The offline planner can inspect the entire timeline, including evaluation blocks. These are optimization inputs, so the selected plan's cost is not an independent future-performance estimate.

Offline planning methods

Method What it does
exact Measures every configured candidate and finds the minimum-cost schedule over that finite candidate set.
bayes, lightweight backend Uses a dependency-free nearest-neighbor heuristic to select candidates.
bayes, botorch backend Uses optional Gaussian-process surrogates for acquisition-guided search.

For bayes, the final schedule is reoptimized over all measured candidates. estimated_total_cost is its estimate before the final measurements, while total_cost is its measured cost. Approximate search does not guarantee the global optimum. See the algorithm guide for cost accounting and search budgets.

Online retraining

The Base and Learned policies use an initial period of historical data to guide later retraining decisions. Base derives a retraining interval and sample count from a historical plan. Learned fits a classifier for keep/retrain and a regressor for the retraining sample count; it requires the sklearn extra.

collect_online_training_data(..., history_steps=...) limits policy training to that period. OnlineController.step() then processes one deployment step at a time, using the current model's measured loss and executing the policy's decision. Supply the initial deployed model and its reference loss explicitly; policy training does not deploy a historical candidate model automatically. Current loss measurements require labels for the evaluation observations. Custom training-cost functions and pre-window model history are supported in historical tuning and deployment.

python examples/online_timeline.py
# Requires retrainopt[sklearn]:
python examples/learned_online_timeline.py

See Online retraining for the API, initialization choices and policy assumptions. Neither online strategy guarantees the globally optimal deployment schedule.

Documentation and examples

python examples/minimal_array_timeline.py
python examples/verify_exact_against_bruteforce.py
# After installing the corresponding extra:
python examples/sklearn_timeline.py
python examples/torch_timeline.py
python examples/botorch_timeline.py

License

RetrainOpt is licensed under the Apache License 2.0. Copyright (c) 2026 Jun Yang and Michael Mathioudakis.

Citation

If you use RetrainOpt in your research, please cite our paper in the ECML PKDD 2026 proceedings and report the software version you used. Citation metadata is available in CITATION.cff.

@inproceedings{yang2027automated,
  author = {Yang, Jun and Mathioudakis, Michael},
  title = {Automated Retraining for Cost-Optimal ML},
  booktitle = {Machine Learning and Knowledge Discovery in Databases. Research Track},
  year = {2027},
  series = {Lecture Notes in Computer Science},
  volume = {16941},
  pages = {231--249},
  publisher = {Springer Nature Switzerland},
  address = {Cham},
  doi = {10.1007/978-3-032-37654-1_14},
  url = {https://doi.org/10.1007/978-3-032-37654-1_14}
}

Metadata

Release files for retrainopt 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for retrainopt 0.4.2
File Size Uploaded
retrainopt-0.4.2.tar.gz 420.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for retrainopt 0.4.2
File Interpreter ABI Platform
retrainopt-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 468.8 kB

Release files / retrainopt-0.4.2.tar.gz

Download URL retrainopt-0.4.2.tar.gz
Size 420.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3003bc5ce8a14b05c843fc5422328475741c10607c2c79190743b19a5b19e08e
BLAKE2b-256 checksum
How to use checksums
f954038d1f9450c6c464f486e2d4c6c0ed37d856258022c90d7e95fd4e3b3d25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / retrainopt-0.4.2-py3-none-any.whl

Download URL retrainopt-0.4.2-py3-none-any.whl
Size 48.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83890e3e88dfa93f1432a0d617e85f1c06779cb38dc78b3b84ed7e97d6401c74
BLAKE2b-256 checksum
How to use checksums
562c4cdf013d02d3b010a73091f3ecd2c5b34d518c5b11abf4c91422a904b364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page