@@ -5,6 +5,7 @@ import math
|
||||
from dataclasses import dataclass
|
||||
from typing import Sequence
|
||||
|
||||
from app.ml.explanation import FeatureExplanation, explain_feature
|
||||
from app.ml.feature_store import FeatureVector
|
||||
from app.ml.registry.model_registry import ModelRegistry
|
||||
from app.ml.training import TrainedArtifact, TrainingPipeline
|
||||
@@ -19,6 +20,7 @@ class PredictionResult:
|
||||
predictions: dict[str, float]
|
||||
confidence: float
|
||||
model_type: str
|
||||
explanations: dict[str, FeatureExplanation]
|
||||
|
||||
|
||||
class Predictor:
|
||||
@@ -52,13 +54,21 @@ class Predictor:
|
||||
)
|
||||
|
||||
predictions: dict[str, float] = {}
|
||||
explanations: dict[str, FeatureExplanation] = {}
|
||||
confidences: list[float] = []
|
||||
for feature_name in feature_names:
|
||||
model = sensor_models[feature_name]
|
||||
current_value = float(entity.values[feature_name])
|
||||
if not math.isfinite(current_value):
|
||||
raise ValueError("Vorhersagewerte müssen endlich sein.")
|
||||
predictions[feature_name] = model.forecast(current_value)
|
||||
predicted_value = model.forecast(current_value)
|
||||
predictions[feature_name] = predicted_value
|
||||
explanations[feature_name] = explain_feature(
|
||||
feature_name,
|
||||
current_value,
|
||||
predicted_value,
|
||||
model,
|
||||
)
|
||||
confidences.append(model.confidence)
|
||||
|
||||
return PredictionResult(
|
||||
@@ -67,6 +77,7 @@ class Predictor:
|
||||
predictions=predictions,
|
||||
confidence=sum(confidences) / len(confidences),
|
||||
model_type=artifact.model_type,
|
||||
explanations=explanations,
|
||||
)
|
||||
|
||||
def predict_batch(
|
||||
|
||||
Reference in New Issue
Block a user