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.
Files changed (27) hide show
  1. {mlquantify-0.1.1 → mlquantify-0.1.2}/PKG-INFO +1 -1
  2. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/threshold_optimization.py +75 -12
  3. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/PKG-INFO +1 -1
  4. {mlquantify-0.1.1 → mlquantify-0.1.2}/setup.py +1 -1
  5. {mlquantify-0.1.1 → mlquantify-0.1.2}/README.md +0 -0
  6. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/__init__.py +0 -0
  7. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/base.py +0 -0
  8. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/classification/__init__.py +0 -0
  9. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/classification/methods.py +0 -0
  10. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/__init__.py +0 -0
  11. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/measures.py +0 -0
  12. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/evaluation/protocol.py +0 -0
  13. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/__init__.py +0 -0
  14. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/aggregative.py +0 -0
  15. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/meta.py +0 -0
  16. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/mixture_models.py +0 -0
  17. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/methods/non_aggregative.py +0 -0
  18. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/model_selection.py +0 -0
  19. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/plots.py +0 -0
  20. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/__init__.py +0 -0
  21. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/general.py +0 -0
  22. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify/utils/method.py +0 -0
  23. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/SOURCES.txt +0 -0
  24. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/dependency_links.txt +0 -0
  25. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/requires.txt +0 -0
  26. {mlquantify-0.1.1 → mlquantify-0.1.2}/mlquantify.egg-info/top_level.txt +0 -0
  27. {mlquantify-0.1.1 → mlquantify-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mlquantify
3
- Version: 0.1.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
@@ -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, threshold: float = 0.5):
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 (self.threshold, tpr, fpr)
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
- raise ValueError("No cases meet the condition |TPR - FPR| > 0.25.")
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
- # Compute medians for the selected cases
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
- return (threshold, tpr, fpr)
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
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mlquantify
3
- Version: 0.1.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
@@ -6,7 +6,7 @@ here = pathlib.Path(__file__).parent.resolve()
6
6
 
7
7
  long_description = (here / 'README.md').read_text(encoding='utf-8')
8
8
 
9
- VERSION = '0.1.1'
9
+ VERSION = '0.1.2'
10
10
  DESCRIPTION = 'Quantification Library'
11
11
 
12
12
  # Setting up
File without changes
File without changes