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.

IsolationForest_test.py 1.2 kB

4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. import numpy as np
  2. from tods.sk_interface.detection_algorithm.IsolationForest_skinterface import IsolationForestSKI
  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. #prepare the data
  8. data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt")
  9. # print("shape:", data.shape)
  10. # print("datatype of data:",data.dtype)
  11. # print("First 5 rows:\n", data[:5])
  12. X_train = np.expand_dims(data[:10000], axis=1)
  13. X_test = np.expand_dims(data[10000:], axis=1)
  14. # print("First 5 rows train:\n", X_train[:5])
  15. # print("First 5 rows test:\n", X_test[:5])
  16. transformer = IsolationForestSKI()
  17. transformer.fit(X_train)
  18. prediction_labels_train = transformer.predict(X_train)
  19. prediction_labels = transformer.predict(X_test)
  20. prediction_score = transformer.predict_score(X_test)
  21. print("Prediction Labels\n", prediction_labels)
  22. print("Prediction Score\n", prediction_score)
  23. y_true = prediction_labels_train
  24. y_pred = prediction_labels
  25. print('Accuracy Score: ', accuracy_score(y_true, y_pred))
  26. confusion_matrix(y_true, y_pred)
  27. print(classification_report(y_true, y_pred))

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