question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow user-defined metrics

See original GitHub issue

I would like to allow users to pass their own metrics into compute_. Right now, we have to add a new metric to climpred first.

def my_mse(forecast, reference, dim='svd', **metric_kwargs):
    return ((forecast - reference)**2).mean(dim)

@pytest.mark.parametrize('comparison', PM_COMPARISONS)
@pytest.mark.parametrize('metric',[my_mse])
def test_new_metric_passed_to_compute(pm_da_ds1d, pm_da_control1d, metric, comparison):
    actual = compute_perfect_model(
        pm_da_ds1d, pm_da_control1d, comparison=comparison, metric=metric)

    expected = compute_perfect_model(
        pm_da_ds1d, pm_da_control1d, comparison=comparison, metric='mse')

    assert_allclose(actual, expected)

However, implementing this requires to re-structure metrics.py and compute_. constants.py would need to generate DETERMINISTIC_HINDCAST_METRICS, POSITIVELY_ORIENTED_METRICS, … dynamically, because currently the logic of compute_ asks several times what kind of metric is applied.

I first thought of just allowing metric to be a function in get_metric_function, but how does this function then pass through the flow of compute_? Would we just allow it to pass regardless the other checks (bad idea)?

This would allow users to quickly checkout new metrics in climpred. If their metric is not available, there is a long way to implement new metrics currently (see https://github.com/bradyrx/climpred/pull/264).

So, there are two questions here: should we implement this? and if so, how best?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bradyrxcommented, Dec 4, 2019

Correct. I’d assume the latter is the much preferred way. You could move the docstrings there which would get pulled into the API and you can add anything unique to the given metric that the base class (Metric) doesn’t have.

0reactions
aaronspringcommented, Dec 4, 2019

so I shouldnt do:

# initialize new metric
mse = Metrics(True, False, 'mse', _mse)
pearson_r = Metrics(False, False, 'mse', _pearson_r)
...

but rather

class mse(Metric):
    def __init__(self, a,b,c,d):
        super().__init__(a,b,c,d)
class pearson_r(Metric):
    def __init__(self, a,b,c,d):
        super().__init__(a,b,c,d)
Read more comments on GitHub >

github_iconTop Results From Across the Web

User Defined Metrics are Being Deprecated in Enterprise ...
User-Defined Metrics allow users to extend Enterprise Manager's monitoring capabilities by defining their own custom metrics.
Read more >
User-defined Metrics - Avi Networks
Any given user-defined metric is scoped to the virtual service that creates it via a DataScript. Since a DataScript can be used by...
Read more >
Configuring User-Defined Metrics - Riverbed Support
Login to the UI as a user with administrative privilege. 2. Navigate to CONFIGURE > All Settings->Monitor->User-Defined Metrics. The User-Defined Metrics ...
Read more >
Enabling monitoring for user-defined projects
Cluster administrators can enable monitoring for user-defined projects by setting the enableUserWorkload: true field in the cluster monitoring ConfigMap object.
Read more >
Enabling user-defined custom metrics for Horizontal Pod ...
On this page · Enabling Logging and Monitoring for user applications · Annotate a user application for metrics collection · Deploy an example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found