code: def test_incremental_lof_scores():
      """
      Test that the incremental LOF algorithm returns similar LOF scores for each observation
      compared with the original static LOF algorithm implemented in scikit-learn.
      """
      norm_dist = 0.5 * np.random.rand(100, 2)
      x_inliers = np.concatenate(
          (norm_dist - 2, norm_dist, norm_dist + 2), axis=0
      )
      x_outliers = np.concatenate(
          (
              np.random.uniform(low=-4, high=4, size=(20, 2)),
              np.random.uniform(low=-10, high=-5, size=(10, 2)),
              np.random.uniform(low=5, high=10, size=(10, 2)),
          ),
          axis=0,
      )
      x_train = np.concatenate((x_inliers, x_outliers), axis=0)
      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}
      )
      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_pred = []
      for x in x_pred_dict:
          ilof_scores_pred.append(incremental_lof.score_one(x))
  
      lof_sklearn = neighbors.LocalOutlierFactor(n_neighbors=20)
      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,
      )
  
file_path: river/river/anomaly/test_lof.py
imports: from __future__ import annotations
  import numpy
  import pandas
  from sklearn import neighbors
  from river import anomaly, datasets
label_desc: Use image node_id 1 for calling a global function with example usage: test_incremental_lof_scores() without return types