mlquantify 0.1.0__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.0 → mlquantify-0.1.2}/PKG-INFO +3 -3
- {mlquantify-0.1.0 → mlquantify-0.1.2}/README.md +1 -1
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/threshold_optimization.py +82 -21
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/model_selection.py +1 -1
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify.egg-info/PKG-INFO +3 -3
- {mlquantify-0.1.0 → mlquantify-0.1.2}/setup.py +1 -1
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/__init__.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/base.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/classification/__init__.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/classification/methods.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/evaluation/__init__.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/evaluation/measures.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/evaluation/protocol.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/__init__.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/aggregative.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/meta.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/mixture_models.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/methods/non_aggregative.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/plots.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/utils/__init__.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/utils/general.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify/utils/method.py +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify.egg-info/SOURCES.txt +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify.egg-info/dependency_links.txt +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify.egg-info/requires.txt +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/mlquantify.egg-info/top_level.txt +0 -0
- {mlquantify-0.1.0 → mlquantify-0.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: mlquantify
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Quantification Library
|
|
5
5
|
Home-page: https://github.com/luizfernandolj/QuantifyML/tree/master
|
|
6
6
|
Maintainer: Luiz Fernando Luth Junior
|
|
@@ -58,7 +58,7 @@ pip install mlquantify
|
|
|
58
58
|
If you only want to update, run the code below:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
pip install --
|
|
61
|
+
pip install --upgrade mlquantify
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
___
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
2
|
import numpy as np
|
|
3
|
+
import warnings
|
|
3
4
|
from sklearn.base import BaseEstimator
|
|
4
5
|
|
|
5
6
|
from ..base import AggregativeQuantifier
|
|
@@ -446,9 +447,8 @@ class MS(ThresholdOptimization):
|
|
|
446
447
|
{0: 0.3991228070175439, 1: 0.6008771929824561}
|
|
447
448
|
"""
|
|
448
449
|
|
|
449
|
-
def __init__(self, learner: BaseEstimator=None
|
|
450
|
+
def __init__(self, learner: BaseEstimator=None):
|
|
450
451
|
super().__init__(learner)
|
|
451
|
-
self.threshold = threshold
|
|
452
452
|
|
|
453
453
|
def best_tprfpr(self, thresholds: np.ndarray, tprs: np.ndarray, fprs: np.ndarray) -> tuple:
|
|
454
454
|
"""
|
|
@@ -481,11 +481,42 @@ class MS(ThresholdOptimization):
|
|
|
481
481
|
ValueError
|
|
482
482
|
If `thresholds`, `tprs`, or `fprs` are empty or have mismatched lengths.
|
|
483
483
|
"""
|
|
484
|
-
# Compute median TPR and FPR
|
|
485
|
-
tpr = np.median(tprs)
|
|
486
|
-
fpr = np.median(fprs)
|
|
487
484
|
|
|
488
|
-
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)
|
|
489
520
|
|
|
490
521
|
|
|
491
522
|
|
|
@@ -570,33 +601,63 @@ class MS2(ThresholdOptimization):
|
|
|
570
601
|
- The median threshold value for cases meeting the condition (float).
|
|
571
602
|
- The median true positive rate for cases meeting the condition (float).
|
|
572
603
|
- The median false positive rate for cases meeting the condition (float).
|
|
573
|
-
|
|
604
|
+
|
|
574
605
|
Raises
|
|
575
606
|
------
|
|
576
607
|
ValueError
|
|
577
|
-
If no cases satisfy the condition `|TPR - FPR| > 0.25
|
|
578
|
-
|
|
608
|
+
If no cases satisfy the condition `|TPR - FPR| > 0.25`.
|
|
609
|
+
Warning
|
|
610
|
+
If all TPR or FPR values are zero.
|
|
579
611
|
"""
|
|
612
|
+
# Check if all TPR or FPR values are zero
|
|
613
|
+
if np.all(tprs == 0) or np.all(fprs == 0):
|
|
614
|
+
warnings.warn("All TPR or FPR values are zero.")
|
|
615
|
+
|
|
580
616
|
# Identify indices where the condition is satisfied
|
|
581
617
|
indices = np.where(np.abs(tprs - fprs) > 0.25)[0]
|
|
582
618
|
if len(indices) == 0:
|
|
583
|
-
|
|
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]
|
|
584
625
|
|
|
585
|
-
|
|
586
|
-
threshold = np.median(thresholds[indices])
|
|
587
|
-
tpr = np.median(tprs[indices])
|
|
588
|
-
fpr = np.median(fprs[indices])
|
|
589
|
-
|
|
590
|
-
return (threshold, tpr, fpr)
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
626
|
+
return (thresholds_, tprs_, fprs_)
|
|
596
627
|
|
|
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.
|
|
598
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]
|
|
599
659
|
|
|
660
|
+
return np.asarray(prevalences)
|
|
600
661
|
|
|
601
662
|
class PACC(ThresholdOptimization):
|
|
602
663
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: mlquantify
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Quantification Library
|
|
5
5
|
Home-page: https://github.com/luizfernandolj/QuantifyML/tree/master
|
|
6
6
|
Maintainer: Luiz Fernando Luth Junior
|
|
@@ -58,7 +58,7 @@ pip install mlquantify
|
|
|
58
58
|
If you only want to update, run the code below:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
pip install --
|
|
61
|
+
pip install --upgrade mlquantify
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
___
|
|
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
|