Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the outputs of jaccard_score and jaccard_similarity_score different?

When trying to use jaccard_similarity_score I get "Deprecation Warning: jaccard_similarity_score has been deprecated and replaced with jaccard_score. It will be removed in version 0.23. This implementation has surprising behavior for binary and multiclass classification tasks."

The classic explanation for Jaccard Similarity Score matches the output from the deprecated jaccard_similarity_score .

However, the results of jaccard_score and jaccard_similarity_score are different (even when trying different parameters, as shown).

from sklearn.metrics import jaccard_similarity_score, jaccard_score  
y_pred = [0,1,0,1,0,0,0,1,0,1]  
y_true = [0,0,0,1,0,1,0,1,0,0] 
print("jaccard_similarity_score=",jaccard_similarity_score(y_true, y_pred),'\n')  
for param in ['weighted', 'micro', 'macro']:  
    print(param, " jaccard_score=", jaccard_score(y_true, y_pred,  average=param))    

This is the output of the code above:

jaccard_similarity_score= 0.7 

weighted  jaccard_score= 0.5575  
micro  jaccard_score= 0.5384615384615384  
macro  jaccard_score= 0.5125 

Is there an option that can be applied for the results to be equal ? Is the new jaccard_score working as expected ?

like image 553
steelponey Avatar asked Aug 31 '25 22:08

steelponey


1 Answers

from sklearn.metrics import jaccard_similarity_score needs to be replaced by from sklearn.metrics import jaccard_score and new parameter pos_label is required, for e.g. - jaccard_score(y_test, dt_yhat,pos_label = "PAIDOFF"). Valid labels for pos_label are: array(['COLLECTION', 'PAIDOFF'], dtype='<U10')

https://github.com/DiamondLightSource/SuRVoS/issues/103

like image 74
mridulrb Avatar answered Sep 03 '25 14:09

mridulrb