Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested fix for deprecated 'from sklearn.utils.linear_assignment_ import linear_assignment' #25

Open
AliS567 opened this issue Nov 30, 2020 · 1 comment

Comments

@AliS567
Copy link

AliS567 commented Nov 30, 2020

Hello great work!

i think 'from sklearn.utils.linear_assignment_ import linear_assignment' is now deprecated and I would recommend making the following changes to the accuracy module.

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 scipy.optimize import linear_sum_assignment as linear_assignment
ind = np.transpose(np.asarray(linear_assignment(w.max() - w)))
return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size

Thanks for all the great work!
Ali

@enaserianhanzaei
Copy link

I just found the sklearn linear-assignment and added that to the code (locally)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants