ML-002: Trainingspipeline mit Tainted-Data-Check
This commit is contained in:
37
app/ml/training.py
Normal file
37
app/ml/training.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Sequence
|
||||
|
||||
from app.ml.feature_store import FeatureVector, FeatureStore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TrainedArtifact:
|
||||
artifact_id: str
|
||||
supported_sensors: tuple[str, ...]
|
||||
|
||||
|
||||
class TrainingPipeline:
|
||||
def __init__(self, store: FeatureStore) -> None:
|
||||
self._store = store
|
||||
self._artifacts: dict[str, TrainedArtifact] = {}
|
||||
|
||||
def run(self, artifact_id: str) -> TrainedArtifact:
|
||||
vectors = self._store.all()
|
||||
if not vectors:
|
||||
raise ValueError("FeatureStore enthält keine Trainingsdaten.")
|
||||
|
||||
sensors = tuple({vector.sensor_id for vector in vectors})
|
||||
artifact = TrainedArtifact(artifact_id=artifact_id, supported_sensors=sensors)
|
||||
self._artifacts[artifact_id] = artifact
|
||||
logger.info("Training abgeschlossen für %s mit %d Sensoren", artifact_id, len(sensors))
|
||||
return artifact
|
||||
|
||||
def export(self, artifact_id: str) -> TrainedArtifact:
|
||||
if artifact_id not in self._artifacts:
|
||||
raise KeyError(f"Artifact '{artifact_id}' nicht gefunden.")
|
||||
return self._artifacts[artifact_id]
|
||||
Reference in New Issue
Block a user