返回技能列表

run-ab-test-models

pjt222
更新于 2 days ago
5 次查看
17
2
17
在 GitHub 上查看
测试aitestingdesigndata

关于

This skill enables A/B testing for ML models in production through traffic splitting and statistical significance testing. It supports canary/shadow deployments to measure performance differences between model versions before full rollout. Use it when validating new models, comparing algorithms, or meeting gradual rollout requirements.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/run-ab-test-models

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

A/Bテストモデルの実行

See Extended Examples for complete configuration files and templates.

Execute controlled experiments comparing model versions using traffic splitting and statistical analysis.

使用タイミング

  • Deploying new model version and want to validate improvement before full rollout
  • Comparing multiple candidate models trained with different algorithms or features
  • Testing impact of hyperparameter changes on business metrics
  • Need to measure model performance in production without risking full traffic
  • Regulatory requirements for gradual rollout (e.g., medical ML systems)
  • Evaluating cost-performance tradeoffs between model sizes

入力

  • 必須: Champion model (current production version)
  • 必須: Challenger model(s) (new version to test)
  • 必須: Traffic allocation percentage (e.g., 5% to challenger)
  • 必須: Success metrics (business and ML metrics)
  • 必須: Minimum sample size or test duration
  • 任意: Guardrail metrics (latency, error rate thresholds)
  • 任意: User segments for stratified testing

手順

ステップ1: Design Experiment

Define test parameters, success criteria, and statistical requirements.

# ab_test/experiment_config.py
from dataclasses import dataclass
from typing import List, Dict
import numpy as np
from scipy.stats import norm


@dataclass
# ... (see EXAMPLES.md for complete implementation)

期待結果: Experiment configuration with statistically sound sample size calculation, typically 5-10k samples per variant for 5-10% MDE.

失敗時: If required sample size too large, increase traffic allocation, extend test duration, or accept larger MDE; verify baseline metric estimate is accurate; consider sequential testing for continuous monitoring.

ステップ2: Implement Traffic Splitting

Set up routing logic to randomly assign requests to models.

# ab_test/traffic_router.py
import hashlib
import random
from typing import Dict, Optional
from dataclasses import dataclass
import logging

logger = logging.getLogger(__name__)
# ... (see EXAMPLES.md for complete implementation)

期待結果: Consistent user-to-variant assignment, accurate traffic split matching configured percentages, all assignments logged for analysis.

失敗時: Verify hash function produces uniform distribution (test with 10k user IDs), check that user_id is stable across requests (not session_id), ensure logs capture all prediction events, validate traffic split in first 1000 requests.

ステップ3: Implement Shadow Deployment (Optional)

Run challenger model in parallel without affecting users (shadow mode).

# ab_test/shadow_deployment.py
import asyncio
from typing import Dict, Any
import logging
from concurrent.futures import ThreadPoolExecutor
import time

logger = logging.getLogger(__name__)
# ... (see EXAMPLES.md for complete implementation)

期待結果: Champion predictions served with normal latency, challenger predictions logged asynchronously without blocking, prediction differences captured for analysis.

失敗時: Set challenger timeout < champion SLA to avoid blocking, handle challenger errors gracefully without affecting champion, monitor memory usage (two models loaded), consider sampling (log only 10% of shadow predictions).

ステップ4: Collect and Analyze Metrics

Gather experiment data and perform statistical tests.

# ab_test/analysis.py
import pandas as pd
import numpy as np
from scipy import stats
from typing import Dict, Tuple
import logging

logger = logging.getLogger(__name__)
# ... (see EXAMPLES.md for complete implementation)

期待結果: Statistical test results with p-values, confidence intervals, and clear decision (rollout/keep/inconclusive), typically after 7-14 days or reaching sample size.

失敗時: Verify ground truth labels are available (may need delayed analysis), check for sample ratio mismatch (SRM) indicating assignment bugs, ensure sufficient sample size reached, look for novelty/primacy effects in early data, consider sequential testing if fixed-horizon test is too slow.

ステップ5: Monitor Guardrail Metrics

Continuously check that challenger doesn't violate safety thresholds.

# ab_test/guardrails.py
import pandas as pd
import logging
from typing import Dict, List

logger = logging.getLogger(__name__)


# ... (see EXAMPLES.md for complete implementation)

期待結果: Guardrail violations detected within 5-15 minutes, automated experiment stop if critical thresholds breached (latency, errors), alerts sent to team.

失敗時: Verify guardrail thresholds are realistic (not too tight), ensure monitoring loop is running continuously, check that stop_experiment() function actually updates routing, test alert delivery channels.

ステップ6: Make Rollout Decision

Based on experiment results, decide whether to rollout challenger.

# ab_test/rollout_decision.py
import logging
from typing import Dict
from dataclasses import dataclass

logger = logging.getLogger(__name__)


# ... (see EXAMPLES.md for complete implementation)

期待結果: Clear decision (full/gradual rollout, keep champion, or extend test) with justification and action items.

失敗時: If decision unclear, perform subgroup analysis (by user segment, time of day, device type), check for interaction effects, review business context (e.g., is 2% lift worth engineering cost?), consult with stakeholders.

バリデーション

  • Traffic split matches configured percentages (within 1%)
  • Same user always assigned to same variant (consistency check)
  • Sample size calculation produces reasonable numbers (5-50k per variant)
  • Statistical tests produce p-values consistent with manual calculation
  • Guardrail violations trigger alerts within 5 minutes
  • Shadow deployment shows <5% prediction divergence between models
  • Experiment reports include confidence intervals
  • Rollout decision documented with justification

よくある落とし穴

  • Sample ratio mismatch (SRM): If observed traffic split differs from configured (e.g., 95/5 becomes 92/8), indicates assignment bug; check hash function uniformity
  • Peeking: Checking results before reaching sample size inflates Type I error; use sequential testing or wait for pre-determined end date
  • Novelty effect: Users respond differently to new model initially; run for 2+ weeks to see steady-state behavior
  • Carryover effects: Previous variant exposure affects current behavior; use new users or sufficient washout period
  • Multiple testing: Testing many metrics increases false positive risk; correct with Bonferroni or focus on single primary metric
  • Insufficient power: Small traffic allocation may require months to detect realistic effects; balance statistical power with risk tolerance
  • Ignoring segments: Aggregate lift may hide negative impact on important user segments; perform subgroup analysis
  • Attribution errors: Ensure outcome metrics correctly attributed to model predictions (not other system changes)

関連スキル

  • deploy-ml-model-serving - Model deployment infrastructure and versioning
  • monitor-model-drift - Ongoing performance monitoring post-rollout

GitHub 仓库

pjt222/agent-almanac
路径: i18n/ja/skills/run-ab-test-models
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

evaluating-llms-harness

测试

该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。

查看技能

cloudflare-cron-triggers

测试

这个Claude Skill提供了关于Cloudflare Cron Triggers的完整知识库,用于通过cron表达式定时执行Workers。它支持配置周期性任务、维护作业和自动化工作流,并能处理常见的cron触发错误。开发者可以用它来设置定时任务、测试cron处理器,并集成Workflows和Green Compute功能。

查看技能

webapp-testing

测试

该Skill为开发者提供了基于Playwright的本地Web应用测试工具集,支持自动化测试前端功能、调试UI行为、捕获屏幕截图和查看浏览器日志。它包含管理服务器生命周期的辅助脚本,可直接作为黑盒工具运行而无需阅读源码。适用于需要快速验证本地Web应用界面和交互功能的开发场景。

查看技能

finishing-a-development-branch

测试

这个Skill用于开发分支完成后的集成决策,当代码实现完成且测试通过时,它会引导开发者选择合适的工作流。它首先验证测试状态,然后提供合并、创建PR或清理等结构化选项。核心价值在于确保代码质量的同时,标准化分支收尾流程。

查看技能