ZhuangDingyi / STZINB

Source code of implementing spatial-temporal zero-inflated negative binomial network for trip demand prediction
MIT License
22 stars 7 forks source link

true-zero rate and F1-score #1

Open ssssbug opened 3 months ago

ssssbug commented 3 months ago

Hello author, I would like to know how you implement the true-zero rate and F1-score, I wonder if you can make the code of these two public

ZhuangDingyi commented 3 months ago

Hi there,

It is based on their definitions:

def true_zeros(truth,pred):
    idx = truth == 0
    return np.sum(pred[idx]==0)/np.sum(idx)

def F1_SCORE(truth,pred):
    true_zeros = truth == 0
    pred_zeros = pred == 0
    precision = np.sum(pred_zeros & true_zeros ) / np.sum(pred_zeros)
    recall = np.sum(pred_zeros)/np.sum(true_zeros)
    return 2*(precision*recall)/(precision+recall)
ssssbug commented 3 months ago

Thank you very much for your reply, it was very helpful for me

Hi there,

It is based on their definitions:

def true_zeros(truth,pred):
    idx = truth == 0
    return np.sum(pred[idx]==0)/np.sum(idx)

def F1_SCORE(truth,pred):
    true_zeros = truth == 0
    pred_zeros = pred == 0
    precision = np.sum(pred_zeros & true_zeros ) / np.sum(pred_zeros)
    recall = np.sum(pred_zeros)/np.sum(true_zeros)
    return 2*(precision*recall)/(precision+recall)