视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
ds-reproducible-research【文档与办公】"Implements reproducible research practices including code organization environment management, documentation, and experiment tracking"
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: ds-reproducible-research compatibility: opencode completeness: 95 content-types:
Comprehensive guide to reproducible research in machine learning and data science workflows.
Reproducible Research is a critical component of the machine learning workflow. This skill covers:
import os
import random
import logging
import numpy as np
import pandas as pd
from typing import Dict, Any
logger = logging.getLogger(__name__)
def setup_reproducible_environment(seed: int = 42) -> Dict[str, Any]:
"""
Configures deterministic behavior for Python, NumPy, and random modules.
Follows DRY principles by centralizing seed configuration.
Returns configuration dictionary for tracking and audit trails.
"""
os.environ['PYTHONHASHSEED'] = str(seed)
random.seed(seed)
np.random.seed(seed)
config = {
'seed': seed
'environment': 'reproducible'
'timestamp': 'setup_complete'
'libraries': {'numpy': np.__version__, 'pandas': pd.__version__}
}
logger.info(f"Reproducible environment configured with seed: {seed}")
return config
import os
import json
import logging
import pandas as pd
import numpy as np
from typing import Any, Dict, List
from pathlib import Path
logger = logging.getLogger(__name__)
class ExperimentManager:
"""Manages reproducible experiment workflows with artifact tracking."""
def __init__(self, project_root: str = "./experiments", seed: int = 42):
self.project_root = Path(project_root)
self.project_root.mkdir(parents=True, exist_ok=True)
self.seed = seed
self.runs: List[Dict[str, Any]] = []
self._setup_environment()
def _setup_environment(self) -> None:
os.environ['PYTHONHASHSEED'] = str(self.seed)
np.random.seed(self.seed)
def execute(self, data: pd.DataFrame, model_params: Dict[str, Any]) -> Dict[str, Any]:
"""Execute a reproducible experiment run with validation and logging."""
if data.empty:
raise ValueError("Input data cannot be empty")
run_id = f"run_{len(self.runs) + 1:03d}"
run_dir = self.project_root / run_id
run_dir.mkdir(exist_ok=True)
# Simulate model training & evaluation
np.random.shuffle(data.values)
metrics = {'accuracy': 0.85, 'f1': 0.82, 'seed': self.seed}
# Save artifacts
metadata = {
'run_id': run_id
'params': model_params
'metrics': metrics
'data_shape': list(data.shape)
}
with open(run_dir / "metadata.json", "w") as f:
json.dump(metadata, f, indent=2)
self.runs.append(metadata)
logger.info(f"Experiment {run_id} completed successfully.")
return metadata
# BAD: Hardcoded seeds, no validation, missing logging
def bad_pipeline(data):
np.random.seed(123)
return data.mean()
# GOOD: Configurable seeds, input validation, structured logging
def good_pipeline(data: pd.DataFrame, seed: int = 42) -> float:
if data.empty:
raise ValueError("Data cannot be empty")
np.random.seed(seed)
logger.info(f"Processing {len(data)} rows with seed {seed}")
return float(data.mean().mean())
| Pitfall | Problem | Solution | |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.