def is_anomaly(adl_dataset, adl_data_test): # At train time lsanomaly calculates parameters rho and sigma lsanomaly = LSAnomaly(sigma=3, rho=0.1) res = np.reshape((adl_dataset), (-1, 1)) lsanomaly.fit(res) res_test = np.reshape((adl_data_test), (-1, 1)) predit_res = lsanomaly.predict(res_test) return predit_res, lsanomaly.predict_proba( res_test) # predicted result and probability of the result
def test_example_doc(doc_arrays, check_ndarray): test_pt = np.array([[0]]) x_train, predict_prob = doc_arrays anomaly_model = LSAnomaly(sigma=3, rho=0.1, seed=42) anomaly_model.fit(x_train) expected = [0.0] p = anomaly_model.predict(test_pt) assert p == expected expected = np.array([[0.7231233, 0.2768767]]) p = anomaly_model.predict_proba(test_pt) logger.debug("p = {}".format(p)) check_ndarray(expected, p)