xarray-contrib / xskillscore

Metrics for verifying forecasts
https://xskillscore.readthedocs.io/en/stable/
Apache License 2.0
225 stars 40 forks source link

Non-dichotomous threat scores #187

Open ahuang11 opened 4 years ago

ahuang11 commented 4 years ago

If I'm not mistaken, I think threat scores can be non-dichotomous? Is this decorator used only because it hasn't been implemented yet or am I mistaken?

def dichotomous_only(method):
    """Decorator for methods that are defined for dichotomous forecasts only
    """

    @wraps(method)
    def wrapper(self, *args, **kwargs):
        if not self.dichotomous:
            raise AttributeError(
                f'{method.__name__} can only be computed for dichotomous (2-category) data'
            )
        return method(self, *args, **kwargs)

    return wrapper
aaronspring commented 4 years ago

I don’t understand what your question is.

ahuang11 commented 4 years ago

Why can't I use it for more than just two categories?

On Tue, Sep 22, 2020, 5:09 PM Aaron Spring notifications@github.com wrote:

I don’t understand what your question is.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/raybellwaves/xskillscore/issues/187#issuecomment-697008871, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADU7FFSG7HL4C6WZSUT4OR3SHEOC7ANCNFSM4RWJGLKQ .

dougiesquire commented 4 years ago

The current implementation of threat score requires that the data is dichotomous (see https://www.cawcr.gov.au/projects/verification/#Methods_for_dichotomous_forecasts). An extension to multi-category would certainly be welcome if you want to open a PR.

raybellwaves commented 4 years ago

@ahuang11 you may also be interested in https://github.com/raybellwaves/xskillscore/issues/138. May be worth dipping your toe in there before having a crack at multi-category

ahuang11 commented 4 years ago

I haven't looked too closely at the code, but https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html seems to be easy way to support multi categories.

ahuang11 commented 4 years ago

although I guess the code already supports multi-category; just need to update the functions to calculate similar to below: https://stackoverflow.com/questions/50666091/true-positive-rate-and-false-positive-rate-tpr-fpr-for-multi-class-data-in-py

    @dichotomous_only
    def threat_score(self, yes_category=2):
        """Returns the threat score(s) for dichotomous contingency data.
        .. math::
            TS = \\frac{hits}{hits + misses + \\mathrm{false~alarms}}
        Parameters
        ----------
        yes_category : value, optional
            The category coordinate value of the category corresponding to 'yes'
        Returns
        -------
        xarray.Dataset or xarray.DataArray
            An array containing the threat score(s)
        References
        ----------
        https://www.cawcr.gov.au/projects/verification/#Contingency_table
        """

        return self.hits(yes_category) / (
            self.hits(yes_category)
            + self.misses(yes_category)
            + self.false_alarms(yes_category)
        )
raybellwaves commented 3 years ago

moved to https://github.com/xarray-contrib/xskillscore/issues/284 leaving open