MultiLabel Ranking Metrics – Ranking Loss | ML
Code: Python code to implement Ranking Loss using the scikit-learn library.
# import sklearn and numpy libraries import numpy as np from sklearn.metrics import label_ranking_loss # take sample dataset y_true = np.array([[ 1 , 0 , 0 ], [ 0 , 1 , 0 ], [ 0 , 0 , 1 ]]) y_pred_score = np.array([[ 0.75 , 0.5 , 1 ], [ 1 , 0.2 , 0.1 ], [ 0.1 , 1 , 0.9 ]]) # calculate and print label ranking loss print (label_ranking_loss(y_true, y_pred_score )) # this will give minimum ranking loss y_pred_score = np.array([[ 0.75 , 0.5 , 0.1 ], [ 0.1 , 0.6 , 0.1 ], [ 0.3 , 0.3 , 0.4 ]]) print (label_ranking_loss(y_true, y_pred_score )) |
Output:
0.5 0
0
References:
- Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010). Mining multi-label data. In Data mining and knowledge discovery handbook (pp. 667-685). Springer US.
Contact Us