2019-ICML-COMIC icon indicating copy to clipboard operation
2019-ICML-COMIC copied to clipboard

How to calculate Accuracy?

Open dugzzuli opened this issue 5 years ago • 2 comments

How to calculate Accuracy?

dugzzuli avatar Nov 20 '20 13:11 dugzzuli

You can get acc in this way

def acc_(y_true, y_pred): """ Calculate clustering accuracy. Require scikit-learn installed

# Arguments
    y: true labels, numpy.array with shape `(n_samples,)`
    y_pred: predicted labels, numpy.array with shape `(n_samples,)`

# Return
    accuracy, in [0,1]
"""
y_true = y_true.astype(np.int64)
assert y_pred.size == y_true.size
D = max(y_pred.max(), y_true.max()) + 1
w = np.zeros((D, D), dtype=np.int64)
for i in range(y_pred.size):
    w[y_pred[i], y_true[i]] += 1
from sklearn.utils.linear_assignment_ import linear_assignment
ind = linear_assignment(w.max() - w)
return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size

m22453 avatar Nov 21 '20 04:11 m22453

Thank you very much.

dugzzuli avatar Nov 24 '20 02:11 dugzzuli