Metric names and icons #502
ecomodeller
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
def metric(best=None):
"""Decorator to attach a 'best' attribute to metric functions."""
def decorator(func):
func.best = best # Set the best value
return func
return decorator
@metric(best=0)
def mean_error(obs, model):
return (model - obs).mean()
@metric(best="+")
def r2_score(obs, model):
return 1 - ((obs - model)**2).sum() / ((obs - obs.mean())**2).sum()
# User-defined metric without 'best'
def user_metric(obs, model):
return (obs - model).std()
# Function to get best value safely
def get_best(metric_func):
"""Returns the 'best' attribute if it exists, otherwise None."""
return getattr(metric_func, "best", None)
# Usage
print(get_best(mean_error)) # Output: 0
print(get_best(r2_score)) # Output: "+"
print(get_best(user_metric)) # Output: None (no best defined) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Is this how you envision this decorator to be used for user defined metrics? from modelskill.metrics import metric, add_metric
@metric(best="-")
def silly(obs,model):
return np.random.uniform()
add_metric(silly) # this step seems unnecessary, could this be part of the decorator?
cc.skill(metrics=[silly]).style() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
The

skoreproject is designed to make evaluation of ML models easy.One feature is nice skill tables were the direction of better is indicated for clarity.
skoreuses a simple dict to store this info.https://github.com/probabl-ai/skore/blob/b5f84adb03cfb659233d3085739b33ab086710d9/skore/src/skore/sklearn/_estimator/metrics_accessor.py#L27-L38
Should we add a similar feature to ModelSkill?
Beta Was this translation helpful? Give feedback.
All reactions