Browse Source

fix skitest of KDiscord, PCA, Telemenom

master
lhenry15 4 years ago
parent
commit
7804184f7d
4 changed files with 18 additions and 49 deletions
  1. +3
    -1
      tods/tests/sk_interface/detection_algorithm/test_ski_KDiscordODetector.py
  2. +3
    -1
      tods/tests/sk_interface/detection_algorithm/test_ski_PCAODetector.py
  3. +0
    -46
      tods/tests/sk_interface/detection_algorithm/test_ski_SystemWiseDetection.py
  4. +12
    -1
      tods/tests/sk_interface/detection_algorithm/test_ski_Telemanom.py

+ 3
- 1
tods/tests/sk_interface/detection_algorithm/test_ski_KDiscordODetector.py View File

@@ -25,11 +25,13 @@ class KDiscordODetectorSKI_TestCase(unittest.TestCase):
self.n_test = 100
self.contamination = 0.1
self.roc_floor = 0.0
self.window_size = 5
self.X_train, self.y_train, self.X_test, self.y_test = generate_data(
n_train=self.n_train, n_test=self.n_test,
contamination=self.contamination, random_state=42)

self.transformer = KDiscordODetectorSKI(contamination=self.contamination)
self.transformer = KDiscordODetectorSKI(contamination=self.contamination, window_size=self.window_size)
self.y_test = self.y_test[self.window_size-1:]
self.transformer.fit(self.X_train)

def test_prediction_labels(self):


+ 3
- 1
tods/tests/sk_interface/detection_algorithm/test_ski_PCAODetector.py View File

@@ -25,11 +25,13 @@ class PCAODetectorSKI_TestCase(unittest.TestCase):
self.n_test = 100
self.contamination = 0.1
self.roc_floor = 0.0
self.window_size = 5
self.X_train, self.y_train, self.X_test, self.y_test = generate_data(
n_train=self.n_train, n_test=self.n_test,
contamination=self.contamination, random_state=42)

self.transformer = PCAODetectorSKI(contamination=self.contamination)
self.transformer = PCAODetectorSKI(contamination=self.contamination, window_size=self.window_size)
self.y_test = self.y_test[self.window_size-1:]
self.transformer.fit(self.X_train)

def test_prediction_labels(self):


+ 0
- 46
tods/tests/sk_interface/detection_algorithm/test_ski_SystemWiseDetection.py View File

@@ -1,46 +0,0 @@
import numpy as np
import pandas as pd
import os
from tods.sk_interface.detection_algorithm.SystemWiseDetection_skinterface import SystemWiseDetectionSKI

from pyod.utils.data import generate_data
import unittest
from numpy.testing import assert_allclose
from numpy.testing import assert_array_less
from unittest import TestCase
from sklearn.metrics import roc_auc_score

class SystemWiseDetectionSKI_TestCase(unittest.TestCase):
def setUp(self):

_dummy = TestCase('__init__')
self.assert_greater_equal = _dummy.assertGreaterEqual
self.assert_greater = _dummy.assertGreater
self.assert_less_equal = _dummy.assertLessEqual
self.assert_less = _dummy.assertLess
self.assert_equal = _dummy.assertEqual

self.maxDiff = None
self.n_train = 200
self.n_test = 100
self.contamination = 0.1
self.roc_floor = 0.0
self.X_train, self.y_train, self.X_test, self.y_test = generate_data(
n_train=self.n_train, n_test=self.n_test,
contamination=self.contamination, random_state=42)

self.transformer = SystemWiseDetectionSKI(contamination=self.contamination)
self.transformer.fit(self.X_train)

def test_prediction_labels(self):
pred_labels = self.transformer.predict(self.X_test)
self.assert_equal(pred_labels.shape[0], self.y_test.shape[0])

def test_prediction_score(self):
pred_scores = self.transformer.predict_score(self.X_test)
self.assert_equal(pred_scores.shape[0], self.y_test.shape[0])
self.assert_greater_equal(roc_auc_score(self.y_test, pred_scores), self.roc_floor)


if __name__ == '__main__':
unittest.main()

+ 12
- 1
tods/tests/sk_interface/detection_algorithm/test_ski_Telemanom.py View File

@@ -27,10 +27,21 @@ class TelemanomSKI_TestCase(unittest.TestCase):
self.roc_floor = 0.0
self.X_train, self.y_train, self.X_test, self.y_test = generate_data(
n_train=self.n_train, n_test=self.n_test,
contamination=self.contamination, random_state=42)
contamination=self.contamination, random_state=42, n_features=3)

self.transformer = TelemanomSKI(contamination=self.contamination)
self.transformer.fit(self.X_train)
self.l_s = 5
self.n_predictions = 1
self.X_train, self.y_train, self.X_test, self.y_test = generate_data(
n_train=self.n_train, n_test=self.n_test,
contamination=self.contamination, random_state=42)

self.transformer = TelemanomSKI(contamination=self.contamination, l_s=self.l_s, n_predictions=self.n_predictions)

self.y_test = self.y_test[self.l_s:-self.n_predictions]
self.y_train = self.y_train[self.l_s:-self.n_predictions]
self.transformer.fit(self.X_train)

def test_prediction_labels(self):
pred_labels = self.transformer.predict(self.X_test)


Loading…
Cancel
Save