Skip to content

Commit 1beb189

Browse files
committed
Fix relative error calculations to ensure absolute values are used
1 parent ce48301 commit 1beb189

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Scripts/utils/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def basic_error(df: pd.DataFrame) -> pd.Series:
320320
def absolute_error(df: pd.DataFrame) -> pd.Series:
321321
return (df["prediction"] - df["expected"]).abs()
322322
def relative_error(df: pd.DataFrame) -> pd.Series:
323-
return (df["prediction"] - df["expected"]) / df["expected"]
323+
return (df["prediction"] - df["expected"]).abs() / df["expected"].abs()
324324
def squared_error(df: pd.DataFrame) -> pd.Series:
325325
return (df["prediction"] - df["expected"]) ** 2
326326

@@ -341,7 +341,7 @@ def max_error(df: pd.DataFrame) -> float:
341341
def mean_error(df: pd.DataFrame) -> float:
342342
return ((df["prediction"] - df["expected"]) * df['weight']).mean()
343343
def relative_error(df: pd.DataFrame) -> float:
344-
return ((df["prediction"] - df["expected"]) / df["expected"] * df['weight']).mean()
344+
return ((df["prediction"] - df["expected"]).abs() / df["expected"].abs() * df['weight']).mean()
345345

346346
def mean(source: str):
347347
return lambda df: df[source].mean()

0 commit comments

Comments
 (0)