Skip to content

Commit

Permalink
Remove errors and use warning behaviour instead
Browse files Browse the repository at this point in the history
The performance calculator for binary classification had checks in place
to generate an exception if the prediction column contains nothing but
`NaN`'s. This behaviour contradicts the warning functionality that is in
the same functions that would should return `NaN` and issue a warning.
It is also inconsistent with other calculators which do issue a warning
instead of raising an error.

This commit removes the errors and relies on the existing warning
functionality.
  • Loading branch information
michael-nml committed Nov 19, 2023
1 parent a0e5b4e commit de16772
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions nannyml/performance_calculation/metrics/binary_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,6 @@ def _calculate(self, data: pd.DataFrame):
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
f"could not calculate metric {self.display_name}: " "prediction column contains no data"
)

if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
warnings.warn("Calculated Specificity score contains NaN values.")
return np.nan
Expand Down Expand Up @@ -440,11 +435,6 @@ def _calculate(self, data: pd.DataFrame):
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
f"could not calculate metric '{self.display_name}': " "prediction column contains no data"
)

if (y_true.nunique() <= 1) or (y_pred.nunique() <= 1):
warnings.warn("Calculated Accuracy score contains NaN values.")
return np.nan
Expand Down Expand Up @@ -546,14 +536,6 @@ def _calculate(self, data: pd.DataFrame):
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
f"could not calculate metric '{self.name}': " "prediction column contains no data"
)

if y_true is None:
warnings.warn("Calculated Business Value contains NaN values.")
return np.NaN
if y_true.shape[0] == 0:
warnings.warn("Calculated Business Value contains NaN values.")
return np.NaN
Expand Down Expand Up @@ -742,11 +724,6 @@ def _calculate_true_positives(self, data: pd.DataFrame) -> float:
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
"could not calculate metric true_positive. prediction column contains no data"
)

if y_true.empty or y_pred.empty:
warnings.warn("Calculated true_positives contain NaN values.")
return np.nan
Expand All @@ -771,11 +748,6 @@ def _calculate_true_negatives(self, data: pd.DataFrame) -> float:
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
"could not calculate metric true_negative. prediction column contains no data"
)

if y_true.empty or y_pred.empty:
warnings.warn("Calculated true_negatives contain NaN values.")
return np.nan
Expand All @@ -800,10 +772,6 @@ def _calculate_false_positives(self, data: pd.DataFrame) -> float:
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
"could not calculate metric false_positive. prediction column contains no data"
)
if y_true.empty or y_pred.empty:
warnings.warn("Calculated false_positives contain NaN values.")
return np.nan
Expand All @@ -828,11 +796,6 @@ def _calculate_false_negatives(self, data: pd.DataFrame) -> float:
y_true = data[self.y_true]
y_pred = data[self.y_pred]

if y_pred.isna().all():
raise InvalidArgumentsException(
"could not calculate metric false_negative. prediction column contains no data"
)

if y_true.empty or y_pred.empty:
warnings.warn("Calculated false_negatives contain NaN values.")
return np.nan
Expand Down

0 comments on commit de16772

Please sign in to comment.