mlquantify 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mlquantify-0.1.1 → mlquantify-0.1.2}/PKG-INFO +1 -1
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/threshold_optimization.py +75 -12
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/PKG-INFO +1 -1
- {mlquantify-0.1.1 → mlquantify-0.1.2}/setup.py +1 -1
- {mlquantify-0.1.1 → mlquantify-0.1.2}/README.md +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/__init__.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/base.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/classification/__init__.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/classification/methods.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/__init__.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/measures.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/protocol.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/__init__.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/aggregative.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/meta.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/mixture_models.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/non_aggregative.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/model_selection.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/plots.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/__init__.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/general.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/method.py +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/SOURCES.txt +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/dependency_links.txt +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/requires.txt +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/top_level.txt +0 -0
- {mlquantify-0.1.1 → mlquantify-0.1.2}/setup.cfg +0 -0
|
@@ -447,9 +447,8 @@ class MS(ThresholdOptimization):
|
|
|
447
447
|
{0: 0.3991228070175439, 1: 0.6008771929824561}
|
|
448
448
|
"""
|
|
449
449
|
|
|
450
|
-
def __init__(self, learner: BaseEstimator=None
|
|
450
|
+
def __init__(self, learner: BaseEstimator=None):
|
|
451
451
|
super().__init__(learner)
|
|
452
|
-
self.threshold = threshold
|
|
453
452
|
|
|
454
453
|
def best_tprfpr(self, thresholds: np.ndarray, tprs: np.ndarray, fprs: np.ndarray) -> tuple:
|
|
455
454
|
"""
|
|
@@ -482,11 +481,42 @@ class MS(ThresholdOptimization):
|
|
|
482
481
|
ValueError
|
|
483
482
|
If `thresholds`, `tprs`, or `fprs` are empty or have mismatched lengths.
|
|
484
483
|
"""
|
|
485
|
-
# Compute median TPR and FPR
|
|
486
|
-
tpr = np.median(tprs)
|
|
487
|
-
fpr = np.median(fprs)
|
|
488
484
|
|
|
489
|
-
return (
|
|
485
|
+
return (thresholds, tprs, fprs)
|
|
486
|
+
|
|
487
|
+
def _predict_method(self, X) -> dict:
|
|
488
|
+
"""
|
|
489
|
+
Predicts class prevalences using the adjusted threshold.
|
|
490
|
+
|
|
491
|
+
Parameters
|
|
492
|
+
----------
|
|
493
|
+
X : pd.DataFrame or np.ndarray
|
|
494
|
+
The input features for prediction.
|
|
495
|
+
|
|
496
|
+
Returns
|
|
497
|
+
-------
|
|
498
|
+
np.ndarray
|
|
499
|
+
An array of predicted prevalences for the classes.
|
|
500
|
+
"""
|
|
501
|
+
# Get predicted probabilities for the positive class
|
|
502
|
+
probabilities = self.predict_learner(X)[:, 1]
|
|
503
|
+
|
|
504
|
+
prevs = []
|
|
505
|
+
|
|
506
|
+
for thr, tpr, fpr in zip(self.threshold, self.tpr, self.fpr):
|
|
507
|
+
cc_output = len(probabilities[probabilities >= thr]) / len(probabilities)
|
|
508
|
+
|
|
509
|
+
if tpr - fpr == 0:
|
|
510
|
+
prevalence = cc_output
|
|
511
|
+
else:
|
|
512
|
+
prev = np.clip((cc_output - fpr) / (tpr - fpr), 0, 1)
|
|
513
|
+
prevs.append(prev)
|
|
514
|
+
|
|
515
|
+
prevalence = np.median(prevs)
|
|
516
|
+
|
|
517
|
+
prevalences = [1 - prevalence, prevalence]
|
|
518
|
+
|
|
519
|
+
return np.asarray(prevalences)
|
|
490
520
|
|
|
491
521
|
|
|
492
522
|
|
|
@@ -586,15 +616,48 @@ class MS2(ThresholdOptimization):
|
|
|
586
616
|
# Identify indices where the condition is satisfied
|
|
587
617
|
indices = np.where(np.abs(tprs - fprs) > 0.25)[0]
|
|
588
618
|
if len(indices) == 0:
|
|
589
|
-
|
|
619
|
+
warnings.warn("No cases satisfy the condition |TPR - FPR| > 0.25.")
|
|
620
|
+
indices = np.where(np.abs(tprs - fprs) >= 0)[0]
|
|
621
|
+
|
|
622
|
+
thresholds_ = thresholds[indices]
|
|
623
|
+
tprs_ = tprs[indices]
|
|
624
|
+
fprs_ = fprs[indices]
|
|
590
625
|
|
|
591
|
-
|
|
592
|
-
threshold = np.median(thresholds[indices])
|
|
593
|
-
tpr = np.median(tprs[indices])
|
|
594
|
-
fpr = np.median(fprs[indices])
|
|
626
|
+
return (thresholds_, tprs_, fprs_)
|
|
595
627
|
|
|
596
|
-
|
|
628
|
+
def _predict_method(self, X) -> dict:
|
|
629
|
+
"""
|
|
630
|
+
Predicts class prevalences using the adjusted threshold.
|
|
597
631
|
|
|
632
|
+
Parameters
|
|
633
|
+
----------
|
|
634
|
+
X : pd.DataFrame or np.ndarray
|
|
635
|
+
The input features for prediction.
|
|
636
|
+
|
|
637
|
+
Returns
|
|
638
|
+
-------
|
|
639
|
+
np.ndarray
|
|
640
|
+
An array of predicted prevalences for the classes.
|
|
641
|
+
"""
|
|
642
|
+
# Get predicted probabilities for the positive class
|
|
643
|
+
probabilities = self.predict_learner(X)[:, 1]
|
|
644
|
+
|
|
645
|
+
prevs = []
|
|
646
|
+
|
|
647
|
+
for thr, tpr, fpr in zip(self.threshold, self.tpr, self.fpr):
|
|
648
|
+
cc_output = len(probabilities[probabilities >= thr]) / len(probabilities)
|
|
649
|
+
|
|
650
|
+
if tpr - fpr == 0:
|
|
651
|
+
prevalence = cc_output
|
|
652
|
+
else:
|
|
653
|
+
prev = np.clip((cc_output - fpr) / (tpr - fpr), 0, 1)
|
|
654
|
+
prevs.append(prev)
|
|
655
|
+
|
|
656
|
+
prevalence = np.median(prevs)
|
|
657
|
+
|
|
658
|
+
prevalences = [1 - prevalence, prevalence]
|
|
659
|
+
|
|
660
|
+
return np.asarray(prevalences)
|
|
598
661
|
|
|
599
662
|
class PACC(ThresholdOptimization):
|
|
600
663
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|