Skip to content

Commit

Permalink
Update _kdey.py
Browse files Browse the repository at this point in the history
fix in KDEy: makes the method robust to cases in which the number of positives for any class is smaller than the number k of folds. In such cases, the kde for that class is created from the uniform prevalence vector
  • Loading branch information
AlexMoreo authored Apr 19, 2024
1 parent e6f380d commit bf33c13
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions quapy/method/_kdey.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def get_mixture_components(self, X, y, classes, bandwidth):
:param bandwidth: float, the bandwidth of the kernel
:return: a list of KernelDensity objects, each fitted with the corresponding class-specific covariates
"""
return [self.get_kde_function(X[y == cat], bandwidth) for cat in classes]

class_cond_X = []
for cat in classes:
selX = X[y==cat]
if selX.size==0:
selX = [F.uniform_prevalence(len(classes))]
class_cond_X.append(selX)
return [self.get_kde_function(X_cond_yi, bandwidth) for X_cond_yi in class_cond_X]


class KDEyML(AggregativeSoftQuantifier, KDEBase):
Expand Down

0 comments on commit bf33c13

Please sign in to comment.