Created
July 28, 2022 14:34
-
-
Save kylegallatin/6fea75fc58ba053fbceb03941a1834d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
class PerformanceMonitor: | |
def __init__(self): | |
self.inference_times = [] | |
def record(self, prediction_time: float) -> None: | |
self.inference_times.append(prediction_time) | |
def mean(self) -> float: | |
return sum(self.inference_times)/len(self.inference_times) | |
def model_predict(user_id: str) -> float: | |
start = time.time() | |
model = load_latest_model() | |
features = feature_store.get_user_feature(user_id) | |
prediction = model.predict([[v for k,v in features.items() if k != "target"]]) | |
end = time.time() | |
monitor.record(end-start) | |
return prediction | |
monitor = PerformanceMonitor() | |
model_predict("a27b0912-0cf8-11ed-899e-b29c4abd48f4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment