| """MacroLens — public unified API (v0.2). |
| |
| The 10-line workflow:: |
| |
| import macrolens as ml |
| |
| X_train, y_train, meta_train = ml.load("T1", "train", granularity="daily") |
| X_test, y_test, meta_test = ml.load("T1", "test") |
| |
| model = ml.methods.LightGBMRegressor(task="T1") |
| model.fit(X_train, y_train, seed=42) |
| y_pred = model.predict(X_test) |
| |
| metrics = ml.score("T1", y_test, y_pred, |
| cluster_keys=meta_test["ticker"].values) |
| print(metrics["mse"].value, metrics["mse"].ci_lo, metrics["mse"].ci_hi) |
| |
| Public surface |
| -------------- |
| |
| * :func:`load` — sklearn-style ``(X, y, meta)`` data layer. |
| * :func:`score` / :func:`compare_methods` — eval layer. |
| * :func:`info` / :func:`features` — benchmark metadata. |
| * :func:`list_methods` — registered method names (filterable by family / task). |
| * :data:`methods` — sub-namespace; ``ml.methods.<ClassName>(task=...)``. |
| * :class:`LoadedData`, :class:`MetricValue`, :class:`RunRecord` — types. |
| |
| Legacy v0.1 entry points (``load_tsf``, ``to_arrays``, ``evaluate``, |
| ``ask_lumina``, ...) remain importable during the v0.1 → v0.2 transition; |
| they will be removed in Phase 7. |
| """ |
|
|
| from __future__ import annotations |
|
|
| |
| from . import methods |
| from ._types import LoadedData, MetricValue, RunRecord |
| from .data import load |
| from .eval import compare_methods, score |
| from .meta import BENCHMARK_NAME, __version__, features, info |
| from .methods import ALL_METHODS, list_methods |
|
|
|
|
| |
| |
| |
| |
| |
| def _import_legacy() -> dict[str, object]: |
| out: dict[str, object] = {} |
| try: |
| from ._evaluate import evaluate, format_submission |
| out["evaluate"] = evaluate |
| out["format_submission"] = format_submission |
| except Exception: |
| pass |
| try: |
| from ._fast import TSFTorchDataset, load_torch, to_arrays |
| out["TSFTorchDataset"] = TSFTorchDataset |
| out["load_torch"] = load_torch |
| out["to_arrays"] = to_arrays |
| |
| |
| from ._fast import features as _legacy_features |
| out["_legacy_features"] = _legacy_features |
| except Exception: |
| pass |
| try: |
| from ._loaders import load_panel, load_scenarios, load_task, load_tsf |
| out["load_panel"] = load_panel |
| out["load_scenarios"] = load_scenarios |
| out["load_task"] = load_task |
| out["load_tsf"] = load_tsf |
| except Exception: |
| pass |
| try: |
| from ._meta import BENCHMARK_VERSION |
| out["BENCHMARK_VERSION"] = BENCHMARK_VERSION |
| except Exception: |
| pass |
| try: |
| from ._types import ( |
| BenchmarkInfo, |
| GenerationMetrics, |
| REValuationMetrics, |
| ScenarioMetrics, |
| TaskSample, |
| TSFMetrics, |
| TSFSample, |
| ValuationMetrics, |
| ) |
| out["BenchmarkInfo"] = BenchmarkInfo |
| out["GenerationMetrics"] = GenerationMetrics |
| out["REValuationMetrics"] = REValuationMetrics |
| out["ScenarioMetrics"] = ScenarioMetrics |
| out["TaskSample"] = TaskSample |
| out["TSFMetrics"] = TSFMetrics |
| out["TSFSample"] = TSFSample |
| out["ValuationMetrics"] = ValuationMetrics |
| except Exception: |
| pass |
| return out |
|
|
|
|
| _LEGACY = _import_legacy() |
|
|
|
|
| def __getattr__(name: str): |
| """Resolve legacy attributes lazily (and ``ask_lumina`` even more so).""" |
| if name in _LEGACY: |
| return _LEGACY[name] |
| if name == "ask_lumina": |
| |
| |
| |
| from ..agents.lumina import ask as ask_lumina |
| return ask_lumina |
| if name == "lakehouse": |
| def _lakehouse(tag: str = "macrolens-v1.0"): |
| from ..lakehouse import Client |
| return Client.from_release(tag) |
| return _lakehouse |
| raise AttributeError(f"module 'macrolens' has no attribute {name!r}") |
|
|
|
|
| __all__ = [ |
| |
| "load", |
| "score", |
| "compare_methods", |
| "info", |
| "features", |
| "list_methods", |
| "methods", |
| "ALL_METHODS", |
| "LoadedData", |
| "MetricValue", |
| "RunRecord", |
| "BENCHMARK_NAME", |
| "__version__", |
| |
| "evaluate", |
| "format_submission", |
| "TSFTorchDataset", |
| "load_torch", |
| "to_arrays", |
| "load_panel", |
| "load_scenarios", |
| "load_task", |
| "load_tsf", |
| "ask_lumina", |
| "lakehouse", |
| "BENCHMARK_VERSION", |
| "BenchmarkInfo", |
| "GenerationMetrics", |
| "REValuationMetrics", |
| "ScenarioMetrics", |
| "TaskSample", |
| "TSFMetrics", |
| "TSFSample", |
| "ValuationMetrics", |
| ] |
|
|