@@ -0,0 +1,54 @@ | |||||
import numpy as np | |||||
from tods.sk_interface.detection_algorithm.DeepLog_skinterface import DeepLogSKI | |||||
#from tods.tods_skinterface.primitiveSKI.detection_algorithm.DeepLog_skinterface import DeepLogSKI | |||||
from sklearn.metrics import precision_recall_curve | |||||
from sklearn.metrics import accuracy_score | |||||
from sklearn.metrics import confusion_matrix | |||||
from sklearn.metrics import classification_report | |||||
import matplotlib.pyplot as plt | |||||
from sklearn import metrics | |||||
#prepare the data | |||||
data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt") | |||||
X_train = np.expand_dims(data[:10000], axis=1) | |||||
X_test = np.expand_dims(data[10000:], axis=1) | |||||
transformer = DeepLogSKI() | |||||
transformer.fit(X_train) | |||||
prediction_labels_train = transformer.predict(X_train) | |||||
prediction_labels = transformer.predict(X_test) | |||||
prediction_score = transformer.predict_score(X_test) | |||||
print("Primitive: ", transformer.primitive) | |||||
print("Prediction Labels\n", prediction_labels) | |||||
print("Prediction Score\n", prediction_score) | |||||
# y_true = prediction_labels_train[:1000] | |||||
# y_pred = prediction_labels[:1000] | |||||
y_true = prediction_labels_train | |||||
y_pred = prediction_labels | |||||
print('Accuracy Score: ', accuracy_score(y_true, y_pred)) | |||||
confusion_matrix(y_true, y_pred) | |||||
print(classification_report(y_true, y_pred)) | |||||
precision, recall, thresholds = precision_recall_curve(y_true, y_pred) | |||||
f1_scores = 2*recall*precision/(recall+precision) | |||||
print('Best threshold: ', thresholds[np.argmax(f1_scores)]) | |||||
print('Best F1-Score: ', np.max(f1_scores)) | |||||
fpr, tpr, threshold = metrics.roc_curve(y_true, y_pred) | |||||
roc_auc = metrics.auc(fpr, tpr) | |||||
plt.title('ROC') | |||||
plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc) | |||||
plt.legend(loc = 'lower right') | |||||
plt.ylabel('True Positive Rate') | |||||
plt.xlabel('False Positive Rate') | |||||
plt.show() |
@@ -0,0 +1,44 @@ | |||||
import numpy as np | |||||
from tods.tods_skinterface.primitiveSKI.detection_algorithm.IsolationForest_skinterface import IsolationForestSKI | |||||
from sklearn.metrics import precision_recall_curve | |||||
from sklearn.metrics import accuracy_score | |||||
from sklearn.metrics import confusion_matrix | |||||
from sklearn.metrics import classification_report | |||||
#prepare the data | |||||
data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt") | |||||
# print("shape:", data.shape) | |||||
# print("datatype of data:",data.dtype) | |||||
# print("First 5 rows:\n", data[:5]) | |||||
X_train = np.expand_dims(data[:10000], axis=1) | |||||
X_test = np.expand_dims(data[10000:], axis=1) | |||||
# print("First 5 rows train:\n", X_train[:5]) | |||||
# print("First 5 rows test:\n", X_test[:5]) | |||||
transformer = IsolationForestSKI() | |||||
transformer.fit(X_train) | |||||
prediction_labels_train = transformer.predict(X_train) | |||||
prediction_labels = transformer.predict(X_test) | |||||
prediction_score = transformer.predict_score(X_test) | |||||
print("Primitive: ", transformer.primitive) | |||||
print("Prediction Labels\n", prediction_labels) | |||||
print("Prediction Score\n", prediction_score) | |||||
y_true = prediction_labels_train | |||||
y_pred = prediction_labels | |||||
print('Accuracy Score: ', accuracy_score(y_true, y_pred)) | |||||
confusion_matrix(y_true, y_pred) | |||||
print(classification_report(y_true, y_pred)) | |||||
precision, recall, thresholds = precision_recall_curve(y_true, y_pred) | |||||
f1_scores = 2*recall*precision/(recall+precision) | |||||
print('Best threshold: ', thresholds[np.argmax(f1_scores)]) | |||||
print('Best F1-Score: ', np.max(f1_scores)) |
@@ -0,0 +1,37 @@ | |||||
import numpy as np | |||||
from tods.tods_skinterface.primitiveSKI.detection_algorithm.MatrixProfile_skinterface import MatrixProfileSKI | |||||
from sklearn.metrics import precision_recall_curve | |||||
from sklearn.metrics import accuracy_score | |||||
from sklearn.metrics import confusion_matrix | |||||
from sklearn.metrics import classification_report | |||||
#prepare the data | |||||
data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt") | |||||
X_train = np.expand_dims(data[:10000], axis=1) | |||||
X_test = np.expand_dims(data[10000:], axis=1) | |||||
transformer = MatrixProfileSKI() | |||||
transformer.fit(X_train) | |||||
prediction_labels_train = transformer.predict(X_train) | |||||
prediction_labels = transformer.predict(X_test) | |||||
prediction_score = transformer.predict_score(X_test) | |||||
print("Primitive: ", transformer.primitive) | |||||
print("Prediction Labels\n", prediction_labels) | |||||
print("Prediction Score\n", prediction_score) | |||||
y_true = prediction_labels_train | |||||
y_pred = prediction_labels | |||||
print('Accuracy Score: ', accuracy_score(y_true, y_pred)) | |||||
confusion_matrix(y_true, y_pred) | |||||
print(classification_report(y_true, y_pred)) | |||||
precision, recall, thresholds = precision_recall_curve(y_true, y_pred) | |||||
f1_scores = 2*recall*precision/(recall+precision) | |||||
print('Best threshold: ', thresholds[np.argmax(f1_scores)]) | |||||
print('Best F1-Score: ', np.max(f1_scores)) |
@@ -0,0 +1,54 @@ | |||||
import numpy as np | |||||
from tods.tods_skinterface.primitiveSKI.detection_algorithm.Telemanom_skinterface import TelemanomSKI | |||||
from sklearn.metrics import precision_recall_curve | |||||
from sklearn.metrics import accuracy_score | |||||
from sklearn.metrics import confusion_matrix | |||||
from sklearn.metrics import classification_report | |||||
import matplotlib.pyplot as plt | |||||
from sklearn import metrics | |||||
#prepare the data | |||||
data = np.loadtxt("./500_UCR_Anomaly_robotDOG1_10000_19280_19360.txt") | |||||
# print("shape:", data.shape) | |||||
# print("datatype of data:",data.dtype) | |||||
# print("First 5 rows:\n", data[:5]) | |||||
X_train = np.expand_dims(data[:10000], axis=1) | |||||
X_test = np.expand_dims(data[10000:], axis=1) | |||||
# print("First 5 rows train:\n", X_train[:5]) | |||||
# print("First 5 rows test:\n", X_test[:5]) | |||||
transformer = TelemanomSKI(l_s= 2, n_predictions= 1) | |||||
transformer.fit(X_train) | |||||
prediction_labels_train = transformer.predict(X_train) | |||||
prediction_labels = transformer.predict(X_test) | |||||
prediction_score = transformer.predict_score(X_test) | |||||
print("Primitive: ", transformer.primitive) | |||||
print("Prediction Labels\n", prediction_labels) | |||||
print("Prediction Score\n", prediction_score) | |||||
y_true = prediction_labels_train | |||||
y_pred = prediction_labels | |||||
print('Accuracy Score: ', accuracy_score(y_true, y_pred)) | |||||
confusion_matrix(y_true, y_pred) | |||||
print(classification_report(y_true, y_pred)) | |||||
precision, recall, thresholds = precision_recall_curve(y_true, y_pred) | |||||
f1_scores = 2*recall*precision/(recall+precision) | |||||
print('Best threshold: ', thresholds[np.argmax(f1_scores)]) | |||||
print('Best F1-Score: ', np.max(f1_scores)) | |||||
fpr, tpr, threshold = metrics.roc_curve(y_true, y_pred) | |||||
roc_auc = metrics.auc(fpr, tpr) | |||||
plt.title('ROC') | |||||
plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc) | |||||
plt.legend(loc = 'lower right') | |||||
plt.ylabel('True Positive Rate') | |||||
plt.xlabel('False Positive Rate') | |||||
plt.show() |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.CategoricalToBinary import CategoricalToBinaryPrimitive | |||||
class CategoricalToBinarySKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=CategoricalToBinaryPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.ContinuityValidation import ContinuityValidationPrimitive | |||||
class ContinuityValidationSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=ContinuityValidationPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.DuplicationValidation import DuplicationValidationPrimitive | |||||
class DuplicationValidationSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=DuplicationValidationPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.SKImputer import SKImputerPrimitive | |||||
class SKImputerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SKImputerPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.TimeIntervalTransform import TimeIntervalTransformPrimitive | |||||
class TimeIntervalTransformSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=TimeIntervalTransformPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.data_processing.TimeStampValidation import TimeStampValidationPrimitive | |||||
class TimeStampValidationSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=TimeStampValidationPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,46 @@ | |||||
import re | |||||
import os | |||||
with open('../utils/entry_points/entry_points_data_processing.txt','r',encoding='utf-8') as f: | |||||
entry_file = f.read() | |||||
output_dir = '../data_processing' | |||||
fit_available_primitives = ['SKImputerPrimitive'] | |||||
primitive_folder_start_loc_buf = [i.start()+2 for i in re.finditer('=', entry_file)] | |||||
primitive_start_loc_buf = [i.start()+1 for i in re.finditer(':', entry_file)] | |||||
primitive_end_loc_buf = [i.start() for i in re.finditer('\n', entry_file)] | |||||
for primitive_index, primitive_start_loc in enumerate(primitive_start_loc_buf): | |||||
primitive_folder_start_loc = primitive_folder_start_loc_buf[primitive_index] | |||||
primitive_end_loc = primitive_end_loc_buf[primitive_index] | |||||
primitive_folder = entry_file[primitive_folder_start_loc:primitive_start_loc-1] | |||||
primitive_name = entry_file[primitive_start_loc:primitive_end_loc] | |||||
# print(entry_file[primitive_folder_start_loc:primitive_start_loc-1]) | |||||
# print(entry_file[primitive_start_loc:primitive_end_loc]) | |||||
import_line1 = 'import numpy as np \nfrom ..base import BaseSKI\n' | |||||
import_line2 = 'from ' + primitive_folder + ' import ' + primitive_name + '\n\n' | |||||
# print(import_line) | |||||
class_name = primitive_name.replace('Primitive', 'SKI') | |||||
class_line1 = 'class ' + class_name + '(BaseSKI):\n\tdef __init__(self, **hyperparams):\n\t\tsuper().__init__(primitive=' | |||||
class_line2 = primitive_name + ', **hyperparams)\n' | |||||
if primitive_name in fit_available_primitives: | |||||
class_line3 = '\t\tself.fit_available = True\n\t\tself.predict_available = False\n\t\tself.produce_available = True\n' | |||||
else: | |||||
class_line3 = '\t\tself.fit_available = False\n\t\tself.predict_available = False\n\t\tself.produce_available = True\n' | |||||
python_content = import_line1 + import_line2 + class_line1 + class_line2 + class_line3 | |||||
python_name = primitive_name.replace('Primitive', '_skinterface.py') | |||||
with open(os.path.join(output_dir, python_name), 'w', encoding='utf-8') as f: | |||||
f.write(python_content) | |||||
print(os.path.join(output_dir, python_name)) | |||||
print(python_content) | |||||
@@ -0,0 +1,46 @@ | |||||
import re | |||||
import os | |||||
with open('../utils/entry_points/entry_points_timeseries_processing.txt','r',encoding='utf-8') as f: | |||||
entry_file = f.read() | |||||
output_dir = '../timeseries_processing' | |||||
fit_unavailable_primitives = ['SubsequenceSegmentationPrimitive', 'TimeSeriesSeasonalityTrendDecompositionPrimitive', 'SKAxiswiseScalerPrimitive'] | |||||
primitive_folder_start_loc_buf = [i.start()+2 for i in re.finditer('=', entry_file)] | |||||
primitive_start_loc_buf = [i.start()+1 for i in re.finditer(':', entry_file)] | |||||
primitive_end_loc_buf = [i.start() for i in re.finditer('\n', entry_file)] | |||||
for primitive_index, primitive_start_loc in enumerate(primitive_start_loc_buf): | |||||
primitive_folder_start_loc = primitive_folder_start_loc_buf[primitive_index] | |||||
primitive_end_loc = primitive_end_loc_buf[primitive_index] | |||||
primitive_folder = entry_file[primitive_folder_start_loc:primitive_start_loc-1] | |||||
primitive_name = entry_file[primitive_start_loc:primitive_end_loc] | |||||
# print(entry_file[primitive_folder_start_loc:primitive_start_loc-1]) | |||||
# print(entry_file[primitive_start_loc:primitive_end_loc]) | |||||
import_line1 = 'import numpy as np \nfrom ..base import BaseSKI\n' | |||||
import_line2 = 'from ' + primitive_folder + ' import ' + primitive_name + '\n\n' | |||||
# print(import_line) | |||||
class_name = primitive_name.replace('Primitive', 'SKI') | |||||
class_line1 = 'class ' + class_name + '(BaseSKI):\n\tdef __init__(self, **hyperparams):\n\t\tsuper().__init__(primitive=' | |||||
class_line2 = primitive_name + ', **hyperparams)\n' | |||||
if primitive_name in fit_unavailable_primitives: | |||||
class_line3 = '\t\tself.fit_available = False\n\t\tself.predict_available = False\n\t\tself.produce_available = True\n' | |||||
else: | |||||
class_line3 = '\t\tself.fit_available = True\n\t\tself.predict_available = False\n\t\tself.produce_available = True\n' | |||||
python_content = import_line1 + import_line2 + class_line1 + class_line2 + class_line3 | |||||
python_name = primitive_name.replace('Primitive', '_skinterface.py') | |||||
with open(os.path.join(output_dir, python_name), 'w', encoding='utf-8') as f: | |||||
f.write(python_content) | |||||
print(os.path.join(output_dir, python_name)) | |||||
print(python_content) | |||||
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.HoltSmoothing import HoltSmoothingPrimitive | |||||
class HoltSmoothingSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=HoltSmoothingPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.HoltWintersExponentialSmoothing import HoltWintersExponentialSmoothingPrimitive | |||||
class HoltWintersExponentialSmoothingSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=HoltWintersExponentialSmoothingPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.MovingAverageTransformer import MovingAverageTransformerPrimitive | |||||
class MovingAverageTransformerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=MovingAverageTransformerPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SKAxiswiseScaler import SKAxiswiseScalerPrimitive | |||||
class SKAxiswiseScalerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SKAxiswiseScalerPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SKPowerTransformer import SKPowerTransformerPrimitive | |||||
class SKPowerTransformerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SKPowerTransformerPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SKQuantileTransformer import SKQuantileTransformerPrimitive | |||||
class SKQuantileTransformerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SKQuantileTransformerPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SKStandardScaler import SKStandardScalerPrimitive | |||||
class SKStandardScalerSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SKStandardScalerPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SimpleExponentialSmoothing import SimpleExponentialSmoothingPrimitive | |||||
class SimpleExponentialSmoothingSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SimpleExponentialSmoothingPrimitive, **hyperparams) | |||||
self.fit_available = True | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.SubsequenceSegmentation import SubsequenceSegmentationPrimitive | |||||
class SubsequenceSegmentationSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=SubsequenceSegmentationPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,10 @@ | |||||
import numpy as np | |||||
from ..base import BaseSKI | |||||
from tods.timeseries_processing.TimeSeriesSeasonalityTrendDecomposition import TimeSeriesSeasonalityTrendDecompositionPrimitive | |||||
class TimeSeriesSeasonalityTrendDecompositionSKI(BaseSKI): | |||||
def __init__(self, **hyperparams): | |||||
super().__init__(primitive=TimeSeriesSeasonalityTrendDecompositionPrimitive, **hyperparams) | |||||
self.fit_available = False | |||||
self.predict_available = False | |||||
self.produce_available = True |
@@ -0,0 +1,6 @@ | |||||
tods.data_processing.time_interval_transform = tods.data_processing.TimeIntervalTransform:TimeIntervalTransformPrimitive | |||||
tods.data_processing.categorical_to_binary = tods.data_processing.CategoricalToBinary:CategoricalToBinaryPrimitive | |||||
tods.data_processing.timestamp_validation = tods.data_processing.TimeStampValidation:TimeStampValidationPrimitive | |||||
tods.data_processing.duplication_validation = tods.data_processing.DuplicationValidation:DuplicationValidationPrimitive | |||||
tods.data_processing.continuity_validation = tods.data_processing.ContinuityValidation:ContinuityValidationPrimitive | |||||
tods.data_processing.impute_missing = tods.data_processing.SKImputer:SKImputerPrimitive |
@@ -0,0 +1,10 @@ | |||||
tods.timeseries_processing.transformation.axiswise_scaler = tods.timeseries_processing.SKAxiswiseScaler:SKAxiswiseScalerPrimitive | |||||
tods.timeseries_processing.transformation.standard_scaler = tods.timeseries_processing.SKStandardScaler:SKStandardScalerPrimitive | |||||
tods.timeseries_processing.transformation.power_transformer = tods.timeseries_processing.SKPowerTransformer:SKPowerTransformerPrimitive | |||||
tods.timeseries_processing.transformation.quantile_transformer = tods.timeseries_processing.SKQuantileTransformer:SKQuantileTransformerPrimitive | |||||
tods.timeseries_processing.transformation.moving_average_transform = tods.timeseries_processing.MovingAverageTransformer:MovingAverageTransformerPrimitive | |||||
tods.timeseries_processing.transformation.simple_exponential_smoothing = tods.timeseries_processing.SimpleExponentialSmoothing:SimpleExponentialSmoothingPrimitive | |||||
tods.timeseries_processing.transformation.holt_smoothing = tods.timeseries_processing.HoltSmoothing:HoltSmoothingPrimitive | |||||
tods.timeseries_processing.transformation.subsequence_segmentation = tods.timeseries_processing.SubsequenceSegmentation:SubsequenceSegmentationPrimitive | |||||
tods.timeseries_processing.transformation.holt_winters_exponential_smoothing = tods.timeseries_processing.HoltWintersExponentialSmoothing:HoltWintersExponentialSmoothingPrimitive | |||||
tods.timeseries_processing.decomposition.time_series_seasonality_trend_decomposition = tods.timeseries_processing.TimeSeriesSeasonalityTrendDecomposition:TimeSeriesSeasonalityTrendDecompositionPrimitive |