You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Telemanom_test.py 1.8 kB

4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import numpy as np
  2. from tods.tods_skinterface.primitiveSKI.detection_algorithm.Telemanom_skinterface import TelemanomSKI
  3. from sklearn.metrics import precision_recall_curve
  4. from sklearn.metrics import accuracy_score
  5. from sklearn.metrics import confusion_matrix
  6. from sklearn.metrics import classification_report
  7. import matplotlib.pyplot as plt
  8. from sklearn import metrics
  9. #prepare the data
  10. data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt")
  11. # print("shape:", data.shape)
  12. # print("datatype of data:",data.dtype)
  13. # print("First 5 rows:\n", data[:5])
  14. X_train = np.expand_dims(data[:10000], axis=1)
  15. X_test = np.expand_dims(data[10000:], axis=1)
  16. # print("First 5 rows train:\n", X_train[:5])
  17. # print("First 5 rows test:\n", X_test[:5])
  18. transformer = TelemanomSKI(l_s= 2, n_predictions= 1)
  19. transformer.fit(X_train)
  20. prediction_labels_train = transformer.predict(X_train)
  21. prediction_labels = transformer.predict(X_test)
  22. prediction_score = transformer.predict_score(X_test)
  23. print("Prediction Labels\n", prediction_labels)
  24. print("Prediction Score\n", prediction_score)
  25. y_true = prediction_labels_train
  26. y_pred = prediction_labels
  27. print('Accuracy Score: ', accuracy_score(y_true, y_pred))
  28. confusion_matrix(y_true, y_pred)
  29. print(classification_report(y_true, y_pred))
  30. precision, recall, thresholds = precision_recall_curve(y_true, y_pred)
  31. f1_scores = 2*recall*precision/(recall+precision)
  32. print('Best threshold: ', thresholds[np.argmax(f1_scores)])
  33. print('Best F1-Score: ', np.max(f1_scores))
  34. fpr, tpr, threshold = metrics.roc_curve(y_true, y_pred)
  35. roc_auc = metrics.auc(fpr, tpr)
  36. plt.title('ROC')
  37. plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)
  38. plt.legend(loc = 'lower right')
  39. plt.ylabel('True Positive Rate')
  40. plt.xlabel('False Positive Rate')
  41. plt.show()

全栈的自动化机器学习系统,主要针对多变量时间序列数据的异常检测。TODS提供了详尽的用于构建基于机器学习的异常检测系统的模块,它们包括:数据处理(data processing),时间序列处理( time series processing),特征分析(feature analysis),检测算法(detection algorithms),和强化模块( reinforcement module)。这些模块所提供的功能包括常见的数据预处理、时间序列数据的平滑或变换,从时域或频域中抽取特征、多种多样的检测算