Generalized Scores for Multi-Class Imbalanced Classification

### Describe the workflow you want to enable

We wish to extend Matthew coefficient and F1 to multi- class problems.

### Describe your proposed solution

We already generated a pypi package
https://pypi.org/project/matthew-Coef-MultiClass/  which supports this. 

We created a unique function that follows the signature pf metrics._classification.py  current solution for the binary case
I will be glad to add this solution 

### Describe alternatives you've considered, if relevant

The following functions performs the required  (as an alternative to use our own package):

```python
class AVERAG_TYPE(Enum):
    MATTHEW_GEN = 2
    F1_GEN = 3

def generalized_matthew(y_true,y_pred,labels,ave_type=AVERAG_TYPE.MATTHEW_GEN.value):

    # A utitliy function which normalizes the confusion and perfroms the relevant average
    def norm_confusion_mat(conf_mat, average, dimension_size):
        m1 = conf_mat / np.sum(conf_mat, axis=1)
        m2 = conf_mat / np.sum(conf_mat, axis=0)

        return [[average([m1[i, j], m2[j][i]])
                 for i in range(dimension_size)] for j in range(dimension_size)]

    # A utitliy function that perfroms the generaized score of F1 . it calculates the hamonic average
    # over the trace of the normalized confusion matrix
    def gen_f1_scalar_op(h_conf_mat):
        l_mat = len(h_conf_mat)
        return st.mstats.hmean([h_conf_mat[i][i] for i in range(l_mat)])

    dimension_size =len(labels)
    conf_mat=confusion_matrix(y_true=y_true,y_pred=y_pred ,labels=labels)
    if ave_type == AVERAG_TYPE.MATTHEW_GEN.value:
        av_func =st.mstats.gmean
        scalar_op =np.linalg.det
    elif ave_type ==AVERAG_TYPE.F1_GEN.value:
        av_func = st.mstats.hmean
        scalar_op =gen_f1_scalar_op

    G_mat= norm_confusion_mat(conf_mat, av_func, dimension_size)
    return scalar_op(G_mat)
```


### Additional context

I wish to stress that there is a sound mathematical work behind this generalization which is soon to be published . The paper will be gladly provided by either myself or Uri Itai

COMMENT:
Do you mean this is not enough

https://scholar.google.com/scholar?hl=en&as_sdt=0,5&q=geometric+mean

On Mon, Aug 1, 2022 at 4:20 PM Thomas J. Fan ***@***.***>
wrote:

> Thank you for the feature request. Every feature we include has a maintenance
> cost
> <http://scikit-learn.org/dev/faq.html#why-are-you-so-selective-on-what-algorithms-you-include-in-scikit-learn>.
> Our maintainers are mostly volunteers. For a new feature to be included, we
> need evidence that it is often useful and, ideally, well-established
> <http://scikit-learn.org/dev/faq.html#what-are-the-inclusion-criteria-for-new-algorithms>
> in the literature or in practice.
>
> Given that the proposed method has not been published yet, I do not think
> it meets scikit-learn's includion critetion
> <https://scikit-learn.org/dev/faq.html#what-are-the-inclusion-criteria-for-new-algorithms>
> .
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/scikit-learn/scikit-learn/issues/24008#issuecomment-1201195713>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AB7W2Z7ANNJOOTHPBWLHUQDVW7FK7ANCNFSM54VCHWLA>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>

Labels: New Feature, Needs Decision - Include Feature