Chuyển đến nội dung chính

レッスン 21: ML パイプラインと機能ストア — トレーニング、サービス提供、A/B テスト

ファッション POD 用 ML プラットフォーム — フィーチャー ストア、トレーニング パイプライン、モデル提供、A/B テスト、モデル モニタリング、ドリフト検出、MLOps スタック (MLflow、レジストリ、実験追跡)。

🏗️ アーキテクチャ — レッスン 21 レッスン 21: ML パイプラインと機能ストア — トレーニング、サービス、A/B テスト

ファッション デザインとプリント オン デマンド システム アーキテクチャ — ドメイン分析から生産まで

パート 6: データ プラットフォームと分析

xdev.asia

1. ML プラットフォームの概要

Raw Data -> Feature Pipeline -> Feature Store
                     │
                     ├-> Training Jobs -> Model Registry
                     │
                     └-> Online Features -> Model Serving -> Predictions

2. フィーチャーストアのデザイン

interface FeatureDefinition {
  name: string;
  entity: 'user' | 'product' | 'shop';
  type: 'float' | 'int' | 'string' | 'vector';
  source: string;
  ttlHours?: number;
}

const features: FeatureDefinition[] = [
  { name: 'user_30d_click_count', entity: 'user', type: 'int', source: 'events' },
  { name: 'product_ctr_7d', entity: 'product', type: 'float', source: 'analytics' },
  { name: 'product_clip_embedding', entity: 'product', type: 'vector', source: 'ai' },
  { name: 'shop_return_rate_30d', entity: 'shop', type: 'float', source: 'orders' },
];
  • オフラインストア: トレーニング データセット
  • オンラインストア: 低遅延推論機能
  • 特定時点の正確性: データ漏洩を回避します

3. トレーニング パイプライン

Schedule trigger (daily/weekly)
  -> Build training dataset
  -> Train model
  -> Evaluate metrics
  -> Register candidate model
  -> Optional shadow deployment
class TrainingOrchestrator {
  async run(job: TrainingJob) {
    const dataset = await this.datasetBuilder.build(job.featureSet, job.timeWindow);
    const model = await this.trainer.train(job.algorithm, dataset);
    const metrics = await this.evaluator.evaluate(model, dataset.validation);

    await this.mlflow.logRun({ job, metrics });

    if (metrics.auc >= job.minAuc && metrics.calibrationError <= job.maxCalibrationError) {
      await this.registry.register(model, metrics);
    }
  }
}

4. モデルの提供

パターン使用時
オンライン推論レコメンデーション、リアルタイムのパーソナライゼーション
バッチ推論夜間のランキング事前計算、トレンド予測
ストリーミング推論イベント別の不正/リスクスコアリング
interface PredictionRequest {
  modelName: string;
  entityId: string;
  features: Record<string, unknown>;
}

class ModelServingGateway {
  async predict(req: PredictionRequest) {
    const onlineFeatures = await this.featureStore.getOnline(req.entityId);
    const merged = { ...onlineFeatures, ...req.features };
    return this.runtime.predict(req.modelName, merged);
  }
}

5. A/B テストのフレームワーク

interface Experiment {
  id: string;
  name: string;
  variants: Array<{ name: 'control' | 'treatment'; weight: number }>;
  primaryMetric: 'ctr' | 'conversion' | 'revenue_per_session';
  guardrails: string[];
}

function assignVariant(userId: string, experimentId: string): string {
  const bucket = hash(userId + experimentId) % 100;
  return bucket < 50 ? 'control' : 'treatment';
}
  • テストを実行する前に主要な指標が明確である
  • ガードレール: レイテンシ、エラー率、返金率
  • 停止基準: 重要性 + 実際の影響

6. モニタリングとドリフト検出

Monitors:
- Data drift: PSI / KS distance
- Prediction drift: distribution shift
- Performance drift: CTR/conversion decay
- Operational: latency/error/timeout
if (psi(featureDistTrain, featureDistLive) > 0.2) {
  alert('Feature drift high');
  triggerRetraining('recommendation_model');
}

7. MLOps ガバナンス

  • バージョン管理と承認ワークフローを備えたモデル レジストリ
  • 実験的な追跡 (MLflow)
  • 再現可能なトレーニング (コード + データのスナップショット)
  • モデルが劣化した場合のロールバック戦略

8. まとめ

  • 機能ストア トレーニングとサービスを同期させるためのセンターです

  • トレーニングパイプライン モデルを宣伝する前に品質基準が必要

  • A/B テスト 安全な生産意思決定メカニズムです

  • ドリフト監視 モデルの劣化を早期に検出するのに役立ちます

  • MLOps ガバナンス ML が持続的に運営できるようにする