Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn import metrics
- import matplotlib.pyplot as plt
- import numpy as np
- from sklearn.metrics import mean_squared_error
- #異常値の算出
- test_normal_pred = vae.predict(test_normal, verbose=1)
- test_anomaly_pred = vae.predict(test_anomaly, verbose=1)
- MSE_normal = mean_squared_error(test_normal, test_normal_pred)
- MSE_anomaly = mean_squared_error(test_anomaly, test_anomaly_pred)
- print(test_normal.shape)
- print(test_anomaly.shape)
- print(test_normal_pred.shape)
- print(test_anomaly_pred.shape)
- print(MSE_normal)
- print(MSE_anomaly)
- #ROC曲線の描画
- y_true = np.zeros(len(test_normal)+len(test_anomaly))
- y_true[len(test_normal):] = 1#0:正常、1:異常
- score_normal = np.array(MSE_normal)
- score = np.hstack((score_normal, np.array(MSE_anomaly)))
- #print(RMSE_normal.shape)
- #print(RMSE_anomaly.shape)
- print(y_true.shape)
- print(score.shape)
- print(score)
- # FPR, TPR(, しきい値) を算出
- #fpr_old, tpr_old, _ = metrics.roc_curve(y_true, old_score)
- fpr, tpr = metrics.roc_curve(y_true, score)
- # AUC
- #auc_old = metrics.auc(fpr_old, tpr_old)
- auc = metrics.auc(fpr, tpr)
- # ROC曲線をプロット
- plt.figure
- #plt.plot(fpr_old, tpr_old, label='Old method (area = %.2f)'%auc_old)
- plt.plot(fpr, tpr, label='VAE method (area = %.2f)'%auc, c="r")
- plt.legend()
- plt.title('ROC curve')
- plt.xlabel('False Positive Rate')
- plt.ylabel('True Positive Rate')
- plt.grid(True)
- plt.savefig(path + "ROC curve.png")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement