From 3bb31f95de3db2f2a8c9da518c7006e5399c04ea Mon Sep 17 00:00:00 2001 From: guzhujushi Date: Sat, 10 Oct 2026 14:01:56 +0800 Subject: [PATCH] =?UTF-8?q?chore(models):=20=E5=BC=80=E5=B7=A5=E5=89=8D?= =?UTF-8?q?=E6=B8=85=E7=90=86=20+=20=E5=8E=BB=E6=8E=89=20mm1=20=E7=9A=84?= =?UTF-8?q?=E6=AE=8B=E7=95=99=E6=B3=A8=E9=87=8A=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tests/test_models.py:模块级 pytestmark -> 逐条 @pytest.mark.skip(决策 26); 该文件的 5 条测试仍然全跳过,只是形式上与其它测试文件对齐了。 - models/metrics.py:rmse / mae / r2_score 的注释 TODO(L0) -> TODO(L1) (roadmap 的 L0 12 项里没有这三个指标,它们属于 L1 的 models 清单)。 - simulate.py:用户去掉 # 4. 封装返回 这行残留序号注释(无代码变化)。 校验:pytest 204 passed / 28 skipped;ruff 0;pyright 0 --- src/mcm_toolkit/models/metrics.py | 6 +++--- src/mcm_toolkit/solve/simulate.py | 1 - tests/test_models.py | 7 ++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mcm_toolkit/models/metrics.py b/src/mcm_toolkit/models/metrics.py index 17159f2..334a26a 100644 --- a/src/mcm_toolkit/models/metrics.py +++ b/src/mcm_toolkit/models/metrics.py @@ -24,13 +24,13 @@ __all__ = [ def rmse(y_true: Any, y_pred: Any) -> float: """均方根误差。与 y 同量纲,最常用。""" - # TODO(L0) + # TODO(L1) raise NotImplementedError def mae(y_true: Any, y_pred: Any) -> float: """平均绝对误差。对离群值比 RMSE 稳健。""" - # TODO(L0) + # TODO(L1) raise NotImplementedError @@ -48,7 +48,7 @@ def smape(y_true: Any, y_pred: Any) -> float: def r2_score(y_true: Any, y_pred: Any) -> float: """决定系数 R²。注意:加变量一定会升高,跨模型比较要看 adjusted_r2。""" - # TODO(L0) + # TODO(L1) raise NotImplementedError diff --git a/src/mcm_toolkit/solve/simulate.py b/src/mcm_toolkit/solve/simulate.py index 810b76d..9aa6727 100644 --- a/src/mcm_toolkit/solve/simulate.py +++ b/src/mcm_toolkit/solve/simulate.py @@ -772,7 +772,6 @@ def mm1_metrics(arrival_rate: float, service_rate: float) -> Any: W = 1.0 / (service_rate - arrival_rate) # 平均逗留时间 Wq = W - 1.0 / service_rate # 平均等待时间 - # 4. 封装返回 metrics = { "rho": float(rho), "L": float(L), diff --git a/tests/test_models.py b/tests/test_models.py index 56acd5f..2bd5814 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -5,9 +5,10 @@ from __future__ import annotations import numpy as np import pytest -pytestmark = pytest.mark.skip(reason="未实现:见 docs/03-roadmap.md L1") +_NOT_IMPLEMENTED = "未实现:见 docs/03-roadmap.md L1" +@pytest.mark.skip(reason=_NOT_IMPLEMENTED) def test_fit_linear_recovers_known_coefficients(linear_data): """真值 y = 2x + 1,拟合系数应在 1% 内。""" from mcm_toolkit.models import fit_linear @@ -18,6 +19,7 @@ def test_fit_linear_recovers_known_coefficients(linear_data): assert np.isclose(r.params["intercept"], 1.0, atol=0.05) +@pytest.mark.skip(reason=_NOT_IMPLEMENTED) def test_fit_polynomial_matches_numpy(linear_data): from mcm_toolkit.models import fit_polynomial @@ -26,6 +28,7 @@ def test_fit_polynomial_matches_numpy(linear_data): assert np.allclose(r.params["coef"], np.polyfit(x, y, 2), rtol=1e-6) +@pytest.mark.skip(reason=_NOT_IMPLEMENTED) def test_metrics_known_values(): from mcm_toolkit.models import mae, r2_score, rmse @@ -36,6 +39,7 @@ def test_metrics_known_values(): assert r2_score(y_true, y_pred) < 1.0 +@pytest.mark.skip(reason=_NOT_IMPLEMENTED) def test_r2_is_one_for_perfect_fit(): from mcm_toolkit.models import r2_score @@ -43,6 +47,7 @@ def test_r2_is_one_for_perfect_fit(): assert np.isclose(r2_score(y, y), 1.0) +@pytest.mark.skip(reason=_NOT_IMPLEMENTED) def test_compare_models_returns_table_sorted_by_first_metric(linear_data): from mcm_toolkit.models import compare_models, fit_linear, fit_polynomial