Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. from sklearn import metrics
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from sklearn.metrics import mean_squared_error
  5. #異常値の算出
  6. test_normal_pred = vae.predict(test_normal, verbose=1)
  7. test_anomaly_pred = vae.predict(test_anomaly, verbose=1)
  8.  
  9. MSE_normal = mean_squared_error(test_normal, test_normal_pred)
  10. MSE_anomaly = mean_squared_error(test_anomaly, test_anomaly_pred)
  11.  
  12. print(test_normal.shape)
  13. print(test_anomaly.shape)
  14. print(test_normal_pred.shape)
  15. print(test_anomaly_pred.shape)
  16. print(MSE_normal)
  17. print(MSE_anomaly)
  18.  
  19.  
  20. #ROC曲線の描画
  21. y_true = np.zeros(len(test_normal)+len(test_anomaly))
  22. y_true[len(test_normal):] = 1#0:正常、1:異常
  23. score_normal = np.array(MSE_normal)
  24. score = np.hstack((score_normal, np.array(MSE_anomaly)))
  25. #print(RMSE_normal.shape)
  26. #print(RMSE_anomaly.shape)
  27. print(y_true.shape)
  28. print(score.shape)
  29. print(score)
  30.  
  31. # FPR, TPR(, しきい値) を算出
  32. #fpr_old, tpr_old, _ = metrics.roc_curve(y_true, old_score)
  33. fpr, tpr = metrics.roc_curve(y_true, score)
  34.  
  35. # AUC
  36. #auc_old = metrics.auc(fpr_old, tpr_old)
  37. auc = metrics.auc(fpr, tpr)
  38.  
  39. # ROC曲線をプロット
  40. plt.figure
  41. #plt.plot(fpr_old, tpr_old, label='Old method (area = %.2f)'%auc_old)
  42. plt.plot(fpr, tpr, label='VAE method (area = %.2f)'%auc, c="r")
  43. plt.legend()
  44. plt.title('ROC curve')
  45. plt.xlabel('False Positive Rate')
  46. plt.ylabel('True Positive Rate')
  47. plt.grid(True)
  48. plt.savefig(path + "ROC curve.png")
  49. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement