Skip to content

Commit

Permalink
Fix nan condition for confusion matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-nml committed Jun 16, 2023
1 parent 34fbe41 commit 887b461
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def _calculate_true_positives(self, data: pd.DataFrame) -> float:
)

y_true, y_pred = _common_data_cleaning(y_true, y_pred)
if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
if y_true.empty or y_pred.empty:
return np.nan

num_tp = np.sum(np.logical_and(y_pred, y_true))
Expand Down Expand Up @@ -772,7 +772,7 @@ def _calculate_true_negatives(self, data: pd.DataFrame) -> float:
)

y_true, y_pred = _common_data_cleaning(y_true, y_pred)
if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
if y_true.empty or y_pred.empty:
return np.nan

num_tn = np.sum(np.logical_and(np.logical_not(y_pred), np.logical_not(y_true)))
Expand Down Expand Up @@ -800,7 +800,7 @@ def _calculate_false_positives(self, data: pd.DataFrame) -> float:
)

y_true, y_pred = _common_data_cleaning(y_true, y_pred)
if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
if y_true.empty or y_pred.empty:
return np.nan

num_fp = np.sum(np.logical_and(y_pred, np.logical_not(y_true)))
Expand Down Expand Up @@ -828,7 +828,7 @@ def _calculate_false_negatives(self, data: pd.DataFrame) -> float:
)

y_true, y_pred = _common_data_cleaning(y_true, y_pred)
if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
if y_true.empty or y_pred.empty:
return np.nan

num_fn = np.sum(np.logical_and(np.logical_not(y_pred), y_true))
Expand Down

0 comments on commit 887b461

Please sign in to comment.