Skip to content

Commit

Permalink
Added clips to avoid division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
sidchaini committed Mar 13, 2024
1 parent 953fed9 commit 08b2383
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions distclassipy/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ def predict_and_analyse(self, X: np.array):
sum_1d_dists = sum_1d_dists + dists / self.df_iqr_.loc[cl, feat]
else:
sum_1d_dists = sum_1d_dists + dists
confs = 1 / sum_1d_dists
# Add epsilon later
# confs = 1 / (sum_1d_dists + np.finfo(float).eps)
confs = 1 / np.clip(sum_1d_dists, a_min=np.finfo(float).eps, a_max=None)
conf_cl.append(confs)
conf_cl = np.array(conf_cl)
self.conf_cl_ = conf_cl
Expand Down Expand Up @@ -388,7 +386,9 @@ def calculate_confidence(self, method: str = "distance_inverse"):

# Calculate confidence for each prediction
if method == "distance_inverse":
self.confidence_df_ = 1 / self.centroid_dist_df_
self.confidence_df_ = 1 / np.clip(
self.centroid_dist_df_, a_min=np.finfo(float).eps, a_max=None
)
self.confidence_df_.columns = [
x.replace("_dist", "_conf") for x in self.confidence_df_.columns
]
Expand Down

0 comments on commit 08b2383

Please sign in to comment.