From bf33c134fc80bd79d9d4d7b7bcba41c939b70d15 Mon Sep 17 00:00:00 2001 From: Alejandro Moreo Date: Fri, 19 Apr 2024 14:23:35 +0200 Subject: [PATCH] Update _kdey.py 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 --- quapy/method/_kdey.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/quapy/method/_kdey.py b/quapy/method/_kdey.py index a6ecbea..e678563 100644 --- a/quapy/method/_kdey.py +++ b/quapy/method/_kdey.py @@ -62,8 +62,13 @@ class KDEBase: :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):