Created
July 24, 2019 07:05
-
-
Save MortisHuang/652a37638f9592b6cc7c3c59f160adc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Eval. | |
q = model.predict(x, verbose=0) | |
p = target_distribution(q) # update the auxiliary target distribution p | |
# evaluate the clustering performance | |
y_pred = q.argmax(1) | |
if y is not None: | |
acc = np.round(accu(y, y_pred), 5) | |
nmi = np.round(nmis(y, y_pred), 5) | |
ari = np.round(aris(y, y_pred), 5) | |
loss = np.round(loss, 5) | |
print('Acc = %.5f, nmi = %.5f, ari = %.5f' % (acc, nmi, ari), ' ; loss=', loss) | |
#%% | |
import seaborn as sns | |
import sklearn.metrics | |
import matplotlib.pyplot as plt | |
sns.set(font_scale=3) | |
confusion_matrix = sklearn.metrics.confusion_matrix(y, y_pred) | |
plt.figure(figsize=(16, 14)) | |
sns.heatmap(confusion_matrix, annot=True, fmt="d", annot_kws={"size": 20}); | |
plt.title("Confusion matrix", fontsize=30) | |
plt.ylabel('True label', fontsize=25) | |
plt.xlabel('Clustering label', fontsize=25) | |
plt.show() | |
plt.savefig("Result.png",dpi=400) | |
#%% | |
from sklearn.utils.linear_assignment_ import linear_assignment | |
y_true = y.astype(np.int64) | |
D = max(y_pred.max(), y_true.max()) + 1 | |
w = np.zeros((D, D), dtype=np.int64) | |
# Confusion matrix. | |
for i in range(y_pred.size): | |
w[y_pred[i], y_true[i]] += 1 | |
ind = linear_assignment(-w) | |
sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment