Skip to content

Commit

Permalink
auroc realized perf nan handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nikml committed Apr 16, 2024
1 parent b7a566b commit d19353d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ def _fit(self, reference_data: pd.DataFrame):
def _calculate(self, data: pd.DataFrame):
"""Redefine to handle NaNs and edge cases."""
_list_missing([self.y_true, self.y_pred_proba], list(data.columns))
data = _remove_nans(data, [self.y_true, self.y_pred_proba])
data = data[[self.y_true, self.y_pred_proba]]
data, empty = common_nan_removal(data, [self.y_true, self.y_pred_proba])
if empty:
return np.NaN

y_true = data[self.y_true]
y_pred_proba = data[self.y_pred_proba]

if y_true.nunique() <= 1:
warnings.warn(
f"'{self.y_true}' only contains a single class for chunk, cannot calculate {self.display_name}. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ def test_auroc_sampling_error():
assert np.round(sampling_error, 4) == 0.0575


def test_auroc_sampling_error_nan():
np.random.seed(1)
sample_size = 50
chunk = np.random.random(sample_size)

components = np.NaN, np.NaN
sampling_error = bse.auroc_sampling_error(components, chunk)
assert np.isnan(sampling_error)

def test_f1_sampling_error():
np.random.seed(1)
sample_size = 50
Expand Down

0 comments on commit d19353d

Please sign in to comment.