Пример #1
0
    def __init__(self,
                 w_martingale=15,
                 non_conformity="median",
                 k=20,
                 dev_threshold=0.6,
                 ref_group="month"):
        utils.validate_individual_deviation_params(w_martingale,
                                                   non_conformity, k,
                                                   dev_threshold, ref_group)

        self.w_martingale = w_martingale
        self.non_conformity = non_conformity
        self.k = k
        self.dev_threshold = dev_threshold
        self.ref_group = ref_group

        self.strg = Strangeness(non_conformity, k)
        self.scores = []
        self.T, self.S, self.P, self.M = [], [], [], []

        self.mart = 0
        self.marts = [0, 0, 0]

        self.df = pd.DataFrame(data=[], index=[])
        self.externals = []
Пример #2
0
 def test_strangeness_median_fit(self):
     strg = Strangeness(measure="median", k=10)
     X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
     strg.fit(X)
     self.assertTrue(strg.h.med is not None)
     self.assertTrue(np.allclose(strg.h.med, [4, 5, 6]))
     self.assertEqual(strg.get([1, 2, 3]), 27**0.5)
Пример #3
0
    def test_strangeness_fit_input_wrong(self):
        strg = Strangeness(measure="median", k=10)

        with self.assertRaises(InputValidationError):
            strg.fit([])

        with self.assertRaises(InputValidationError):
            strg.fit("foo")
Пример #4
0
    def test_strangeness_predict_input_wrong(self):
        strg = Strangeness(measure="median", k=10)
        X = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
        strg.fit(X)

        with self.assertRaises(InputValidationError):
            strg.get([])

        with self.assertRaises(InputValidationError):
            strg.get("foo")
Пример #5
0
 def test_strangeness_knn_fit(self):
     strg = Strangeness(measure="knn", k=2)
     X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
     strg.fit(X)
     self.assertTrue(strg.h.X is not None)
     self.assertEqual(strg.get([7, 8, 9]), 27**0.5 / 2)
Пример #6
0
 def test_strangeness_knn_not_fitted(self):
     with self.assertRaises(NotFittedError):
         strg = Strangeness(measure="knn", k=10)
         strg.get([1, 2, 3])
Пример #7
0
 def test_strangeness_wrong_measure(self):
     with self.assertRaises(InputValidationError):
         strg = Strangeness(measure="foo", k=10)
Пример #8
0
 def test_strangeness_knn_wrong_k(self):
     with self.assertRaises(InputValidationError):
         strg = Strangeness(measure="knn", k=0)
Пример #9
0
 def test_strangeness_knn_general(self):
     strg = Strangeness(measure="knn", k=10)
     self.assertEqual(strg.h.X, None)
     self.assertFalse(strg.is_fitted())
Пример #10
0
 def test_strangeness_median_general(self):
     strg = Strangeness(measure="median", k=10)
     self.assertEqual(strg.h.med, None)
     self.assertFalse(strg.is_fitted())