Skip to content

Commit

Permalink
Update test_lof.py
Browse files Browse the repository at this point in the history
Revert unnecessary changes to code style.
  • Loading branch information
hoanganhngo610 authored Mar 18, 2024
1 parent 9094f82 commit ebd98d8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions river/anomaly/test_lof.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@ def test_incremental_lof_scores():
x_train_dict = [{f"feature_{i + 1}": elem[i] for i in range(2)} for elem in x_train]
ground_truth = np.ones(len(x_train), dtype=int)
ground_truth[-len(x_outliers) :] = -1
df_train = pd.DataFrame(
{"observations": x_train_dict, "ground_truth": ground_truth}
)
df_train = pd.DataFrame({"observations": x_train_dict, "ground_truth": ground_truth})
x_pred = np.random.uniform(low=-5, high=5, size=(30, 2))
x_pred_dict = [{f"feature_{i + 1}": elem[i] for i in range(2)} for elem in x_pred]
incremental_lof = anomaly.LocalOutlierFactor(n_neighbors=20)

for x in df_train["observations"]:
incremental_lof.learn_one(x)

ilof_scores_train = np.array(
[ilof_score for ilof_score in incremental_lof.lof.values()]
)
ilof_scores_train = np.array([ilof_score for ilof_score in incremental_lof.lof.values()])

ilof_scores_pred = []
for x in x_pred_dict:
Expand All @@ -50,9 +46,7 @@ def test_incremental_lof_scores():
lof_sklearn.fit_predict(x_train)
lof_sklearn_scores_train = -lof_sklearn.negative_outlier_factor_

assert np.allclose(
ilof_scores_train, lof_sklearn_scores_train, rtol=1e-08, atol=1e-08
)
assert np.allclose(ilof_scores_train, lof_sklearn_scores_train, rtol=1e-08, atol=1e-08)


def test_batch_lof_scores():
Expand Down

0 comments on commit ebd98d8

Please sign in to comment.