--- phase: 11 phase_slug: predictv3 created: 2026-05-01 --- # Phase 11: predictV3算法优化 - Validation Strategy ## Overview 本阶段为算法优化,验证重点在于: 1. 新增指标计算准确性(NDCG、MRR、置信度) 2. 二阶马尔可夫转移矩阵构建正确性 3. 权重优化结果有效性 4. 回测命中率提升验证 ## Test Framework | Property | Value | |----------|-------| | Framework | PHPUnit (ThinkPHP内置) | | Config file | 无独立配置,通过 `php think unit` 运行 | | Quick run command | `php think unit --filter HistoryTest` | | Full suite command | `php think unit` | ## Phase Requirements → Test Map | Req ID | Behavior | Test Type | Automated Command | File Exists? | |--------|----------|-----------|-------------------|-------------| | PRED-01 | 置信度计算准确性 | unit | `php think unit --filter testConfidenceCalculation` | ❌ Wave 0 | | PRED-02 | NDCG计算准确性 | unit | `php think unit --filter testNDCGCalculation` | ❌ Wave 0 | | PRED-03 | 二阶马尔可夫转移矩阵构建 | unit | `php think unit --filter testTransitionMatrix2ndOrder` | ❌ Wave 0 | | PRED-04 | 权重优化收敛性 | unit | `php think unit --filter testWeightOptimization` | ❌ Wave 0 | | PRED-05 | 回测结果完整性 | unit | `php think unit --filter testBacktestV3Extended` | ❌ Wave 0 | ## Sampling Rate - **Per task commit:** 快速单元测试覆盖核心方法 - **Per wave merge:** 回测验证使用真实历史数据 - **Phase gate:** 全量回测(100期)验证整体命中率提升 ## Wave 0 Gaps - [ ] `tests/HistoryTest.php` — 核心预测方法单元测试 - [ ] `tests/ConfidenceTest.php` — 置信度计算测试 - [ ] `tests/BacktestMetricsTest.php` — NDCG、MRR等指标计算测试 - [ ] 共享fixtures: 历史数据模拟生成器 ## Validation Dimensions ### Dimension 8: Nyquist Test Coverage **Target:** 每个 PLAN.md 至少有一个可验证的测试命令 | Plan | Primary Test | Coverage | |------|--------------|----------| | 11-01 | testBacktestV3Extended | NDCG/MRR 计算准确性 | | 11-02 | testConfidenceCalculation | 置信度计算准确性 | | 11-03 | 手动 UI 验证 | 前端展示正确性 | | 11-04 | testWeightOptimization | 权重优化收敛性 | | 11-05 | testTransitionMatrix2ndOrder | 二阶马尔可夫正确性 | ### Dimension 9: Integration Verification **End-to-End Flow:** 1. 后端 `getPredictionV3()` 返回完整数据结构(predictions + confidence + backtest) 2. 前端 `renderPredict()` 正确渲染所有新增指标 3. 回测命中率可量化对比(V2 vs V3) **Verification Command:** ```bash # 验证后端接口返回结构完整性 curl -s "http://localhost/history/predictV3?periods=100" | jq '.data | keys' # 期望输出包含: predictions, confidence, backtest, analysis # 验证 NDCG/MRR 存在 curl -s "http://localhost/history/predictV3?periods=100" | jq '.data.backtest | keys' # 期望输出包含: hit_rate, avg_rank, ndcg_5, mrr, hit_distribution ``` ## Acceptance Criteria ### Phase Gate - [ ] NDCG@5 计算准确(单元测试通过) - [ ] MRR 计算准确(单元测试通过) - [ ] 置信度阈值正确(>=70%高、50-70%中、<50%低) - [ ] 二阶马尔可夫在数据充足时启用 - [ ] 前端展示包含所有新增指标 - [ ] 回测命中率有提升(相比 V2) --- *Phase: 11-predictv3* *Validation strategy created: 2026-05-01*