def amex_metric_mody_true y_pred labels = nptransposenparrayy_true y_pred labels = labelslabels 1argsort-1 weights = npwherelabels0==0 20 1 cut_vals = labelsnpcumsumweights =
The function calculates the AMEX metric, which is a combination of Gini coefficient
and top 4% accuracy, given the true labels and predicted labels.
The function first sorts the labels based on the predicted labels in descending order.
Then, it assigns a weight of 20 to false negatives (labels with true value 0) and a weight of 1 to the rest.
It selects the top 4% of the sorted labels based on the cumulative sum of the weights and calculates
the ratio of true positives in the top 4% to the total number of true positives.
The function then calculates the Gini coefficient for both the true and predicted labels separately.
It first sorts the labels based on each label separately in descending order.
Then, it applies the same weights as before and calculates the cumulative sum of the weighted labels.
It then calculates the Lorentz curve, which is the cumulative sum of true positives divided by the total number
of true positives. Finally, it calculates the Gini coefficient by subtracting the area under the curve from the
area of the diagonal and normalizing it by the area under the diagonal.
The function returns the AMEX metric, which is the sum of the ratio of true positives in the top 4% and the
normalized ratio of Gini coefficients for the true and predicted labels
原文地址: https://www.cveoy.top/t/topic/hcVL 著作权归作者所有。请勿转载和采集!