Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: LOF with QuantileFilter raises IndexError #1330

Merged
merged 8 commits into from
Oct 10, 2023
20 changes: 11 additions & 9 deletions river/anomaly/lof.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import copy
import functools

import pandas as pd
Expand Down Expand Up @@ -342,10 +343,11 @@ def score_one(self, x: dict):
self.x_scores.append(x)
self.x_scores, equal = check_equal(self.x_scores, self.x_list)

if len(self.x_scores) == 0:
return None
if len(self.x_scores) == 0 or len(self.x_list) == 0:
return 0.5
MarekWadinger marked this conversation as resolved.
Show resolved Hide resolved

x_list_copy = self.x_list.copy()

(
nm,
x_list_copy,
Expand All @@ -359,13 +361,13 @@ def score_one(self, x: dict):
) = expand_objects(
self.x_scores,
x_list_copy,
self.neighborhoods,
self.rev_neighborhoods,
self.k_dist,
self.reach_dist,
self.dist_dict,
self.local_reach,
self.lof,
self.neighborhoods.copy(),
self.rev_neighborhoods.copy(),
self.k_dist.copy(),
copy.deepcopy(self.reach_dist),
copy.deepcopy(self.dist_dict),
self.local_reach.copy(),
self.lof.copy(),
)

neighborhoods, rev_neighborhoods, k_dist, dist_dict = self._initial_calculations(
Expand Down
Loading