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
This commit is contained in:
parent
e6f380dc5f
commit
bf33c134fc
|
@ -62,8 +62,13 @@ class KDEBase:
|
||||||
:param bandwidth: float, the bandwidth of the kernel
|
:param bandwidth: float, the bandwidth of the kernel
|
||||||
:return: a list of KernelDensity objects, each fitted with the corresponding class-specific covariates
|
: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):
|
class KDEyML(AggregativeSoftQuantifier, KDEBase):
|
||||||
|
|
Loading…
Reference in New Issue