You are building a model registry. Given a list of model versions, each with a name, accuracy, latency, and timestamp, decide which model should be promoted to production.
A model is promoted if it has the highest accuracy. If two models share the same accuracy, prefer the one with lower latency. If still tied, prefer the most recent model (latest timestamp).
Return the name of the model to promote.
Input:
models = [ {"name": "v1", "accuracy": 0.85, "latency": 120, "timestamp": "2024-01-15"}, {"name": "v2", "accuracy": 0.91, "latency": 95, "timestamp": "2024-02-20"}, ]
Output:
"v2"
v2 has higher accuracy (0.91 vs 0.85), so it is promoted.
Input:
models = [ {"name": "v1", "accuracy": 0.90, "latency": 100, "timestamp": "2024-01-10"}, {"name": "v2", "accuracy": 0.90, "latency": 80, "timestamp": "2024-03-05"}, ]
Output:
"v2"
Both have accuracy 0.90. v2 wins on lower latency (80 vs 100).
Python's sorted() accepts a key function. You can sort by a tuple of criteria.
Negating a value reverses its sort order without changing the direction of other keys.
Sign in to take notes on this problem
Accepts: array
You are building a model registry. Given a list of model versions, each with a name, accuracy, latency, and timestamp, decide which model should be promoted to production.
A model is promoted if it has the highest accuracy. If two models share the same accuracy, prefer the one with lower latency. If still tied, prefer the most recent model (latest timestamp).
Return the name of the model to promote.
Input:
models = [ {"name": "v1", "accuracy": 0.85, "latency": 120, "timestamp": "2024-01-15"}, {"name": "v2", "accuracy": 0.91, "latency": 95, "timestamp": "2024-02-20"}, ]
Output:
"v2"
v2 has higher accuracy (0.91 vs 0.85), so it is promoted.
Input:
models = [ {"name": "v1", "accuracy": 0.90, "latency": 100, "timestamp": "2024-01-10"}, {"name": "v2", "accuracy": 0.90, "latency": 80, "timestamp": "2024-03-05"}, ]
Output:
"v2"
Both have accuracy 0.90. v2 wins on lower latency (80 vs 100).
Python's sorted() accepts a key function. You can sort by a tuple of criteria.
Negating a value reverses its sort order without changing the direction of other keys.
Sign in to take notes on this problem
Accepts: array