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

Use math.isclose Instead of Direct Equality for Floats #453

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sigopt/xgboost/compute_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright © 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
import math

import numpy

from .compat import Booster
Expand Down Expand Up @@ -35,7 +37,7 @@ def compute_classification_report(y_true, y_pred):
tp, _, fp, fn = compute_positives_and_negatives(y_true, y_pred, class_label)
precision = tp / (tp + fp) if (tp + fp) != 0 else 0
recall = tp / (tp + fn) if (tp + fn) != 0 else 0
f1 = tp / (tp + 0.5 * (fp + fn)) if (tp + 0.5 * (fp + fn)) != 0 else 0
f1 = tp / (tp + 0.5 * (fp + fn)) if not math.isclose((tp + 0.5 * (fp + fn)), 0, rel_tol=1e-09, abs_tol=0.0) else 0
support = numpy.count_nonzero(y_true == class_label)
classification_report[str(class_label)] = {
"precision": precision,
Expand Down