算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
run-ab-test-models【设计与创意】Design and execute A/B tests for ML models in production using traffic splitting, statistical significance testing, and canary/shadow deployment strategies. Measure performance differences and make data-driven decisions about model rollout. Use when validating a new model version before full rollout, comparing candidate models trained with different …
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
See Extended Examples for complete configuration files and templates.
Run controlled experiments comparing model versions with traffic split + statistical analysis.
Define test parameters, success criteria, statistical needs.
# 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)
Got: Experiment config with stat-sound sample size calc, typical 5-10k samples per variant for 5-10% MDE.
If fail: Sample too large? Up traffic allocation, extend duration, or accept larger MDE; verify baseline metric estimate; consider sequential testing.
Set up routing — 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)
Got: Consistent user-to-variant assignment, accurate traffic split matches configured %, all assignments logged.
If fail: Verify hash uniform (test 10k user IDs), check user_id stable across requests (not session_id), logs capture all predictions, validate split in first 1000 requests.
Run challenger 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)
Got: Champion served at normal latency, challenger logged async without blocking, prediction diffs captured.
If fail: Set challenger timeout < champion SLA, handle challenger errors gracefully, monitor memory (two models loaded), consider sampling (log 10% of shadow predictions).
Gather data, run 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)
Got: Stat test results with p-values, CIs, clear decision (rollout/keep/inconclusive), typical after 7-14 days or sample size.
If fail: Verify ground truth labels available (delayed analysis maybe), check sample ratio mismatch (SRM = assignment bugs), enough sample size, look for novelty/primacy effects in early data, consider sequential testing if fixed-horizon too slow.
Continuous check challenger does not 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)
Got: Guardrail violations detected within 5-15 min, auto stop if critical thresholds breached (latency, errors), alerts to team.
If fail: Verify thresholds realistic (not too tight), monitoring loop runs continuous, check stop_experiment() updates routing, test alert delivery.
From results, decide 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)
Got: Clear decision (full/gradual rollout, keep champion, extend test) with justification + action items.
If fail: Decision unclear? Subgroup analysis (segment, time, device), check interaction effects, review business context (2% lift worth eng cost?), consult stakeholders.
deploy-ml-model-serving - Model deployment infra, versioningmonitor-model-drift - Post-rollout monitoring