Views
No views yet
Source-code repository for thetime-anchorPython package. Looking for the ready-to-use model and its model card? See K-Iwa/time-anchor-modernbert-32m. This repository bundles the same checkpoint undermodels/so the code can be developed and tested self-contained.
| 📈 Quantile forecast | Probabilistic forecasts at any requested quantile levels |
| 🧭 Variable / time impact | Normalized contribution of every input variable at every time step |
| 📌 Anchor forecast | Forecasts conditioned on known future points you specify |

python -m pip install -e .1import pandas as pd
2from time_anchor import predict_time_anchor
3
4url = (
5 "https://archive-api.open-meteo.com/v1/archive"
6 "?latitude=35.69&longitude=139.69&start_date=2024-10-01&end_date=2024-12-31"
7 "&hourly=temperature_2m,relative_humidity_2m,surface_pressure,wind_speed_10m&format=csv"
8)
9weather = pd.read_csv(url, skiprows=3)
10temperature = weather.iloc[:, 1].astype("float32")
11
12result = predict_time_anchor(
13 "models/time-anchor-modernbert-32m",
14 target_context=temperature[:1440],
15 prediction_length=64,
16 quantile_levels=(0.1, 0.5, 0.9),
17)
18print(pd.DataFrame(result.forecast_rows))subfolder="models/time-anchor-modernbert-32m".
time_index, impact across all variables sums to 1.1result = predict_time_anchor(
2 "models/time-anchor-modernbert-32m",
3 target_context=temperature[:168],
4 explanatory_contexts=[weather.iloc[:168, i].astype("float32") for i in (2, 3, 4)],
5 gaf={"enabled": True, "topk_time_steps": 0},
6)
7print(pd.DataFrame(result.variable_impact_rows))
1url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
2passengers = pd.read_csv(url)["Passengers"].astype("float32")
3
4result = predict_time_anchor(
5 "models/time-anchor-modernbert-32m",
6 target_context=passengers[:-24],
7 prediction_length=24,
8 anchor={
9 "mode": "observed",
10 "positions": [4, 8, 12, 16, 20, 24],
11 "values": [396, 559, 405, 461, 606, 432],
12 },
13)
14print(pd.DataFrame(result.forecast_rows))positions are 1-based forecast horizon steps. Anchor forecasts use the target
history only; disable anchors when passing explanatory_contexts.1time-anchor-infer # forecast + impact on the bundled sample
2time-anchor-infer --no-impact # forecast only
3time-anchor-infer --no-impact --anchor-mode observed \
4 --anchor-positions 12,24,36 --anchor-values 0.2,0.4,0.1
5time-anchor-infer --checkpoint K-Iwa/time-anchor-modernbert-32m --input data.csvoutput/forecast.csv, output/variable_impact.csv, and
output/result.json. time-anchor-sine-test runs a sine-wave anchor evaluation
(requires pip install -e ".[examples]").src/time_anchor — model, pipeline, anchor samplers, and explainability codemodels/time-anchor-modernbert-32m — checkpoint and model cardexamples/sample_data.csv — small input file for smoke testsdocs/publishing.md — Hugging Face / PyPI release checklist1python -m pip install -e ".[dev]"
2python -m ruff check .
3python -m ruff format --check .
4python -m pytest