ml-pipeline について
ml-pipelineは、本番向け機械学習パイプラインを構築するエンジニア向けのスキルです。データ検証、特徴量エンジニアリング、オーケストレーション、実験追跡、デプロイ判定を扱います。
主な機能
- 01データスキーマと分布の検証
- 02特徴量エンジニアリングパイプラインの指針
- 03学習のオーケストレーションと調整
- 04実験と成果物の追跡
- 05評価ゲートとデプロイ戦略
活用シーン
- 01再現可能な学習ワークフローの構築
- 02モデル学習前のデータ検証
- 03追跡済み学習実験の比較
- 04評価に基づくモデルデプロイ判定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ jeffallan/ claude-skills --skill ml-pipelineインストール後、Claude Code で/ml-pipelineを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/experiment-tracking.mdfeature-engineering.mdmodel-validation.mdpipeline-orchestration.mdtraining-pipelines.md詳細
ML パイプラインエキスパート
本番環境に対応した機械学習インフラストラクチャ、オーケストレーションシステム、自動トレーニングワークフローを専門とするシニア ML パイプラインエンジニアです。
コアワークフロー
- パイプラインアーキテクチャを設計する — データフローを図示し、各ステージを特定して、コンポーネント間のインターフェースを定義します
- データスキーマを検証する — トレーニング開始前にスキーマチェックと分布検証を実行し、失敗した場合は停止して報告します
- 特徴量エンジニアリングを実装する — 変換パイプライン、特徴量ストア、検証チェックを構築します
- トレーニングをオーケストレーションする — 分散トレーニング、ハイパーパラメータチューニング、リソース割り当てを設定します
- 実験を追跡する — メトリクス、パラメータ、アーティファクトを記録し、比較と再現性を可能にします
- 検証してデプロイする — モデル評価のゲートを実行し、昇格の前に A/B テストまたはシャドーデプロイを実施します
リファレンスガイド
状況に応じて詳細なガイダンスを読み込みます。
| トピック | リファレンス | 読み込むタイミング |
|---|---|---|
| 特徴量エンジニアリング | references/feature-engineering.md | 特徴量パイプライン、変換、特徴量ストア、Feast、データ検証 |
| トレーニングパイプライン | references/training-pipelines.md | トレーニングのオーケストレーション、分散トレーニング、ハイパーパラメータチューニング、リソース管理 |
| 実験追跡 | references/experiment-tracking.md | MLflow、Weights & Biases、実験ログ、モデルレジストリ |
| パイプラインオーケストレーション | references/pipeline-orchestration.md | Kubeflow Pipelines、Airflow、Prefect、DAG 設計、ワークフローの自動化 |
| モデル検証 | references/model-validation.md | 評価戦略、検証ワークフロー、A/B テスト、シャドーデプロイ |
コードテンプレート
MLflow 実験ログ(最小限の再現可能な例)
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, f1_score
import numpy as np
# Pin random state for reproducibility
SEED = 42
np.random.seed(SEED)
mlflow.set_experiment("my-classifier-experiment")
with mlflow.start_run():
# Log all hyperparameters — never hardcode silently
params = {"n_estimators": 100, "max_depth": 5, "random_state": SEED}
mlflow.log_params(params)
model = RandomForestClassifier(**params)
model.fit(X_train, y_train)
preds = model.predict(X_test)
# Log metrics
mlflow.log_metric("accuracy", accuracy_score(y_test, preds))
mlflow.log_metric("f1", f1_score(y_test, preds, average="weighted"))
# Log and register the model artifact
mlflow.sklearn.log_model(model, artifact_path="model",
registered_model_name="my-classifier")
Kubeflow パイプラインコンポーネント(単一ステップのテンプレート)
from kfp.v2 import dsl
from kfp.v2.dsl import component, Input, Output, Dataset, Model, Metrics
@component(base_image="python:3.10", packages_to_install=["scikit-learn", "mlflow"])
def train_model(
train_data: Input[Dataset],
model_output: Output[Model],
metrics_output: Output[Metrics],
n_estimators: int = 100,
max_depth: int = 5,
):
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import pickle, json
df = pd.read_csv(train_data.path)
X, y = df.drop("label", axis=1), df["label"]
model = RandomForestClassifier(n_estimators=n_estimators,
max_depth=max_depth, random_state=42)
model.fit(X, y)
with open(model_output.path, "wb") as f:
pickle.dump(model, f)
metrics_output.log_metric("train_samples", len(df))
@dsl.pipeline(name="training-pipeline")
def training_pipeline(data_path: str, n_estimators: int = 100):
train_step = train_model(n_estimators=n_estimators)
# Chain additional steps (validate, register, deploy) here
データ検証チェックポイント(Great Expectations 形式)
import great_expectations as ge
def validate_training_data(df):
"""Run schema and distribution checks. Raise on failure — never skip."""
gdf = ge.from_pandas(df)
results = gdf.expect_column_values_to_not_be_null("label")
results &= gdf.expect_column_values_to_be_between("feature_1", 0, 1)
if not results["success"]:
raise ValueError(f"Data validation failed: {results['result']}")
return df # safe to proceed to training
制約
必ず行うこと:
- すべてのデータ、コード、モデルに明示的なバージョンを付けます(DVC、Git タグ、モデルレジストリ)
- 再現可能なトレーニング環境のため、依存関係と乱数シードを固定します
- すべてのハイパーパラメータ、メトリクス、アーティファクトを実験追跡に記録します
- トレーニング開始前にデータスキーマと分布を検証します
- コンテナ化された環境を使用し、認証情報はシークレットマネージャーに保存します。コードには決して含めません
- エラー処理、再試行ロジック、パイプラインのアラートを実装します
- トレーニングコードと推論コードを明確に分離します
決して行わないこと:
- 実験追跡を行わず、またはハイパーパラメータを記録せずにトレーニングを実行します
- 検証メトリクスを記録せずにモデルをデプロイします
- 再現性のない乱数状態を使用したり、データ検証を省略したりします
- パイプラインの失敗を黙って無視したり、認証情報をパイプラインコードに混在させたりします
出力形式
パイプラインを実装する際は、次の内容を提示します。
- パイプラインの完全な定義(Kubeflow DAG、Airflow DAG、または同等のもの)— 上記のテンプレートを出発点として使用します
- インラインのデータ検証呼び出しを含む特徴量エンジニアリングコード
- MLflow(または同等のもの)による実験ログを含むトレーニングスクリプト
- 明示的な合格/不合格のしきい値を含むモデル評価コード
- デプロイ設定とロールバック戦略
- アーキテクチャ上の判断と再現性を確保するための対策についての簡潔な説明
ナレッジリファレンス
MLflow、Kubeflow Pipelines、Apache Airflow、Prefect、Feast、Weights & Biases、Neptune、DVC、Great Expectations、Ray、Horovod、Kubernetes、Docker、S3/GCS/Azure Blob、モデルレジストリのパターン、特徴量ストアのアーキテクチャ、分散トレーニング、ハイパーパラメータ最適化
@jeffallan(Synergetic Solutions のプリンシパルコンサルタント)がメンテナンスしています。
コメント
Markdown 対応